Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

connectionquality.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. var ConnectionQuality = (function () {
  2. /**
  3. * Constructs new ConnectionQuality object
  4. * @constructor
  5. */
  6. function ConnectionQuality() {
  7. }
  8. /**
  9. * local stats
  10. * @type {{}}
  11. */
  12. var stats = {};
  13. /**
  14. * remote stats
  15. * @type {{}}
  16. */
  17. var remoteStats = {};
  18. /**
  19. * Interval for sending statistics to other participants
  20. * @type {null}
  21. */
  22. var sendIntervalId = null;
  23. /**
  24. * Updates the local statistics
  25. * @param data new statistics
  26. */
  27. ConnectionQuality.updateLocalStats = function (data) {
  28. stats = data;
  29. VideoLayout.updateLocalConnectionStats(100 - stats.packetLoss.total,stats);
  30. if(sendIntervalId == null)
  31. {
  32. startSendingStats();
  33. }
  34. };
  35. /**
  36. * Start statistics sending.
  37. */
  38. function startSendingStats() {
  39. sendStats();
  40. sendIntervalId = setInterval(sendStats, 10000);
  41. }
  42. /**
  43. * Sends statistics to other participants
  44. */
  45. function sendStats() {
  46. connection.emuc.addConnectionInfoToPresence(convertToMUCStats(stats));
  47. connection.emuc.sendPresence();
  48. }
  49. /**
  50. * Converts statistics to format for sending through XMPP
  51. * @param stats the statistics
  52. * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
  53. */
  54. function convertToMUCStats(stats) {
  55. return {
  56. "bitrate_donwload": stats.bitrate.download,
  57. "bitrate_uplpoad": stats.bitrate.upload,
  58. "packetLoss_total": stats.packetLoss.total,
  59. "packetLoss_download": stats.packetLoss.download,
  60. "packetLoss_upload": stats.packetLoss.upload
  61. };
  62. }
  63. /**
  64. * Converts statitistics to format used by VideoLayout
  65. * @param stats
  66. * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
  67. */
  68. function parseMUCStats(stats) {
  69. return {
  70. bitrate: {
  71. download: stats.bitrate_donwload,
  72. upload: stats.bitrate_uplpoad
  73. },
  74. packetLoss: {
  75. total: stats.packetLoss_total,
  76. download: stats.packetLoss_download,
  77. upload: stats.packetLoss_upload
  78. }
  79. };
  80. }
  81. /**
  82. * Updates remote statistics
  83. * @param jid the jid associated with the statistics
  84. * @param data the statistics
  85. */
  86. ConnectionQuality.updateRemoteStats = function (jid, data) {
  87. if(data == null || data.packetLoss_total == null)
  88. {
  89. VideoLayout.updateConnectionStats(jid, null, null);
  90. return;
  91. }
  92. remoteStats[jid] = parseMUCStats(data);
  93. console.log(remoteStats[jid]);
  94. VideoLayout.updateConnectionStats(jid, 100 - data.packetLoss_total,remoteStats[jid]);
  95. };
  96. /**
  97. * Stops statistics sending.
  98. */
  99. ConnectionQuality.stopSendingStats = function () {
  100. clearInterval(sendIntervalId);
  101. sendIntervalId = null;
  102. //notify UI about stopping statistics gathering
  103. VideoLayout.onStatsStop();
  104. };
  105. return ConnectionQuality;
  106. })();