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.

JitsiTrack.js 3.5KB

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