Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

connectionquality.bundle.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.connectionquality=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. /**
  3. * local stats
  4. * @type {{}}
  5. */
  6. var stats = {};
  7. /**
  8. * remote stats
  9. * @type {{}}
  10. */
  11. var remoteStats = {};
  12. /**
  13. * Interval for sending statistics to other participants
  14. * @type {null}
  15. */
  16. var sendIntervalId = null;
  17. /**
  18. * Start statistics sending.
  19. */
  20. function startSendingStats() {
  21. sendStats();
  22. sendIntervalId = setInterval(sendStats, 10000);
  23. }
  24. /**
  25. * Sends statistics to other participants
  26. */
  27. function sendStats() {
  28. xmpp.addToPresence("connectionQuality", convertToMUCStats(stats));
  29. }
  30. /**
  31. * Converts statistics to format for sending through XMPP
  32. * @param stats the statistics
  33. * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
  34. */
  35. function convertToMUCStats(stats) {
  36. return {
  37. "bitrate_download": stats.bitrate.download,
  38. "bitrate_upload": stats.bitrate.upload,
  39. "packetLoss_total": stats.packetLoss.total,
  40. "packetLoss_download": stats.packetLoss.download,
  41. "packetLoss_upload": stats.packetLoss.upload
  42. };
  43. }
  44. /**
  45. * Converts statitistics to format used by VideoLayout
  46. * @param stats
  47. * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
  48. */
  49. function parseMUCStats(stats) {
  50. return {
  51. bitrate: {
  52. download: stats.bitrate_download,
  53. upload: stats.bitrate_upload
  54. },
  55. packetLoss: {
  56. total: stats.packetLoss_total,
  57. download: stats.packetLoss_download,
  58. upload: stats.packetLoss_upload
  59. }
  60. };
  61. }
  62. var ConnectionQuality = {
  63. /**
  64. * Updates the local statistics
  65. * @param data new statistics
  66. */
  67. updateLocalStats: function (data) {
  68. stats = data;
  69. UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
  70. if (sendIntervalId == null) {
  71. startSendingStats();
  72. }
  73. },
  74. /**
  75. * Updates remote statistics
  76. * @param jid the jid associated with the statistics
  77. * @param data the statistics
  78. */
  79. updateRemoteStats: function (jid, data) {
  80. if (data == null || data.packetLoss_total == null) {
  81. UI.updateConnectionStats(jid, null, null);
  82. return;
  83. }
  84. remoteStats[jid] = parseMUCStats(data);
  85. UI.updateConnectionStats(jid, 100 - data.packetLoss_total, remoteStats[jid]);
  86. },
  87. /**
  88. * Stops statistics sending.
  89. */
  90. stopSendingStats: function () {
  91. clearInterval(sendIntervalId);
  92. sendIntervalId = null;
  93. //notify UI about stopping statistics gathering
  94. UI.onStatsStop();
  95. },
  96. /**
  97. * Returns the local statistics.
  98. */
  99. getStats: function () {
  100. return stats;
  101. }
  102. };
  103. module.exports = ConnectionQuality;
  104. },{}]},{},[1])(1)
  105. });