modified lib-jitsi-meet dev repo
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.1KB

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