Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

JitsiRemoteTrack.js 4.1KB

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