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.

JitsiRemoteTrack.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. var JitsiTrack = require("./JitsiTrack");
  2. var JitsiTrackEvents = require("../../JitsiTrackEvents");
  3. var RTCBrowserType = require("./RTCBrowserType");
  4. var Statistics = require("../statistics/statistics");
  5. var ttfmTrackerAudioAttached = false;
  6. var ttfmTrackerVideoAttached = false;
  7. /**
  8. * Represents a single media track (either audio or video).
  9. * @param RTC the rtc instance.
  10. * @param ownerJid the MUC JID of the track owner
  11. * @param stream WebRTC MediaStream, parent of the track
  12. * @param track underlying WebRTC MediaStreamTrack for new JitsiRemoteTrack
  13. * @param mediaType the MediaType of the JitsiRemoteTrack
  14. * @param videoType the VideoType of the JitsiRemoteTrack
  15. * @param ssrc the SSRC number of the Media Stream
  16. * @param muted intial muted state of the JitsiRemoteTrack
  17. * @constructor
  18. */
  19. function JitsiRemoteTrack(conference, ownerJid, stream, track, mediaType, videoType,
  20. ssrc, muted) {
  21. JitsiTrack.call(
  22. this, conference, stream, track, function () {}, mediaType, videoType, ssrc);
  23. this.conference = conference;
  24. this.peerjid = ownerJid;
  25. this.muted = muted;
  26. // we want to mark whether the track has been ever muted
  27. // to detect ttfm events for startmuted conferences, as it can significantly
  28. // increase ttfm values
  29. this.hasBeenMuted = muted;
  30. }
  31. JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
  32. JitsiRemoteTrack.prototype.constructor = JitsiRemoteTrack;
  33. /**
  34. * Sets current muted status and fires an events for the change.
  35. * @param value the muted status.
  36. */
  37. JitsiRemoteTrack.prototype.setMute = function (value) {
  38. if(this.muted === value)
  39. return;
  40. if(value)
  41. this.hasBeenMuted = true;
  42. // we can have a fake video stream
  43. if(this.stream)
  44. this.stream.muted = value;
  45. this.muted = value;
  46. this.eventEmitter.emit(JitsiTrackEvents.TRACK_MUTE_CHANGED);
  47. };
  48. /**
  49. * Returns the current muted status of the track.
  50. * @returns {boolean|*|JitsiRemoteTrack.muted} <tt>true</tt> if the track is
  51. * muted and <tt>false</tt> otherwise.
  52. */
  53. JitsiRemoteTrack.prototype.isMuted = function () {
  54. return this.muted;
  55. };
  56. /**
  57. * Returns the participant id which owns the track.
  58. * @returns {string} the id of the participants.
  59. */
  60. JitsiRemoteTrack.prototype.getParticipantId = function() {
  61. return Strophe.getResourceFromJid(this.peerjid);
  62. };
  63. /**
  64. * Return false;
  65. */
  66. JitsiRemoteTrack.prototype.isLocal = function () {
  67. return false;
  68. };
  69. /**
  70. * Returns the synchronization source identifier (SSRC) of this remote track.
  71. * @returns {string} the SSRC of this remote track
  72. */
  73. JitsiRemoteTrack.prototype.getSSRC = function () {
  74. return this.ssrc;
  75. };
  76. /**
  77. * Changes the video type of the track
  78. * @param type the new video type("camera", "desktop")
  79. */
  80. JitsiRemoteTrack.prototype._setVideoType = function (type) {
  81. if(this.videoType === type)
  82. return;
  83. this.videoType = type;
  84. this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
  85. };
  86. /**
  87. * Attach time to first media tracker only if there is conference and only
  88. * for the first element.
  89. * @param container the HTML container which can be 'video' or 'audio' element.
  90. * It can also be 'object' element if Temasys plugin is in use and this
  91. * method has been called previously on video or audio HTML element.
  92. * @private
  93. */
  94. JitsiRemoteTrack.prototype._attachTTFMTracker = function (container) {
  95. if((ttfmTrackerAudioAttached && this.isAudioTrack())
  96. || (ttfmTrackerVideoAttached && this.isVideoTrack()))
  97. return;
  98. if (this.isAudioTrack())
  99. ttfmTrackerAudioAttached = true;
  100. if (this.isVideoTrack())
  101. ttfmTrackerVideoAttached = true;
  102. // FIXME: this is not working for temasys
  103. container.addEventListener("canplay", function () {
  104. var type = (this.isVideoTrack() ? 'video' : 'audio');
  105. var now = window.performance.now();
  106. console.log("(TIME) Render " + type + ":\t", now);
  107. this.conference.getConnectionTimes()[type + ".render"] = now;
  108. var ttfm = now
  109. - (this.conference.getConnectionTimes()["session.initiate"]
  110. - this.conference.getConnectionTimes()["muc.joined"]);
  111. this.conference.getConnectionTimes()[type + ".ttfm"] = ttfm;
  112. console.log("(TIME) TTFM " + type + ":\t", ttfm);
  113. var eventName = type +'.ttfm';
  114. if(this.hasBeenMuted)
  115. eventName += '.muted';
  116. Statistics.analytics.sendEvent(eventName, ttfm);
  117. }.bind(this));
  118. };
  119. module.exports = JitsiRemoteTrack;