modified lib-jitsi-meet dev repo
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var RTC = require("./RTCUtils");
  2. var RTCBrowserType = require("./RTCBrowserType");
  3. /**
  4. * This implements 'onended' callback normally fired by WebRTC after the stream
  5. * is stopped. There is no such behaviour yet in FF, so we have to add it.
  6. * @param stream original WebRTC stream object to which 'onended' handling
  7. * will be added.
  8. */
  9. function implementOnEndedHandling(stream) {
  10. var originalStop = stream.stop;
  11. stream.stop = function () {
  12. originalStop.apply(stream);
  13. if (!stream.ended) {
  14. stream.ended = true;
  15. stream.onended();
  16. }
  17. };
  18. }
  19. /**
  20. * Represents a single media track (either audio or video).
  21. * @constructor
  22. */
  23. function JitsiTrack(RTC, stream)
  24. {
  25. /**
  26. * Array with the HTML elements that are displaying the streams.
  27. * @type {Array}
  28. */
  29. this.containers = [];
  30. this.rtc = RTC;
  31. this.stream = stream;
  32. this.type = (this.stream.getVideoTracks().length > 0)?
  33. JitsiTrack.VIDEO : JitsiTrack.AUDIO;
  34. if(this.type == "audio") {
  35. this._getTracks = function () {
  36. return this.stream.getAudioTracks();
  37. }.bind(this);
  38. } else {
  39. this._getTracks = function () {
  40. return this.stream.getVideoTracks();
  41. }.bind(this);
  42. }
  43. if (RTCBrowserType.isFirefox() && this.stream) {
  44. implementOnEndedHandling(this.stream);
  45. }
  46. }
  47. /**
  48. * JitsiTrack video type.
  49. * @type {string}
  50. */
  51. JitsiTrack.VIDEO = "video";
  52. /**
  53. * JitsiTrack audio type.
  54. * @type {string}
  55. */
  56. JitsiTrack.AUDIO = "audio";
  57. /**
  58. * Returns the type (audio or video) of this track.
  59. */
  60. JitsiTrack.prototype.getType = function() {
  61. return this.type;
  62. };
  63. /**
  64. * Returns the RTCMediaStream from the browser (?).
  65. */
  66. JitsiTrack.prototype.getOriginalStream = function() {
  67. return this.stream;
  68. }
  69. /**
  70. * Mutes the track.
  71. */
  72. JitsiTrack.prototype.mute = function () {
  73. this._setMute(true);
  74. }
  75. /**
  76. * Unmutes the stream.
  77. */
  78. JitsiTrack.prototype.unmute = function () {
  79. this._setMute(false);
  80. }
  81. /**
  82. * Attaches the MediaStream of this track to an HTML container (?).
  83. * Adds the container to the list of containers that are displaying the track.
  84. * @param container the HTML container
  85. */
  86. JitsiTrack.prototype.attach = function (container) {
  87. if(this.stream)
  88. RTC.attachMediaStream(container, this.stream);
  89. this.containers.push(container);
  90. }
  91. /**
  92. * Removes the track from the passed HTML container.
  93. * @param container the HTML container. If <tt>null</tt> all containers are removed.
  94. */
  95. JitsiTrack.prototype.detach = function (container) {
  96. for(var i = 0; i < this.containers.length; i++)
  97. {
  98. if(this.containers[i].is(container))
  99. {
  100. this.containers.splice(i,1);
  101. }
  102. if(!container)
  103. {
  104. this.containers[i].find(">video").remove();
  105. }
  106. }
  107. if(container)
  108. $(container).find(">video").remove();
  109. }
  110. /**
  111. * Stops sending the media track. And removes it from the HTML.
  112. * NOTE: Works for local tracks only.
  113. */
  114. JitsiTrack.prototype.stop = function () {
  115. }
  116. /**
  117. * Starts sending the track.
  118. * NOTE: Works for local tracks only.
  119. */
  120. JitsiTrack.prototype.start = function() {
  121. }
  122. /**
  123. * Returns true if this is a video track and the source of the video is a
  124. * screen capture as opposed to a camera.
  125. */
  126. JitsiTrack.prototype.isScreenSharing = function(){
  127. }
  128. /**
  129. * Returns id of the track.
  130. * @returns {string} id of the track or null if this is fake track.
  131. */
  132. JitsiTrack.prototype.getId = function () {
  133. var tracks = this.stream.getTracks();
  134. if(!tracks || tracks.length === 0)
  135. return null;
  136. return tracks[0].id;
  137. };
  138. module.exports = JitsiTrack;