您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JitsiTrack.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. this.rtc = RTC;
  26. this.stream = stream;
  27. this.type = (this.stream.getVideoTracks().length > 0)?
  28. JitsiTrack.VIDEO : JitsiTrack.AUDIO;
  29. if(this.type == "audio") {
  30. this._getTracks = function () {
  31. return this.stream.getAudioTracks();
  32. }.bind(this);
  33. } else {
  34. this._getTracks = function () {
  35. return this.stream.getVideoTracks();
  36. }.bind(this);
  37. }
  38. if (RTCBrowserType.isFirefox() && this.stream) {
  39. implementOnEndedHandling(this.stream);
  40. }
  41. }
  42. /**
  43. * JitsiTrack video type.
  44. * @type {string}
  45. */
  46. JitsiTrack.VIDEO = "video";
  47. /**
  48. * JitsiTrack audio type.
  49. * @type {string}
  50. */
  51. JitsiTrack.AUDIO = "audio";
  52. /**
  53. * Returns the type (audio or video) of this track.
  54. */
  55. JitsiTrack.prototype.getType = function() {
  56. return this.type;
  57. };
  58. /**
  59. * Returns the RTCMediaStream from the browser (?).
  60. */
  61. JitsiTrack.prototype.getOriginalStream = function() {
  62. return this.stream;
  63. }
  64. /**
  65. * Mutes the track.
  66. */
  67. JitsiTrack.prototype.mute = function () {
  68. this._setMute(true);
  69. }
  70. /**
  71. * Unmutes the stream.
  72. */
  73. JitsiTrack.prototype.unmute = function () {
  74. this._setMute(false);
  75. }
  76. /**
  77. * Attaches the MediaStream of this track to an HTML container (?).
  78. * @param container the HTML container
  79. */
  80. JitsiTrack.prototype.attach = function (container) {
  81. RTC.attachMediaStream(container, this.stream);
  82. }
  83. /**
  84. * Removes the track from the passed HTML container.
  85. * @param container the HTML container
  86. */
  87. JitsiTrack.prototype.detach = function (container) {
  88. $(container).find(">video").remove();
  89. }
  90. /**
  91. * Stops sending the media track. And removes it from the HTML.
  92. * NOTE: Works for local tracks only.
  93. */
  94. JitsiTrack.prototype.stop = function () {
  95. this.detach();
  96. }
  97. /**
  98. * Starts sending the track.
  99. * NOTE: Works for local tracks only.
  100. */
  101. JitsiTrack.prototype.start = function() {
  102. }
  103. /**
  104. * Returns true if this is a video track and the source of the video is a
  105. * screen capture as opposed to a camera.
  106. */
  107. JitsiTrack.prototype.isScreenSharing = function(){
  108. }
  109. /**
  110. * Returns id of the track.
  111. * @returns {string} id of the track or null if this is fake track.
  112. */
  113. JitsiTrack.prototype.getId = function () {
  114. var tracks = this.stream.getTracks();
  115. if(!tracks || tracks.length === 0)
  116. return null;
  117. return tracks[0].id;
  118. };
  119. module.exports = JitsiTrack;