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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* global require, APP */
  2. /**
  3. * Created by hristo on 8/4/14.
  4. */
  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 CallStats = require("./CallStats");
  10. var RTCEvents = require("../../service/RTC/RTCEvents");
  11. var StatisticsEvents = require("../../service/statistics/Events");
  12. var eventEmitter = new EventEmitter();
  13. var rtpStats = null;
  14. function stopRemote() {
  15. if (rtpStats) {
  16. rtpStats.stop();
  17. eventEmitter.emit(StatisticsEvents.STOP);
  18. rtpStats = null;
  19. }
  20. }
  21. function startRemoteStats (peerconnection) {
  22. if (rtpStats) {
  23. rtpStats.stop();
  24. }
  25. rtpStats = new RTPStats(peerconnection, 200, 2000, eventEmitter);
  26. rtpStats.start();
  27. }
  28. function onDisposeConference(onUnload) {
  29. CallStats.sendTerminateEvent();
  30. stopRemote();
  31. if (onUnload) {
  32. eventEmitter.removeAllListeners();
  33. }
  34. }
  35. export default {
  36. /**
  37. * Indicates that this audio level is for local jid.
  38. * @type {string}
  39. */
  40. LOCAL_JID: 'local',
  41. addListener: function(type, listener) {
  42. eventEmitter.on(type, listener);
  43. },
  44. removeListener: function (type, listener) {
  45. eventEmitter.removeListener(type, listener);
  46. },
  47. stop: function () {
  48. stopRemote();
  49. if (eventEmitter) {
  50. eventEmitter.removeAllListeners();
  51. }
  52. },
  53. onAudioMute (mute) {
  54. CallStats.sendMuteEvent(mute, "audio");
  55. },
  56. onVideoMute (mute) {
  57. CallStats.sendMuteEvent(mute, "video");
  58. },
  59. onGetUserMediaFailed (e) {
  60. CallStats.sendGetUserMediaFailed(e);
  61. },
  62. start: function () {
  63. const xmpp = APP.conference._room.xmpp;
  64. xmpp.addListener(
  65. XMPPEvents.DISPOSE_CONFERENCE,
  66. onDisposeConference
  67. );
  68. //FIXME: we may want to change CALL INCOMING event to
  69. // onnegotiationneeded
  70. xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
  71. startRemoteStats(event.peerconnection);
  72. // CallStats.init(event);
  73. });
  74. xmpp.addListener(
  75. XMPPEvents.PEERCONNECTION_READY,
  76. function (session) {
  77. CallStats.init(session);
  78. }
  79. );
  80. xmpp.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  81. CallStats.sendSetupFailedEvent();
  82. });
  83. xmpp.addListener(RTCEvents.CREATE_OFFER_FAILED, function (e, pc) {
  84. CallStats.sendCreateOfferFailed(e, pc);
  85. });
  86. xmpp.addListener(RTCEvents.CREATE_ANSWER_FAILED, function (e, pc) {
  87. CallStats.sendCreateAnswerFailed(e, pc);
  88. });
  89. xmpp.addListener(
  90. RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
  91. function (e, pc) {
  92. CallStats.sendSetLocalDescFailed(e, pc);
  93. }
  94. );
  95. xmpp.addListener(
  96. RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
  97. function (e, pc) {
  98. CallStats.sendSetRemoteDescFailed(e, pc);
  99. }
  100. );
  101. xmpp.addListener(
  102. RTCEvents.ADD_ICE_CANDIDATE_FAILED,
  103. function (e, pc) {
  104. CallStats.sendAddIceCandidateFailed(e, pc);
  105. }
  106. );
  107. },
  108. /**
  109. * FIXME:
  110. * Currently used by torture. If we are removing this, torture needs to
  111. * be fixed also.
  112. *
  113. * Obtains audio level reported in the stats for specified peer.
  114. * @param peerJid full MUC jid of the user for whom we want to obtain last
  115. * audio level.
  116. * @param ssrc the SSRC of audio stream for which we want to obtain audio
  117. * level.
  118. * @returns {*} a float form 0 to 1 that represents current audio level or
  119. * <tt>null</tt> if for any reason the value is not available
  120. * at this time.
  121. */
  122. getPeerSSRCAudioLevel: function (peerJid, ssrc) {
  123. var peerStats = rtpStats.jid2stats[peerJid];
  124. return peerStats ? peerStats.ssrc2AudioLevel[ssrc] : null;
  125. }
  126. };