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.

LocalStream.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  2. function LocalStream(stream, type, eventEmitter, videoType, isGUMStream)
  3. {
  4. this.stream = stream;
  5. this.eventEmitter = eventEmitter;
  6. this.type = type;
  7. this.videoType = videoType;
  8. this.isGUMStream = true;
  9. if(isGUMStream === false)
  10. this.isGUMStream = isGUMStream;
  11. var self = this;
  12. if(type == "audio")
  13. {
  14. this.getTracks = function () {
  15. return self.stream.getAudioTracks();
  16. };
  17. }
  18. else
  19. {
  20. this.getTracks = function () {
  21. return self.stream.getVideoTracks();
  22. };
  23. }
  24. this.stream.onended = function()
  25. {
  26. self.streamEnded();
  27. };
  28. }
  29. LocalStream.prototype.streamEnded = function () {
  30. this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
  31. }
  32. LocalStream.prototype.getOriginalStream = function()
  33. {
  34. return this.stream;
  35. }
  36. LocalStream.prototype.isAudioStream = function () {
  37. return this.type === "audio";
  38. };
  39. LocalStream.prototype.setMute = function(mute)
  40. {
  41. if((window.location.protocol != "https:" && this.isGUMStream) ||
  42. (this.isAudioStream() && this.isGUMStream) || this.videoType === "screen")
  43. {
  44. var tracks = this.getTracks();
  45. for (var idx = 0; idx < tracks.length; idx++) {
  46. tracks[idx].enabled = mute;
  47. }
  48. }
  49. else
  50. {
  51. if(mute === false) {
  52. APP.xmpp.removeStream(this.stream);
  53. this.stream.stop();
  54. }
  55. else
  56. {
  57. var self = this;
  58. APP.RTC.rtcUtils.obtainAudioAndVideoPermissions(
  59. (this.isAudioStream() ? ["audio"] : ["video"]),
  60. function (stream) {
  61. if(self.isAudioStream())
  62. {
  63. APP.RTC.changeLocalAudio(stream, function () {});
  64. }
  65. else
  66. {
  67. APP.RTC.changeLocalVideo(stream, false, function () {});
  68. }
  69. });
  70. }
  71. }
  72. };
  73. LocalStream.prototype.isMuted = function () {
  74. var tracks = [];
  75. if(this.type == "audio")
  76. {
  77. tracks = this.stream.getAudioTracks();
  78. }
  79. else
  80. {
  81. if(this.stream.ended)
  82. return true;
  83. tracks = this.stream.getVideoTracks();
  84. }
  85. for (var idx = 0; idx < tracks.length; idx++) {
  86. if(tracks[idx].enabled)
  87. return false;
  88. }
  89. return true;
  90. }
  91. LocalStream.prototype.getId = function () {
  92. return this.stream.getTracks()[0].id;
  93. }
  94. module.exports = LocalStream;