This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

View File

@ -0,0 +1,43 @@
(function (angular) {
const SECTION_NAME = "remote-debug";
/**
* Display the snippet when in snippet mode
*/
angular
.module("BrowserSync")
.directive("latency", function () {
return {
restrict: "E",
replace: true,
scope: {
"options": "="
},
templateUrl: "latency.html",
controller: ["$scope", "Socket", latencyDirectiveControlller],
controllerAs: "ctrl"
};
});
/**
* @param $scope
* @param Socket
*/
function latencyDirectiveControlller($scope, Socket) {
var ctrl = this;
var ns = SECTION_NAME + ":latency";
ctrl.latency = $scope.options[SECTION_NAME]["latency"];
ctrl.alterLatency = function () {
Socket.emit("ui", {
namespace: ns,
event: "adjust",
data: {
rate: ctrl.latency.rate
}
});
};
}
})(angular);

View File

@ -0,0 +1,12 @@
<div ng-show="ctrl.latency.active" bs-panel-content>
<input type="range"
max="5"
min="0"
step=".50"
id="latency-rate"
ng-change="ctrl.alterLatency()"
ng-model="ctrl.latency.rate"/>
<label for="latency-rate">{{ctrl.latency.rate | number:1}}s</label>
</div>

View File

@ -0,0 +1,44 @@
var Immutable = require("immutable");
module.exports.init = function (ui, bs) {
var timeout = 0;
var optPath = ["remote-debug", "latency"];
ui.setOptionIn(optPath, Immutable.Map({
name: "latency",
title: "Latency",
active: false,
tagline: "Simulate slower connections by throttling the response time of each request.",
rate: 0
}));
var methods = {
toggle: function (value) {
if (value !== true) {
value = false;
}
if (value) {
ui.setOptionIn(optPath.concat("active"), true);
bs.addMiddleware("*", function (req, res, next) {
setTimeout(next, timeout);
}, {id: "cp-latency", override: true});
} else {
ui.setOptionIn(optPath.concat("active"), false);
bs.removeMiddleware("cp-latency");
}
},
adjust: function (data) {
timeout = parseFloat(data.rate) * 1000;
var saved = ui.options.getIn(optPath.concat("rate"));
if (saved !== data.rate) {
ui.setOptionIn(optPath.concat("rate"), timeout/1000);
}
},
event: function (event) {
methods[event.event](event.data);
}
};
return methods;
};