Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LocalStream.js 3.4KB

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