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

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