Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

JitsiRemoteTrack.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* global */
  2. var JitsiTrack = require("./JitsiTrack");
  3. import * as JitsiTrackEvents from "../../JitsiTrackEvents";
  4. var logger = require("jitsi-meet-logger").getLogger(__filename);
  5. var RTCBrowserType = require("./RTCBrowserType");
  6. var RTCEvents = require("../../service/RTC/RTCEvents");
  7. var Statistics = require("../statistics/statistics");
  8. var ttfmTrackerAudioAttached = false;
  9. var ttfmTrackerVideoAttached = false;
  10. /**
  11. * Represents a single media track (either audio or video).
  12. * @param {RTC} rtc the RTC service instance.
  13. * @param {JitsiConference} conference the conference to which this track
  14. * belongs to
  15. * @param {string} ownerEndpointId the endpoint ID of the track owner
  16. * @param {MediaStream} stream WebRTC MediaStream, parent of the track
  17. * @param {MediaStreamTrack} track underlying WebRTC MediaStreamTrack for
  18. * the new JitsiRemoteTrack
  19. * @param {MediaType} mediaType the type of the media
  20. * @param {VideoType} videoType the type of the video if applicable
  21. * @param {string} ssrc the SSRC number of the Media Stream
  22. * @param {boolean} muted the initial muted state
  23. * @constructor
  24. */
  25. function JitsiRemoteTrack(rtc, conference, ownerEndpointId, stream, track,
  26. mediaType, videoType, ssrc, muted) {
  27. JitsiTrack.call(
  28. this, conference, stream, track, function () {}, mediaType, videoType, ssrc);
  29. this.rtc = rtc;
  30. this.ownerEndpointId = ownerEndpointId;
  31. this.muted = muted;
  32. // we want to mark whether the track has been ever muted
  33. // to detect ttfm events for startmuted conferences, as it can significantly
  34. // increase ttfm values
  35. this.hasBeenMuted = muted;
  36. // Bind 'onmute' and 'onunmute' event handlers
  37. if (this.rtc && this.track)
  38. this._bindMuteHandlers();
  39. }
  40. JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
  41. JitsiRemoteTrack.prototype.constructor = JitsiRemoteTrack;
  42. JitsiRemoteTrack.prototype._bindMuteHandlers = function() {
  43. // Bind 'onmute'
  44. // FIXME it would be better to use recently added '_setHandler' method, but
  45. // 1. It does not allow to set more than one handler to the event
  46. // 2. It does mix MediaStream('inactive') with MediaStreamTrack events
  47. // 3. Allowing to bind more than one event handler requires too much
  48. // refactoring around camera issues detection.
  49. this.track.addEventListener('mute', function () {
  50. logger.debug(
  51. '"onmute" event(' + Date.now() + '): ',
  52. this.getParticipantId(), this.getType(), this.getSSRC());
  53. this.rtc.eventEmitter.emit(RTCEvents.REMOTE_TRACK_MUTE, this);
  54. }.bind(this));
  55. // Bind 'onunmute'
  56. this.track.addEventListener('unmute', function () {
  57. logger.debug(
  58. '"onunmute" event(' + Date.now() + '): ',
  59. this.getParticipantId(), this.getType(), this.getSSRC());
  60. this.rtc.eventEmitter.emit(RTCEvents.REMOTE_TRACK_UNMUTE, this);
  61. }.bind(this));
  62. };
  63. /**
  64. * Sets current muted status and fires an events for the change.
  65. * @param value the muted status.
  66. */
  67. JitsiRemoteTrack.prototype.setMute = function (value) {
  68. if(this.muted === value)
  69. return;
  70. if(value)
  71. this.hasBeenMuted = true;
  72. // we can have a fake video stream
  73. if(this.stream)
  74. this.stream.muted = value;
  75. this.muted = value;
  76. this.eventEmitter.emit(JitsiTrackEvents.TRACK_MUTE_CHANGED, this);
  77. };
  78. /**
  79. * Returns the current muted status of the track.
  80. * @returns {boolean|*|JitsiRemoteTrack.muted} <tt>true</tt> if the track is
  81. * muted and <tt>false</tt> otherwise.
  82. */
  83. JitsiRemoteTrack.prototype.isMuted = function () {
  84. return this.muted;
  85. };
  86. /**
  87. * Returns the participant id which owns the track.
  88. * @returns {string} the id of the participants. It corresponds to the Colibri
  89. * endpoint id/MUC nickname in case of Jitsi-meet.
  90. */
  91. JitsiRemoteTrack.prototype.getParticipantId = function() {
  92. return this.ownerEndpointId;
  93. };
  94. /**
  95. * Return false;
  96. */
  97. JitsiRemoteTrack.prototype.isLocal = function () {
  98. return false;
  99. };
  100. /**
  101. * Returns the synchronization source identifier (SSRC) of this remote track.
  102. * @returns {string} the SSRC of this remote track
  103. */
  104. JitsiRemoteTrack.prototype.getSSRC = function () {
  105. return this.ssrc;
  106. };
  107. /**
  108. * Changes the video type of the track
  109. * @param type the new video type("camera", "desktop")
  110. */
  111. JitsiRemoteTrack.prototype._setVideoType = function (type) {
  112. if(this.videoType === type)
  113. return;
  114. this.videoType = type;
  115. this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
  116. };
  117. JitsiRemoteTrack.prototype._playCallback = function () {
  118. var type = this.isVideoTrack() ? 'video' : 'audio';
  119. var now = window.performance.now();
  120. console.log("(TIME) Render " + type + ":\t", now);
  121. this.conference.getConnectionTimes()[type + ".render"] = now;
  122. var ttfm = now
  123. - (this.conference.getConnectionTimes()["session.initiate"]
  124. - this.conference.getConnectionTimes()["muc.joined"])
  125. - (window.connectionTimes["obtainPermissions.end"]
  126. - window.connectionTimes["obtainPermissions.start"]);
  127. this.conference.getConnectionTimes()[type + ".ttfm"] = ttfm;
  128. console.log("(TIME) TTFM " + type + ":\t", ttfm);
  129. var eventName = type +'.ttfm';
  130. if(this.hasBeenMuted)
  131. eventName += '.muted';
  132. Statistics.analytics.sendEvent(eventName, {value: ttfm});
  133. };
  134. /**
  135. * Attach time to first media tracker only if there is conference and only
  136. * for the first element.
  137. * @param container the HTML container which can be 'video' or 'audio' element.
  138. * It can also be 'object' element if Temasys plugin is in use and this
  139. * method has been called previously on video or audio HTML element.
  140. * @private
  141. */
  142. JitsiRemoteTrack.prototype._attachTTFMTracker = function (container) {
  143. if((ttfmTrackerAudioAttached && this.isAudioTrack())
  144. || (ttfmTrackerVideoAttached && this.isVideoTrack()))
  145. return;
  146. if (this.isAudioTrack())
  147. ttfmTrackerAudioAttached = true;
  148. if (this.isVideoTrack())
  149. ttfmTrackerVideoAttached = true;
  150. if (RTCBrowserType.isTemasysPluginUsed()) {
  151. // XXX Don't require Temasys unless it's to be used because it doesn't
  152. // run on React Native, for example.
  153. const AdapterJS = require("./adapter.screenshare");
  154. // FIXME: this is not working for IE11
  155. AdapterJS.addEvent(container, 'play', this._playCallback.bind(this));
  156. }
  157. else {
  158. container.addEventListener("canplay", this._playCallback.bind(this));
  159. }
  160. };
  161. module.exports = JitsiRemoteTrack;