| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 | 
							- /* global APP */
 - var EventEmitter = require("events");
 - var RTCBrowserType = require("./RTCBrowserType");
 - var RTCUtils = require("./RTCUtils.js");
 - var JitsiTrack = require("./JitsiTrack");
 - var JitsiLocalTrack = require("./JitsiLocalTrack.js");
 - var DataChannels = require("./DataChannels");
 - var JitsiRemoteTrack = require("./JitsiRemoteTrack.js");
 - var MediaStreamType = require("../../service/RTC/MediaStreamTypes");
 - var RTCEvents = require("../../service/RTC/RTCEvents.js");
 - 
 - function createLocalTracks(streams, options) {
 -     var newStreams = []
 -     var deviceId = null;
 -     for (var i = 0; i < streams.length; i++) {
 -         if (streams[i].type === 'audio') {
 -           deviceId = options.micDeviceId;
 -         } else if (streams[i].videoType === 'camera'){
 -           deviceId = options.cameraDeviceId;
 -         }
 -         var localStream = new JitsiLocalTrack(streams[i].stream,
 -             streams[i].videoType, streams[i].resolution, deviceId);
 -         newStreams.push(localStream);
 -         if (streams[i].isMuted === true)
 -             localStream.setMute(true);
 -     }
 -     return newStreams;
 - }
 - 
 - function RTC(room, options) {
 -     this.room = room;
 -     this.localStreams = [];
 -     //FIXME: We should support multiple streams per jid.
 -     this.remoteStreams = {};
 -     this.localAudio = null;
 -     this.localVideo = null;
 -     this.eventEmitter = new EventEmitter();
 -     var self = this;
 -     this.options = options || {};
 -     room.addPresenceListener("videomuted", function (values, from) {
 -         if(self.remoteStreams[from]) {
 -             // If there is no video track, but we receive it is muted,
 -             // we need to create a dummy track which we will mute, so we can
 -             // notify interested about the muting
 -             if(!self.remoteStreams[from][JitsiTrack.VIDEO]) {
 -                 var track = self.createRemoteStream(
 -                     {peerjid:room.roomjid + "/" + from,
 -                      videoType:"camera",
 -                      jitsiTrackType:JitsiTrack.VIDEO},
 -                     null, null);
 -                 self.eventEmitter
 -                     .emit(RTCEvents.FAKE_VIDEO_TRACK_CREATED, track);
 -             }
 - 
 -             self.remoteStreams[from][JitsiTrack.VIDEO]
 -                 .setMute(values.value == "true");
 -         }
 -     });
 -     room.addPresenceListener("audiomuted", function (values, from) {
 -         if(self.remoteStreams[from]) {
 -             self.remoteStreams[from][JitsiTrack.AUDIO]
 -                 .setMute(values.value == "true");
 -         }
 -     });
 -     room.addPresenceListener("videoType", function(data, from) {
 -         if(!self.remoteStreams[from] ||
 -             (!self.remoteStreams[from][JitsiTrack.VIDEO]))
 -             return;
 -         self.remoteStreams[from][JitsiTrack.VIDEO]._setVideoType(data.value);
 -     });
 - }
 - 
 - /**
 -  * Creates the local MediaStreams.
 -  * @param {Object} [options] optional parameters
 -  * @param {Array} options.devices the devices that will be requested
 -  * @param {string} options.resolution resolution constraints
 -  * @param {bool} options.dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
 -  * type: "audio" or "video", videoType: "camera" or "desktop"}
 -  * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
 -  * @param {string} options.cameraDeviceId
 -  * @param {string} options.micDeviceId
 -  * @returns {*} Promise object that will receive the new JitsiTracks
 -  */
 - 
 - RTC.obtainAudioAndVideoPermissions = function (options) {
 -     return RTCUtils.obtainAudioAndVideoPermissions(options).then(function (streams) {
 -         return createLocalTracks(streams, options);
 -     });
 - }
 - 
 - RTC.prototype.onIncommingCall = function(event) {
 -     if(this.options.config.openSctp)
 -         this.dataChannels = new DataChannels(event.peerconnection, this.eventEmitter);
 -     for(var i = 0; i < this.localStreams.length; i++)
 -         if(this.localStreams[i])
 -         {
 -             this.room.addStream(this.localStreams[i].getOriginalStream(), function () {});
 -         }
 - }
 - 
 - RTC.prototype.selectedEndpoint = function (id) {
 -     if(this.dataChannels)
 -         this.dataChannels.handleSelectedEndpointEvent(id);
 - }
 - 
 - RTC.prototype.pinEndpoint = function (id) {
 -     if(this.dataChannels)
 -         this.dataChannels.handlePinnedEndpointEvent(id);
 - }
 - 
 - RTC.prototype.addListener = function (type, listener) {
 -     this.eventEmitter.on(type, listener);
 - };
 - 
 - RTC.prototype.removeListener = function (eventType, listener) {
 -     this.eventEmitter.removeListener(eventType, listener);
 - };
 - 
 - RTC.addListener = function (eventType, listener) {
 -     RTCUtils.addListener(eventType, listener);
 - }
 - 
 - RTC.removeListener = function (eventType, listener) {
 -     RTCUtils.removeListener(eventType, listener)
 - }
 - 
 - RTC.isRTCReady = function () {
 -     return RTCUtils.isRTCReady();
 - }
 - 
 - RTC.init = function (options) {
 -     this.options = options || {};
 -     return RTCUtils.init(this.options);
 - }
 - 
 - RTC.getDeviceAvailability = function () {
 -     return RTCUtils.getDeviceAvailability();
 - }
 - 
 - RTC.prototype.addLocalStream = function (stream) {
 -     this.localStreams.push(stream);
 -     stream._setRTC(this);
 - 
 -     if (stream.isAudioTrack()) {
 -         this.localAudio = stream;
 -     } else {
 -         this.localVideo = stream;
 -     }
 - };
 - 
 - /**
 -  * Get local video track.
 -  * @returns {JitsiLocalTrack}
 -  */
 - RTC.prototype.getLocalVideoStream = function () {
 -     return this.localVideo;
 - };
 - 
 - /**
 -  * Set mute for all local audio streams attached to the conference.
 -  * @param value the mute value
 -  */
 - RTC.prototype.setAudioMute = function (value) {
 -     for(var i = 0; i < this.localStreams.length; i++) {
 -         var stream = this.localStreams[i];
 -         if(stream.getType() !== "audio") {
 -             continue;
 -         }
 -         stream._setMute(value);
 -     }
 - }
 - 
 - RTC.prototype.removeLocalStream = function (stream) {
 -     var pos = this.localStreams.indexOf(stream);
 -     if (pos === -1) {
 -         return;
 -     }
 - 
 -     this.localStreams.splice(pos, 1);
 - 
 -     if (stream.isAudioTrack()) {
 -         this.localAudio = null;
 -     } else {
 -         this.localVideo = null;
 -     }
 - };
 - 
 - RTC.prototype.createRemoteStream = function (data, sid, thessrc) {
 -     var remoteStream = new JitsiRemoteTrack(this, data, sid, thessrc);
 -     if(!data.peerjid)
 -         return;
 -     var resource = Strophe.getResourceFromJid(data.peerjid);
 -     if(!this.remoteStreams[resource]) {
 -         this.remoteStreams[resource] = {};
 -     }
 -     this.remoteStreams[resource][remoteStream.type]= remoteStream;
 -     return remoteStream;
 - };
 - 
 - RTC.prototype.removeRemoteStream = function (resource) {
 -     if(this.remoteStreams[resource]) {
 -         delete this.remoteStreams[resource];
 -     }
 - };
 - 
 - RTC.getPCConstraints = function () {
 -     return RTCUtils.pc_constraints;
 - };
 - 
 - RTC.attachMediaStream =  function (elSelector, stream) {
 -     return RTCUtils.attachMediaStream(elSelector, stream);
 - };
 - 
 - RTC.getStreamID = function (stream) {
 -     return RTCUtils.getStreamID(stream);
 - };
 - 
 - RTC.getVideoSrc = function (element) {
 -     return RTCUtils.getVideoSrc(element);
 - };
 - 
 - /**
 -  * Returns true if retrieving the the list of input devices is supported and
 -  * false if not.
 -  */
 - RTC.isDeviceListAvailable = function () {
 -     return RTCUtils.isDeviceListAvailable();
 - };
 - 
 - /**
 -  * Returns true if changing the camera / microphone device is supported and
 -  * false if not.
 -  */
 - RTC.isDeviceChangeAvailable = function () {
 -     return RTCUtils.isDeviceChangeAvailable();
 - }
 - /**
 -  * Allows to receive list of available cameras/microphones.
 -  * @param {function} callback would receive array of devices as an argument
 -  */
 - RTC.enumerateDevices = function (callback) {
 -     RTCUtils.enumerateDevices(callback);
 - };
 - 
 - RTC.setVideoSrc = function (element, src) {
 -     RTCUtils.setVideoSrc(element, src);
 - };
 - 
 - /**
 -  * A method to handle stopping of the stream.
 -  * One point to handle the differences in various implementations.
 -  * @param mediaStream MediaStream object to stop.
 -  */
 - RTC.stopMediaStream = function (mediaStream) {
 -     RTCUtils.stopMediaStream(mediaStream);
 - };
 - 
 - /**
 -  * Returns whether the desktop sharing is enabled or not.
 -  * @returns {boolean}
 -  */
 - RTC.isDesktopSharingEnabled = function () {
 -     return RTCUtils.isDesktopSharingEnabled();
 - };
 - 
 - RTC.prototype.dispose = function() {
 - };
 - 
 - RTC.prototype.switchVideoStreams = function (newStream) {
 -     this.localVideo.stream = newStream;
 - 
 -     this.localStreams = [];
 - 
 -     //in firefox we have only one stream object
 -     if (this.localAudio.getOriginalStream() != newStream)
 -         this.localStreams.push(this.localAudio);
 -     this.localStreams.push(this.localVideo);
 - };
 - 
 - RTC.prototype.setAudioLevel = function (resource, audioLevel) {
 -     if(!resource)
 -         return;
 -     if(this.remoteStreams[resource] && this.remoteStreams[resource][JitsiTrack.AUDIO])
 -         this.remoteStreams[resource][JitsiTrack.AUDIO].setAudioLevel(audioLevel);
 - };
 - 
 - /**
 -  * Searches in localStreams(session stores ssrc for audio and video) and
 -  * remoteStreams for the ssrc and returns the corresponding resource.
 -  * @param ssrc the ssrc to check.
 -  */
 - RTC.prototype.getResourceBySSRC = function (ssrc) {
 -     if(ssrc == this.room.session.localStreamsSSRC.video
 -         || ssrc == this.room.session.localStreamsSSRC.audio) {
 -         return Strophe.getResourceFromJid(this.room.myroomjid);
 -     }
 - 
 -     var resultResource = null;
 -     $.each(this.remoteStreams, function (resource, remoteTracks) {
 -         if((remoteTracks[JitsiTrack.AUDIO]
 -                 && remoteTracks[JitsiTrack.AUDIO].getSSRC() == ssrc)
 -             || (remoteTracks[JitsiTrack.VIDEO]
 -                 && remoteTracks[JitsiTrack.VIDEO].getSSRC() == ssrc))
 -             resultResource = resource;
 -     });
 - 
 -     return resultResource;
 - };
 - 
 - module.exports = RTC;
 
 
  |