Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

statistics.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Created by hristo on 8/4/14.
  3. */
  4. var LocalStats = require("./LocalStatsCollector.js");
  5. var RTPStats = require("./RTPStatsCollector.js");
  6. var EventEmitter = require("events");
  7. var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  8. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  9. var eventEmitter = new EventEmitter();
  10. var localStats = null;
  11. var rtpStats = null;
  12. function stopLocal()
  13. {
  14. if(localStats)
  15. {
  16. localStats.stop();
  17. localStats = null;
  18. }
  19. }
  20. function stopRemote()
  21. {
  22. if(rtpStats)
  23. {
  24. rtpStats.stop();
  25. eventEmitter.emit("statistics.stop");
  26. rtpStats = null;
  27. }
  28. }
  29. function startRemoteStats (peerconnection) {
  30. if (config.enableRtpStats)
  31. {
  32. if(rtpStats)
  33. {
  34. rtpStats.stop();
  35. rtpStats = null;
  36. }
  37. rtpStats = new RTPStats(peerconnection, 200, 2000, eventEmitter);
  38. rtpStats.start();
  39. }
  40. }
  41. function onStreamCreated(stream)
  42. {
  43. if(stream.getOriginalStream().getAudioTracks().length === 0)
  44. return;
  45. localStats = new LocalStats(stream.getOriginalStream(), 100, statistics,
  46. eventEmitter);
  47. localStats.start();
  48. }
  49. function onDisposeConference(onUnload) {
  50. stopRemote();
  51. if(onUnload) {
  52. stopLocal();
  53. eventEmitter.removeAllListeners();
  54. }
  55. }
  56. var statistics =
  57. {
  58. /**
  59. * Indicates that this audio level is for local jid.
  60. * @type {string}
  61. */
  62. LOCAL_JID: 'local',
  63. addAudioLevelListener: function(listener)
  64. {
  65. eventEmitter.on("statistics.audioLevel", listener);
  66. },
  67. removeAudioLevelListener: function(listener)
  68. {
  69. eventEmitter.removeListener("statistics.audioLevel", listener);
  70. },
  71. addConnectionStatsListener: function(listener)
  72. {
  73. eventEmitter.on("statistics.connectionstats", listener);
  74. },
  75. removeConnectionStatsListener: function(listener)
  76. {
  77. eventEmitter.removeListener("statistics.connectionstats", listener);
  78. },
  79. addRemoteStatsStopListener: function(listener)
  80. {
  81. eventEmitter.on("statistics.stop", listener);
  82. },
  83. removeRemoteStatsStopListener: function(listener)
  84. {
  85. eventEmitter.removeListener("statistics.stop", listener);
  86. },
  87. stop: function () {
  88. stopLocal();
  89. stopRemote();
  90. if(eventEmitter)
  91. {
  92. eventEmitter.removeAllListeners();
  93. }
  94. },
  95. stopRemoteStatistics: function()
  96. {
  97. stopRemote();
  98. },
  99. start: function () {
  100. APP.RTC.addStreamListener(onStreamCreated,
  101. StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  102. APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  103. APP.xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
  104. startRemoteStats(event.peerconnection);
  105. });
  106. }
  107. };
  108. module.exports = statistics;