Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MediaStream.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. ////These lines should be uncommented when require works in app.js
  17. var MediaStreamType = require("../../service/RTC/MediaStreamTypes");
  18. var StreamEventType = require("../../service/RTC/StreamEventTypes");
  19. /**
  20. * Creates a MediaStream object for the given data, session id and ssrc.
  21. * It is a wrapper class for the MediaStream.
  22. *
  23. * @param data the data object from which we obtain the stream,
  24. * the peerjid, etc.
  25. * @param sid the session id
  26. * @param ssrc the ssrc corresponding to this MediaStream
  27. *
  28. * @constructor
  29. */
  30. function MediaStream(data, sid, ssrc, browser, eventEmitter) {
  31. // XXX(gp) to minimize headaches in the future, we should build our
  32. // abstractions around tracks and not streams. ORTC is track based API.
  33. // Mozilla expects m-lines to represent media tracks.
  34. //
  35. // Practically, what I'm saying is that we should have a MediaTrack class
  36. // and not a MediaStream class.
  37. //
  38. // Also, we should be able to associate multiple SSRCs with a MediaTrack as
  39. // a track might have an associated RTX and FEC sources.
  40. this.sid = sid;
  41. this.stream = data.stream;
  42. this.peerjid = data.peerjid;
  43. this.ssrc = ssrc;
  44. this.type = (this.stream.getVideoTracks().length > 0)?
  45. MediaStreamType.VIDEO_TYPE : MediaStreamType.AUDIO_TYPE;
  46. this.videoType = null;
  47. this.muted = false;
  48. this.eventEmitter = eventEmitter;
  49. }
  50. MediaStream.prototype.getOriginalStream = function()
  51. {
  52. return this.stream;
  53. };
  54. MediaStream.prototype.setMute = function (value)
  55. {
  56. this.stream.muted = value;
  57. this.muted = value;
  58. };
  59. MediaStream.prototype.setVideoType = function (value) {
  60. if(this.videoType === value)
  61. return;
  62. this.videoType = value;
  63. this.eventEmitter.emit(StreamEventType.EVENT_TYPE_REMOTE_CHANGED,
  64. this.peerjid);
  65. };
  66. module.exports = MediaStream;