您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

statistics.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* global require, APP */
  2. var LocalStats = require("./LocalStatsCollector.js");
  3. var RTPStats = require("./RTPStatsCollector.js");
  4. var EventEmitter = require("events");
  5. var StatisticsEvents = require("../../service/statistics/Events");
  6. //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  7. //var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  8. //var CallStats = require("./CallStats");
  9. //var RTCEvents = require("../../service/RTC/RTCEvents");
  10. //
  11. //function onDisposeConference(onUnload) {
  12. // CallStats.sendTerminateEvent();
  13. // stopRemote();
  14. // if(onUnload) {
  15. // stopLocal();
  16. // eventEmitter.removeAllListeners();
  17. // }
  18. //}
  19. var eventEmitter = new EventEmitter();
  20. function Statistics() {
  21. this.rtpStats = null;
  22. this.eventEmitter = new EventEmitter();
  23. }
  24. Statistics.prototype.startRemoteStats = function (peerconnection) {
  25. if (this.rtpStats) {
  26. this.rtpStats.stop();
  27. }
  28. this.rtpStats = new RTPStats(peerconnection, 200, 2000, this.eventEmitter);
  29. this.rtpStats.start();
  30. }
  31. Statistics.localStats = [];
  32. Statistics.startLocalStats = function (stream, callback) {
  33. var localStats = new LocalStats(stream, 200, callback);
  34. this.localStats.push(localStats);
  35. localStats.start();
  36. }
  37. Statistics.prototype.addAudioLevelListener = function(listener)
  38. {
  39. this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
  40. }
  41. Statistics.prototype.removeAudioLevelListener = function(listener)
  42. {
  43. this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
  44. }
  45. Statistics.prototype.dispose = function () {
  46. Statistics.stopAllLocalStats();
  47. this.stopRemote();
  48. if(this.eventEmitter)
  49. this.eventEmitter.removeAllListeners();
  50. if(eventEmitter)
  51. eventEmitter.removeAllListeners();
  52. }
  53. Statistics.stopAllLocalStats = function () {
  54. for(var i = 0; i < this.localStats.length; i++)
  55. this.localStats[i].stop();
  56. this.localStats = [];
  57. }
  58. Statistics.stopLocalStats = function (stream) {
  59. for(var i = 0; i < Statistics.localStats.length; i++)
  60. if(Statistics.localStats[i].stream === stream){
  61. var localStats = Statistics.localStats.splice(i, 1);
  62. localStats.stop();
  63. break;
  64. }
  65. }
  66. Statistics.prototype.stopRemote = function () {
  67. if (this.rtpStats) {
  68. this.rtpStats.stop();
  69. this.eventEmitter.emit(StatisticsEvents.STOP);
  70. this.rtpStats = null;
  71. }
  72. }
  73. Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
  74. //
  75. //var statistics = {
  76. // /**
  77. // * Indicates that this audio level is for local jid.
  78. // * @type {string}
  79. // */
  80. // LOCAL_JID: 'local',
  81. //
  82. // addConnectionStatsListener: function(listener)
  83. // {
  84. // eventEmitter.on("statistics.connectionstats", listener);
  85. // },
  86. //
  87. // removeConnectionStatsListener: function(listener)
  88. // {
  89. // eventEmitter.removeListener("statistics.connectionstats", listener);
  90. // },
  91. //
  92. //
  93. // addRemoteStatsStopListener: function(listener)
  94. // {
  95. // eventEmitter.on("statistics.stop", listener);
  96. // },
  97. //
  98. // removeRemoteStatsStopListener: function(listener)
  99. // {
  100. // eventEmitter.removeListener("statistics.stop", listener);
  101. // },
  102. //
  103. //
  104. // stopRemoteStatistics: function()
  105. // {
  106. // stopRemote();
  107. // },
  108. //
  109. //// Already implemented with the constructor
  110. // start: function () {
  111. // APP.RTC.addStreamListener(onStreamCreated,
  112. // StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  113. // APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  114. // //FIXME: we may want to change CALL INCOMING event to onnegotiationneeded
  115. // APP.xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
  116. // startRemoteStats(event.peerconnection);
  117. //// CallStats.init(event);
  118. // });
  119. //// APP.xmpp.addListener(XMPPEvents.PEERCONNECTION_READY, function (session) {
  120. //// CallStats.init(session);
  121. //// });
  122. // //FIXME: that event is changed to TRACK_MUTE_CHANGED
  123. //// APP.RTC.addListener(RTCEvents.AUDIO_MUTE, function (mute) {
  124. //// CallStats.sendMuteEvent(mute, "audio");
  125. //// });
  126. //// APP.xmpp.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  127. //// CallStats.sendSetupFailedEvent();
  128. //// });
  129. // //FIXME: that event is changed to TRACK_MUTE_CHANGED
  130. //// APP.RTC.addListener(RTCEvents.VIDEO_MUTE, function (mute) {
  131. //// CallStats.sendMuteEvent(mute, "video");
  132. //// });
  133. // }
  134. //};
  135. module.exports = Statistics;