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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. }
  27. JitsiRemoteTrack.prototype = Object.create(JitsiTrack.prototype);
  28. JitsiRemoteTrack.prototype.constructor = JitsiRemoteTrack;
  29. /**
  30. * Sets current muted status and fires an events for the change.
  31. * @param value the muted status.
  32. */
  33. JitsiRemoteTrack.prototype.setMute = function (value) {
  34. if(this.muted === value)
  35. return;
  36. // we can have a fake video stream
  37. if(this.stream)
  38. this.stream.muted = value;
  39. this.muted = value;
  40. this.eventEmitter.emit(JitsiTrackEvents.TRACK_MUTE_CHANGED);
  41. };
  42. /**
  43. * Returns the current muted status of the track.
  44. * @returns {boolean|*|JitsiRemoteTrack.muted} <tt>true</tt> if the track is
  45. * muted and <tt>false</tt> otherwise.
  46. */
  47. JitsiRemoteTrack.prototype.isMuted = function () {
  48. return this.muted;
  49. };
  50. /**
  51. * Returns the participant id which owns the track.
  52. * @returns {string} the id of the participants.
  53. */
  54. JitsiRemoteTrack.prototype.getParticipantId = function() {
  55. return Strophe.getResourceFromJid(this.peerjid);
  56. };
  57. /**
  58. * Return false;
  59. */
  60. JitsiRemoteTrack.prototype.isLocal = function () {
  61. return false;
  62. };
  63. /**
  64. * Returns the synchronization source identifier (SSRC) of this remote track.
  65. * @returns {string} the SSRC of this remote track
  66. */
  67. JitsiRemoteTrack.prototype.getSSRC = function () {
  68. return this.ssrc;
  69. };
  70. /**
  71. * Changes the video type of the track
  72. * @param type the new video type("camera", "desktop")
  73. */
  74. JitsiRemoteTrack.prototype._setVideoType = function (type) {
  75. if(this.videoType === type)
  76. return;
  77. this.videoType = type;
  78. this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
  79. };
  80. /**
  81. * Attach time to first media tracker only if there is conference and only
  82. * for the first element.
  83. * @param container the HTML container which can be 'video' or 'audio' element.
  84. * It can also be 'object' element if Temasys plugin is in use and this
  85. * method has been called previously on video or audio HTML element.
  86. * @private
  87. */
  88. JitsiRemoteTrack.prototype._attachTTFMTracker = function (container) {
  89. if((ttfmTrackerAudioAttached && this.isAudioTrack())
  90. || (ttfmTrackerVideoAttached && this.isVideoTrack()))
  91. return;
  92. if (this.isAudioTrack())
  93. ttfmTrackerAudioAttached = true;
  94. if (this.isVideoTrack())
  95. ttfmTrackerVideoAttached = true;
  96. // FIXME: this is not working for temasys
  97. container.addEventListener("canplay", function () {
  98. var type = (this.isVideoTrack() ? 'video' : 'audio');
  99. var now = window.performance.now();
  100. console.log("(TIME) Render " + type + ":\t", now);
  101. this.conference.getConnectionTimes()[type + ".render"] = now;
  102. var ttfm = now
  103. - (this.conference.getConnectionTimes()["session.initiate"]
  104. - this.conference.getConnectionTimes()["muc.joined"]);
  105. this.conference.getConnectionTimes()[type + ".ttfm"] = ttfm;
  106. console.log("(TIME) TTFM " + type + ":\t", ttfm);
  107. Statistics.analytics.sendEvent(type +'.ttfm', ttfm);
  108. }.bind(this));
  109. };
  110. module.exports = JitsiRemoteTrack;