Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

throttle.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const utils_1 = require("../../utils");
  4. const NETWORK_PRESETS = {
  5. 'offline': {
  6. offline: true,
  7. downloadThroughput: 0,
  8. uploadThroughput: 0,
  9. latency: 1
  10. },
  11. 'GPRS': {
  12. offline: false,
  13. downloadThroughput: 50 * 1024 / 8,
  14. uploadThroughput: 20 * 1024 / 8,
  15. latency: 500
  16. },
  17. 'Regular2G': {
  18. offline: false,
  19. downloadThroughput: 250 * 1024 / 8,
  20. uploadThroughput: 50 * 1024 / 8,
  21. latency: 300
  22. },
  23. 'Good2G': {
  24. offline: false,
  25. downloadThroughput: 450 * 1024 / 8,
  26. uploadThroughput: 150 * 1024 / 8,
  27. latency: 150
  28. },
  29. 'Regular3G': {
  30. offline: false,
  31. downloadThroughput: 750 * 1024 / 8,
  32. uploadThroughput: 250 * 1024 / 8,
  33. latency: 100
  34. },
  35. 'Good3G': {
  36. offline: false,
  37. downloadThroughput: 1.5 * 1024 * 1024 / 8,
  38. uploadThroughput: 750 * 1024 / 8,
  39. latency: 40
  40. },
  41. 'Regular4G': {
  42. offline: false,
  43. downloadThroughput: 4 * 1024 * 1024 / 8,
  44. uploadThroughput: 3 * 1024 * 1024 / 8,
  45. latency: 20
  46. },
  47. 'DSL': {
  48. offline: false,
  49. downloadThroughput: 2 * 1024 * 1024 / 8,
  50. uploadThroughput: 1 * 1024 * 1024 / 8,
  51. latency: 5
  52. },
  53. 'WiFi': {
  54. offline: false,
  55. downloadThroughput: 30 * 1024 * 1024 / 8,
  56. uploadThroughput: 15 * 1024 * 1024 / 8,
  57. latency: 2
  58. },
  59. 'online': {
  60. offline: false,
  61. latency: 0,
  62. downloadThroughput: -1,
  63. uploadThroughput: -1
  64. }
  65. };
  66. const NETWORK_PRESET_TYPES = Object.keys(NETWORK_PRESETS);
  67. async function throttle(params) {
  68. if ((typeof params !== 'string' || !NETWORK_PRESET_TYPES.includes(params)) &&
  69. (typeof params !== 'object')) {
  70. throw new Error(`Invalid parameter for "throttle". Expected it to be typeof object or one of the following values: ${NETWORK_PRESET_TYPES.join(', ')} but found "${params}"`);
  71. }
  72. if (this.isSauce) {
  73. const browser = utils_1.getBrowserObject(this);
  74. await browser.throttleNetwork(params);
  75. return null;
  76. }
  77. await this.getPuppeteer();
  78. const pages = await this.puppeteer.pages();
  79. const client = await pages[0].target().createCDPSession();
  80. await client.send('Network.emulateNetworkConditions', typeof params === 'string'
  81. ? NETWORK_PRESETS[params]
  82. : params);
  83. return null;
  84. }
  85. exports.default = throttle;