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 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var RTC = require("./RTCUtils");
  2. /**
  3. * Represents a single media track (either audio or video).
  4. * @constructor
  5. */
  6. function JitsiTrack(RTC, stream)
  7. {
  8. this.rtc = RTC;
  9. this.stream = stream;
  10. this.type = (this.stream.getVideoTracks().length > 0)?
  11. JitsiTrack.VIDEO : JitsiTrack.AUDIO;
  12. if(this.type == "audio") {
  13. this._getTracks = function () {
  14. return this.stream.getAudioTracks();
  15. }.bind(this);
  16. } else {
  17. this._getTracks = function () {
  18. return this.stream.getVideoTracks();
  19. }.bind(this);
  20. }
  21. }
  22. /**
  23. * JitsiTrack video type.
  24. * @type {string}
  25. */
  26. JitsiTrack.VIDEO = "video";
  27. /**
  28. * JitsiTrack audio type.
  29. * @type {string}
  30. */
  31. JitsiTrack.AUDIO = "audio";
  32. /**
  33. * Returns the type (audio or video) of this track.
  34. */
  35. JitsiTrack.prototype.getType = function() {
  36. return this.type;
  37. };
  38. /**
  39. * @returns {JitsiParticipant} to which this track belongs, or null if it is a local track.
  40. */
  41. JitsiTrack.prototype.getParitcipant = function() {
  42. };
  43. /**
  44. * Returns the RTCMediaStream from the browser (?).
  45. */
  46. JitsiTrack.prototype.getOriginalStream = function() {
  47. return this.stream;
  48. }
  49. /**
  50. * Mutes the track.
  51. */
  52. JitsiTrack.prototype.mute = function () {
  53. this._setMute(true);
  54. }
  55. /**
  56. * Unmutes the stream.
  57. */
  58. JitsiTrack.prototype.unmute = function () {
  59. this._setMute(false);
  60. }
  61. /**
  62. * Attaches the MediaStream of this track to an HTML container (?).
  63. * @param container the HTML container
  64. */
  65. JitsiTrack.prototype.attach = function (container) {
  66. RTC.attachMediaStream(container, this.stream);
  67. }
  68. /**
  69. * Removes the track from the passed HTML container.
  70. * @param container the HTML container
  71. */
  72. JitsiTrack.prototype.detach = function (container) {
  73. $(container).find(">video").remove();
  74. }
  75. /**
  76. * Stops sending the media track. And removes it from the HTML.
  77. * NOTE: Works for local tracks only.
  78. */
  79. JitsiTrack.prototype.stop = function () {
  80. this.detach();
  81. }
  82. /**
  83. * Starts sending the track.
  84. * NOTE: Works for local tracks only.
  85. */
  86. JitsiTrack.prototype.start = function() {
  87. }
  88. /**
  89. * Returns true if this is a video track and the source of the video is a
  90. * screen capture as opposed to a camera.
  91. */
  92. JitsiTrack.prototype.isScreenSharing = function(){
  93. }
  94. /**
  95. * Returns id of the track.
  96. * @returns {string} id of the track or null if this is fake track.
  97. */
  98. JitsiTrack.prototype.getId = function () {
  99. var tracks = this.stream.getTracks();
  100. if(!tracks || tracks.length === 0)
  101. return null;
  102. return tracks[0].id;
  103. };
  104. module.exports = JitsiTrack;