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.

statistics.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. function Statistics() {
  20. this.localStats = null;
  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.prototype.startLocalStats = function (stream) {
  32. if(stream.getType() !== "audio")
  33. return;
  34. this.localStats = new LocalStats(stream.getOriginalStream(), 200, this,
  35. this.eventEmitter);
  36. this.localStats.start();
  37. }
  38. Statistics.prototype.addAudioLevelListener = function(listener)
  39. {
  40. this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
  41. }
  42. Statistics.prototype.removeAudioLevelListener = function(listener)
  43. {
  44. this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
  45. }
  46. Statistics.prototype.dispose = function () {
  47. this.stopLocal();
  48. this.stopRemote();
  49. if(this.eventEmitter)
  50. {
  51. this.eventEmitter.removeAllListeners();
  52. }
  53. }
  54. Statistics.prototype.stopLocal = function () {
  55. if (this.localStats) {
  56. this.localStats.stop();
  57. this.localStats = null;
  58. }
  59. }
  60. Statistics.prototype.stopRemote = function () {
  61. if (this.rtpStats) {
  62. this.rtpStats.stop();
  63. this.eventEmitter.emit(StatisticsEvents.STOP);
  64. this.rtpStats = null;
  65. }
  66. }
  67. Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
  68. //
  69. //var statistics = {
  70. // /**
  71. // * Indicates that this audio level is for local jid.
  72. // * @type {string}
  73. // */
  74. // LOCAL_JID: 'local',
  75. //
  76. // addConnectionStatsListener: function(listener)
  77. // {
  78. // eventEmitter.on("statistics.connectionstats", listener);
  79. // },
  80. //
  81. // removeConnectionStatsListener: function(listener)
  82. // {
  83. // eventEmitter.removeListener("statistics.connectionstats", listener);
  84. // },
  85. //
  86. //
  87. // addRemoteStatsStopListener: function(listener)
  88. // {
  89. // eventEmitter.on("statistics.stop", listener);
  90. // },
  91. //
  92. // removeRemoteStatsStopListener: function(listener)
  93. // {
  94. // eventEmitter.removeListener("statistics.stop", listener);
  95. // },
  96. //
  97. //
  98. // stopRemoteStatistics: function()
  99. // {
  100. // stopRemote();
  101. // },
  102. //
  103. //// Already implemented with the constructor
  104. // start: function () {
  105. // APP.RTC.addStreamListener(onStreamCreated,
  106. // StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  107. // APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  108. // //FIXME: we may want to change CALL INCOMING event to onnegotiationneeded
  109. // APP.xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
  110. // startRemoteStats(event.peerconnection);
  111. //// CallStats.init(event);
  112. // });
  113. //// APP.xmpp.addListener(XMPPEvents.PEERCONNECTION_READY, function (session) {
  114. //// CallStats.init(session);
  115. //// });
  116. // //FIXME: that event is changed to TRACK_MUTE_CHANGED
  117. //// APP.RTC.addListener(RTCEvents.AUDIO_MUTE, function (mute) {
  118. //// CallStats.sendMuteEvent(mute, "audio");
  119. //// });
  120. //// APP.xmpp.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  121. //// CallStats.sendSetupFailedEvent();
  122. //// });
  123. // //FIXME: that event is changed to TRACK_MUTE_CHANGED
  124. //// APP.RTC.addListener(RTCEvents.VIDEO_MUTE, function (mute) {
  125. //// CallStats.sendMuteEvent(mute, "video");
  126. //// });
  127. // }
  128. //};
  129. module.exports = Statistics;