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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
  17. function LocalStream(stream, type, eventEmitter, videoType, isGUMStream)
  18. {
  19. this.stream = stream;
  20. this.eventEmitter = eventEmitter;
  21. this.type = type;
  22. this.videoType = videoType;
  23. this.isGUMStream = true;
  24. if(isGUMStream === false)
  25. this.isGUMStream = isGUMStream;
  26. var self = this;
  27. if(type == "audio")
  28. {
  29. this.getTracks = function () {
  30. return self.stream.getAudioTracks();
  31. };
  32. }
  33. else
  34. {
  35. this.getTracks = function () {
  36. return self.stream.getVideoTracks();
  37. };
  38. }
  39. this.stream.onended = function()
  40. {
  41. self.streamEnded();
  42. };
  43. }
  44. LocalStream.prototype.streamEnded = function () {
  45. this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
  46. }
  47. LocalStream.prototype.getOriginalStream = function()
  48. {
  49. return this.stream;
  50. }
  51. LocalStream.prototype.isAudioStream = function () {
  52. return this.type === "audio";
  53. };
  54. LocalStream.prototype.setMute = function(mute)
  55. {
  56. if((window.location.protocol != "https:" && this.isGUMStream) ||
  57. (this.isAudioStream() && this.isGUMStream) || this.videoType === "screen")
  58. {
  59. var tracks = this.getTracks();
  60. for (var idx = 0; idx < tracks.length; idx++) {
  61. tracks[idx].enabled = mute;
  62. }
  63. }
  64. else
  65. {
  66. if(mute === false) {
  67. APP.xmpp.removeStream(this.stream);
  68. this.stream.stop();
  69. }
  70. else
  71. {
  72. var self = this;
  73. APP.RTC.rtcUtils.obtainAudioAndVideoPermissions(
  74. (this.isAudioStream() ? ["audio"] : ["video"]),
  75. function (stream) {
  76. if(self.isAudioStream())
  77. {
  78. APP.RTC.changeLocalAudio(stream, function () {});
  79. }
  80. else
  81. {
  82. APP.RTC.changeLocalVideo(stream, false, function () {});
  83. }
  84. });
  85. }
  86. }
  87. };
  88. LocalStream.prototype.isMuted = function () {
  89. var tracks = [];
  90. if(this.type == "audio")
  91. {
  92. tracks = this.stream.getAudioTracks();
  93. }
  94. else
  95. {
  96. if(this.stream.ended)
  97. return true;
  98. tracks = this.stream.getVideoTracks();
  99. }
  100. for (var idx = 0; idx < tracks.length; idx++) {
  101. if(tracks[idx].enabled)
  102. return false;
  103. }
  104. return true;
  105. }
  106. LocalStream.prototype.getId = function () {
  107. return this.stream.getTracks()[0].id;
  108. }
  109. module.exports = LocalStream;