Sfoglia il codice sorgente

Detaches createLocalTracks from JitsiConference.

tags/v0.0.2
hristoterezov 9 anni fa
parent
commit
bc641dc45b

+ 25
- 12
JitsiConference.js Vedi File

@@ -30,6 +30,7 @@ function JitsiConference(options) {
30 30
     this.xmpp = this.connection.xmpp;
31 31
     this.eventEmitter = new EventEmitter();
32 32
     this.room = this.xmpp.createRoom(this.options.name, null, null, this.options.config);
33
+    this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
33 34
     this.rtc = new RTC(this.room, options);
34 35
     if(!options.config.disableAudioLevels)
35 36
         this.statistics = new Statistics();
@@ -56,18 +57,6 @@ JitsiConference.prototype.leave = function () {
56 57
     this.room = null;
57 58
 }
58 59
 
59
-/**
60
- * Creates the media tracks and returns them trough the callback.
61
- * @param options Object with properties / settings specifying the tracks which should be created.
62
- * should be created or some additional configurations about resolution for example.
63
- * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>} A promise that returns an array of created JitsiTracks if resolved,
64
- *     or a JitsiConferenceError if rejected.
65
- */
66
-JitsiConference.prototype.createLocalTracks = function (options) {
67
-    if(this.rtc)
68
-        return this.rtc.obtainAudioAndVideoPermissions(options || {});
69
-}
70
-
71 60
 /**
72 61
  * Returns the local tracks.
73 62
  */
@@ -178,6 +167,24 @@ JitsiConference.prototype.setDisplayName = function(name) {
178 167
     }
179 168
 }
180 169
 
170
+/**
171
+ * Adds JitsiLocalTrack object to the conference.
172
+ * @param track the JitsiLocalTrack object.
173
+ */
174
+JitsiConference.prototype.addTrack = function (track) {
175
+    this.rtc.addLocalStream(track);
176
+    this.room.addStream(track.getOriginalStream, function () {});
177
+}
178
+
179
+/**
180
+ * Removes JitsiLocalTrack object to the conference.
181
+ * @param track the JitsiLocalTrack object.
182
+ */
183
+JitsiConference.prototype.removeTrack = function (track) {
184
+    this.room.removeStream(track.getOriginalStream());
185
+    this.rtc.removeLocalStream(track);
186
+}
187
+
181 188
 /**
182 189
  * Elects the participant with the given id to be the selected participant or the speaker.
183 190
  * @param id the identifier of the participant
@@ -311,6 +318,12 @@ function setupListeners(conference) {
311 318
             function () {
312 319
                 conference.statistics.dispose();
313 320
             });
321
+        RTC.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED, function (devices) {
322
+            conference.room.updateDeviceAvailability(devices);
323
+        });
324
+        RTC.addListener(StreamEventTypes.TRACK_MUTE_CHANGED, function (track) {
325
+            conference.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
326
+        });
314 327
     }
315 328
 }
316 329
 

+ 12
- 1
JitsiMeetJS.js Vedi File

@@ -4,6 +4,7 @@ var JitsiConnectionEvents = require("./JitsiConnectionEvents");
4 4
 var JitsiConnectionErrors = require("./JitsiConnectionErrors");
5 5
 var JitsiConferenceErrors = require("./JitsiConferenceErrors");
6 6
 var Logger = require("jitsi-meet-logger");
7
+var RTC = require("./modules/RTC/RTC");
7 8
 
8 9
 /**
9 10
  * Namespace for the interface of Jitsi Meet Library.
@@ -21,10 +22,20 @@ var LibJitsiMeet = {
21 22
     },
22 23
     logLevels: Logger.levels,
23 24
     init: function (options) {
24
-        require("./modules/RTC/RTC").init(options || {});
25
+        RTC.init(options || {});
25 26
     },
26 27
     setLogLevel: function (level) {
27 28
         Logger.setLogLevel(level);
29
+    },
30
+    /**
31
+     * Creates the media tracks and returns them trough the callback.
32
+     * @param options Object with properties / settings specifying the tracks which should be created.
33
+     * should be created or some additional configurations about resolution for example.
34
+     * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>} A promise that returns an array of created JitsiTracks if resolved,
35
+     *     or a JitsiConferenceError if rejected.
36
+     */
37
+    createLocalTracks: function (options) {
38
+        return RTC.obtainAudioAndVideoPermissions(options || {});
28 39
     }
29 40
 };
30 41
 

+ 22
- 4
doc/example/example.js Vedi File

@@ -18,6 +18,19 @@ var options = {
18 18
     clientNode: 'http://jitsi.org/jitsimeet', // The name of client node advertised in XEP-0115 'c' stanza
19 19
 }
20 20
 
21
+
22
+
23
+// var options = {
24
+//     hosts: {
25
+//         domain: 'whatever.jitsi.net',
26
+//         muc: 'conference.whatever.jitsi.net', // FIXME: use XEP-0030
27
+//         bridge: 'jitsi-videobridge.whatever.jitsi.net', // FIXME: use XEP-0030
28
+//     },
29
+//     bosh: '//whatever.jitsi.net/http-bind?ROOM_NAME=conference2', // FIXME: use xep-0156 for that
30
+//     clientNode: 'http://jitsi.org/jitsimeet', // The name of client node advertised in XEP-0115 'c' stanza
31
+// }
32
+
33
+
21 34
 var confOptions = {
22 35
     openSctp: true,
23 36
     disableAudioLevels: true
@@ -34,7 +47,7 @@ function onLocalTracks(tracks)
34 47
     tracks[1].attach($("#localVideo"));
35 48
     for(var i = 0; i < localTracks.length; i++)
36 49
     {
37
-        localTracks[i].start();
50
+        console.log(localTracks[i]);
38 51
     }
39 52
 }
40 53
 
@@ -61,7 +74,10 @@ function onRemoteTrack(track) {
61 74
  */
62 75
 function onConferenceJoined () {
63 76
     console.log("conference joined!");
64
-    room.createLocalTracks({resolution: "720"}).then(onLocalTracks);
77
+    for(var i = 0; i < localTracks.length; i++)
78
+    {
79
+        room.addTrack(localTracks[i]);
80
+    }
65 81
 }
66 82
 
67 83
 function onUserLeft(id) {
@@ -120,10 +136,12 @@ function unload() {
120 136
 $(window).bind('beforeunload', unload);
121 137
 $(window).bind('unload', unload);
122 138
 
123
-JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
124 139
 
125
-JitsiMeetJS.init();
126 140
 
141
+// JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
142
+
143
+JitsiMeetJS.init();
144
+JitsiMeetJS.createLocalTracks({resolution: "720"}).then(onLocalTracks);
127 145
 var connection = new JitsiMeetJS.JitsiConnection(null, null, options);
128 146
 
129 147
 var room = null;

+ 447
- 376
lib-jitsi-meet.js
File diff soppresso perché troppo grande
Vedi File


+ 21
- 24
modules/RTC/JitsiLocalTrack.js Vedi File

@@ -1,25 +1,20 @@
1 1
 var JitsiTrack = require("./JitsiTrack");
2 2
 var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
3
-var RTC = require("./RTCUtils");
4 3
 var RTCBrowserType = require("./RTCBrowserType");
5 4
 
6 5
 /**
7 6
  * Represents a single media track (either audio or video).
8 7
  * @constructor
9 8
  */
10
-function JitsiLocalTrack(RTC, stream, eventEmitter, videoType, isGUMStream,
9
+function JitsiLocalTrack(RTC, stream, eventEmitter, videoType,
11 10
   resolution)
12 11
 {
13 12
     JitsiTrack.call(this, RTC, stream);
14 13
     this.eventEmitter = eventEmitter;
15 14
     this.videoType = videoType;
16
-    this.isGUMStream = true;
17 15
     this.dontFireRemoveEvent = false;
18
-    this.isStarted = false;
19 16
     this.resolution = resolution;
20 17
     var self = this;
21
-    if(isGUMStream === false)
22
-        this.isGUMStream = isGUMStream;
23 18
     this.stream.onended = function () {
24 19
         if(!self.dontFireRemoveEvent)
25 20
             self.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, self);
@@ -35,11 +30,15 @@ JitsiLocalTrack.prototype.constructor = JitsiLocalTrack;
35 30
  * @param mute {boolean} if true the track will be muted. Otherwise the track will be unmuted.
36 31
  */
37 32
 JitsiLocalTrack.prototype._setMute = function (mute) {
33
+    if(!this.rtc) {
34
+        console.error("Mute is not supported for streams not attached to conference!");
35
+        return;
36
+    }
38 37
     var isAudio = this.type === JitsiTrack.AUDIO;
39 38
     this.dontFireRemoveEvent = false;
40 39
 
41
-    if ((window.location.protocol != "https:" && this.isGUMStream) ||
42
-        (isAudio && this.isGUMStream) || this.videoType === "screen" ||
40
+    if ((window.location.protocol != "https:") ||
41
+        (isAudio) || this.videoType === "screen" ||
43 42
         // FIXME FF does not support 'removeStream' method used to mute
44 43
         RTCBrowserType.isFirefox()) {
45 44
 
@@ -66,9 +65,10 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
66 65
             //FIXME: Maybe here we should set the SRC for the containers to something
67 66
         } else {
68 67
             var self = this;
69
-            this.rtc.obtainAudioAndVideoPermissions(
70
-                {devices: (isAudio ? ["audio"] : ["video"]),
71
-                  resolution: self.resolution}, true)
68
+            var RTC = require("./RTCUtils");
69
+            RTC.obtainAudioAndVideoPermissions(
70
+                (isAudio ? ["audio"] : ["video"]),
71
+                  self.resolution, true)
72 72
                 .then(function (streams) {
73 73
                     var stream = null;
74 74
                     for(var i = 0; i < streams.length; i++) {
@@ -76,7 +76,6 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
76 76
                         if(stream.type === self.type) {
77 77
                             self.stream = stream.stream;
78 78
                             self.videoType = stream.videoType;
79
-                            self.isGUMStream = stream.isGUMStream;
80 79
                             break;
81 80
                         }
82 81
                     }
@@ -109,22 +108,12 @@ JitsiLocalTrack.prototype._setMute = function (mute) {
109 108
 JitsiLocalTrack.prototype.stop = function () {
110 109
     if(!this.stream)
111 110
         return;
112
-    this.rtc.room.removeStream(this.stream);
111
+    if(this.rtc)
112
+        this.rtc.room.removeStream(this.stream);
113 113
     this.stream.stop();
114 114
     this.detach();
115 115
 }
116 116
 
117
-
118
-/**
119
- * Starts sending the track.
120
- * NOTE: Works for local tracks only.
121
- */
122
-JitsiLocalTrack.prototype.start = function() {
123
-    this.isStarted = true;
124
-    this.rtc.room.addStream(this.stream, function () {});
125
-}
126
-
127
-
128 117
 /**
129 118
  * Returns <tt>true</tt> - if the stream is muted
130 119
  * and <tt>false</tt> otherwise.
@@ -150,4 +139,12 @@ JitsiLocalTrack.prototype.isMuted = function () {
150 139
     return true;
151 140
 };
152 141
 
142
+/**
143
+ * Private method. Updates rtc property of the track.
144
+ * @param rtc the rtc instance.
145
+ */
146
+JitsiLocalTrack.prototype._setRTC = function (rtc) {
147
+    this.rtc = rtc;
148
+};
149
+
153 150
 module.exports = JitsiLocalTrack;

+ 3
- 13
modules/RTC/JitsiTrack.js Vedi File

@@ -1,4 +1,3 @@
1
-var RTC = require("./RTCUtils");
2 1
 var RTCBrowserType = require("./RTCBrowserType");
3 2
 
4 3
 /**
@@ -22,14 +21,14 @@ function implementOnEndedHandling(stream) {
22 21
  * Represents a single media track (either audio or video).
23 22
  * @constructor
24 23
  */
25
-function JitsiTrack(RTC, stream)
24
+function JitsiTrack(rtc, stream)
26 25
 {
27 26
     /**
28 27
      * Array with the HTML elements that are displaying the streams.
29 28
      * @type {Array}
30 29
      */
31 30
     this.containers = [];
32
-    this.rtc = RTC;
31
+    this.rtc = rtc;
33 32
     this.stream = stream;
34 33
     this.type = (this.stream.getVideoTracks().length > 0)?
35 34
         JitsiTrack.VIDEO : JitsiTrack.AUDIO;
@@ -94,7 +93,7 @@ JitsiTrack.prototype.unmute = function () {
94 93
  */
95 94
 JitsiTrack.prototype.attach = function (container) {
96 95
     if(this.stream)
97
-        RTC.attachMediaStream(container, this.stream);
96
+        require("./RTCUtils").attachMediaStream(container, this.stream);
98 97
     this.containers.push(container);
99 98
 }
100 99
 
@@ -126,15 +125,6 @@ JitsiTrack.prototype.detach = function (container) {
126 125
 JitsiTrack.prototype.stop = function () {
127 126
 }
128 127
 
129
-
130
-/**
131
- * Starts sending the track.
132
- * NOTE: Works for local tracks only.
133
- */
134
-JitsiTrack.prototype.start = function() {
135
-
136
-}
137
-
138 128
 /**
139 129
  * Returns true if this is a video track and the source of the video is a
140 130
  * screen capture as opposed to a camera.

+ 0
- 125
modules/RTC/LocalStream.js Vedi File

@@ -1,125 +0,0 @@
1
-/* global APP */
2
-var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
3
-var RTCEvents = require("../../service/RTC/RTCEvents");
4
-var RTCBrowserType = require("./RTCBrowserType");
5
-
6
-/**
7
- * This implements 'onended' callback normally fired by WebRTC after the stream
8
- * is stopped. There is no such behaviour yet in FF, so we have to add it.
9
- * @param stream original WebRTC stream object to which 'onended' handling
10
- *               will be added.
11
- */
12
-function implementOnEndedHandling(stream) {
13
-    var originalStop = stream.stop;
14
-    stream.stop = function () {
15
-        originalStop.apply(stream);
16
-        if (!stream.ended) {
17
-            stream.ended = true;
18
-            stream.onended();
19
-        }
20
-    };
21
-}
22
-
23
-function LocalStream(RTC, stream, type, eventEmitter, videoType, isGUMStream) {
24
-    this.rtc = RTC;
25
-    this.stream = stream;
26
-    this.eventEmitter = eventEmitter;
27
-    this.type = type;
28
-    this.videoType = videoType;
29
-    this.isGUMStream = true;
30
-    if(isGUMStream === false)
31
-        this.isGUMStream = isGUMStream;
32
-    var self = this;
33
-    if(type == "audio") {
34
-        this.getTracks = function () {
35
-            return self.stream.getAudioTracks();
36
-        };
37
-    } else {
38
-        this.getTracks = function () {
39
-            return self.stream.getVideoTracks();
40
-        };
41
-    }
42
-
43
-    this.stream.onended = function () {
44
-        self.streamEnded();
45
-    };
46
-    if (RTCBrowserType.isFirefox()) {
47
-        implementOnEndedHandling(this.stream);
48
-    }
49
-}
50
-
51
-LocalStream.prototype.streamEnded = function () {
52
-    this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
53
-};
54
-
55
-LocalStream.prototype.getOriginalStream = function()
56
-{
57
-    return this.stream;
58
-};
59
-
60
-LocalStream.prototype.isAudioStream = function () {
61
-    return this.type === "audio";
62
-};
63
-
64
-LocalStream.prototype.setMute = function (mute)
65
-{
66
-    var isAudio = this.isAudioStream();
67
-    var eventType = isAudio ? RTCEvents.AUDIO_MUTE : RTCEvents.VIDEO_MUTE;
68
-
69
-    if ((window.location.protocol != "https:" && this.isGUMStream) ||
70
-        (isAudio && this.isGUMStream) || this.videoType === "screen" ||
71
-        // FIXME FF does not support 'removeStream' method used to mute
72
-        RTCBrowserType.isFirefox()) {
73
-
74
-        var tracks = this.getTracks();
75
-        for (var idx = 0; idx < tracks.length; idx++) {
76
-            tracks[idx].enabled = !mute;
77
-        }
78
-        this.eventEmitter.emit(eventType, mute);
79
-    } else {
80
-        if (mute) {
81
-            APP.xmpp.removeStream(this.stream);
82
-            this.stream.stop();
83
-            this.eventEmitter.emit(eventType, true);
84
-        } else {
85
-            var self = this;
86
-            this.rtc.obtainAudioAndVideoPermissions(
87
-                {devices: (this.isAudioStream() ? ["audio"] : ["video"])})
88
-                .then(function (stream) {
89
-                    if (isAudio) {
90
-                        self.rtc.changeLocalAudio(stream,
91
-                            function () {
92
-                                self.eventEmitter.emit(eventType, false);
93
-                            });
94
-                    } else {
95
-                        self.rtc.changeLocalVideo(stream, false,
96
-                            function () {
97
-                                self.eventEmitter.emit(eventType, false);
98
-                            });
99
-                    }
100
-                });
101
-        }
102
-    }
103
-};
104
-
105
-LocalStream.prototype.isMuted = function () {
106
-    var tracks = [];
107
-    if (this.isAudioStream()) {
108
-        tracks = this.stream.getAudioTracks();
109
-    } else {
110
-        if (this.stream.ended)
111
-            return true;
112
-        tracks = this.stream.getVideoTracks();
113
-    }
114
-    for (var idx = 0; idx < tracks.length; idx++) {
115
-        if(tracks[idx].enabled)
116
-            return false;
117
-    }
118
-    return true;
119
-};
120
-
121
-LocalStream.prototype.getId = function () {
122
-    return this.stream.getTracks()[0].id;
123
-};
124
-
125
-module.exports = LocalStream;

+ 0
- 47
modules/RTC/MediaStream.js Vedi File

@@ -1,47 +0,0 @@
1
-var MediaStreamType = require("../../service/RTC/MediaStreamTypes");
2
-
3
-/**
4
- * Creates a MediaStream object for the given data, session id and ssrc.
5
- * It is a wrapper class for the MediaStream.
6
- *
7
- * @param data the data object from which we obtain the stream,
8
- * the peerjid, etc.
9
- * @param sid the session id
10
- * @param ssrc the ssrc corresponding to this MediaStream
11
- *
12
- * @constructor
13
- */
14
-function MediaStream(data, sid, ssrc, browser, eventEmitter) {
15
-
16
-    // XXX(gp) to minimize headaches in the future, we should build our
17
-    // abstractions around tracks and not streams. ORTC is track based API.
18
-    // Mozilla expects m-lines to represent media tracks.
19
-    //
20
-    // Practically, what I'm saying is that we should have a MediaTrack class
21
-    // and not a MediaStream class.
22
-    //
23
-    // Also, we should be able to associate multiple SSRCs with a MediaTrack as
24
-    // a track might have an associated RTX and FEC sources.
25
-
26
-    this.sid = sid;
27
-    this.stream = data.stream;
28
-    this.peerjid = data.peerjid;
29
-    this.videoType = data.videoType;
30
-    this.ssrc = ssrc;
31
-    this.type = (this.stream.getVideoTracks().length > 0)?
32
-        MediaStreamType.VIDEO_TYPE : MediaStreamType.AUDIO_TYPE;
33
-    this.muted = false;
34
-    this.eventEmitter = eventEmitter;
35
-}
36
-
37
-
38
-MediaStream.prototype.getOriginalStream = function() {
39
-    return this.stream;
40
-};
41
-
42
-MediaStream.prototype.setMute = function (value) {
43
-    this.stream.muted = value;
44
-    this.muted = value;
45
-};
46
-
47
-module.exports = MediaStream;

+ 24
- 89
modules/RTC/RTC.js Vedi File

@@ -13,42 +13,7 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
13 13
 var RTCEvents = require("../../service/RTC/RTCEvents.js");
14 14
 var desktopsharing = require("../desktopsharing/desktopsharing");
15 15
 
16
-function getMediaStreamUsage()
17
-{
18
-    var result = {
19
-        audio: true,
20
-        video: true
21
-    };
22
-
23
-    /** There are some issues with the desktop sharing
24
-     * when this property is enabled.
25
-     * WARNING: We must change the implementation to start video/audio if we
26
-     * receive from the focus that the peer is not muted.
27
-
28
-     var isSecureConnection = window.location.protocol == "https:";
29
-
30
-    if(config.disableEarlyMediaPermissionRequests || !isSecureConnection)
31
-    {
32
-        result = {
33
-            audio: false,
34
-            video: false
35
-        };
36
-
37
-    }
38
-    **/
39
-
40
-    return result;
41
-}
42
-
43
-var rtcReady = false;
44
-
45
-
46
-
47 16
 function RTC(room, options) {
48
-    this.devices = {
49
-        audio: true,
50
-        video: true
51
-    };
52 17
     this.room = room;
53 18
     this.localStreams = [];
54 19
     this.remoteStreams = {};
@@ -75,22 +40,22 @@ function RTC(room, options) {
75 40
  * Creates the local MediaStreams.
76 41
  * @param options object for options (NOTE: currently only list of devices and resolution are supported)
77 42
  * @param dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
78
-  * type: "audio" or "video", isMuted: true/false, videoType: "camera" or "desktop"}
43
+  * type: "audio" or "video", videoType: "camera" or "desktop"}
79 44
  * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
80 45
  * @returns {*} Promise object that will receive the new JitsiTracks
81 46
  */
82
-RTC.prototype.obtainAudioAndVideoPermissions = function (options, dontCreateJitsiTrack) {
83
-    return RTCUtils.obtainAudioAndVideoPermissions(this,
84
-        options.devices, getMediaStreamUsage(), options.resolution, dontCreateJitsiTrack);
47
+RTC.obtainAudioAndVideoPermissions = function (options, dontCreateJitsiTrack) {
48
+    return RTCUtils.obtainAudioAndVideoPermissions(
49
+        options.devices, options.resolution, dontCreateJitsiTrack);
85 50
 }
86 51
 
87 52
 RTC.prototype.onIncommingCall = function(event) {
88 53
     if(this.options.config.openSctp)
89 54
         this.dataChannels = new DataChannels(event.peerconnection, this.eventEmitter);
90 55
     for(var i = 0; i < this.localStreams.length; i++)
91
-        if(this.localStreams[i].isStarted)
56
+        if(this.localStreams[i])
92 57
         {
93
-            this.localStreams[i].start();
58
+            this.room.addStream(this.localStreams[i].getOriginalStream(), function () {});
94 59
         }
95 60
 }
96 61
 
@@ -112,56 +77,36 @@ RTC.prototype.removeListener = function (eventType, listener) {
112 77
     this.eventEmitter.removeListener(eventType, listener);
113 78
 };
114 79
 
115
-RTC.addRTCReadyListener = function (listener) {
116
-    RTCUtils.eventEmitter.on(RTCEvents.RTC_READY, listener);
80
+RTC.addListener = function (eventType, listener) {
81
+    RTCUtils.addListener(eventType, listener);
117 82
 }
118 83
 
119
-RTC.removeRTCReadyListener = function (listener) {
84
+RTC.removeListener = function (eventType, listener) {
120 85
     RTCUtils.eventEmitter.removeListener(RTCEvents.RTC_READY, listener);
86
+    RTCUtils.removeListener(eventType, listener)
121 87
 }
122 88
 
123 89
 RTC.isRTCReady = function () {
124
-    return rtcReady;
90
+    return RTCUtils.isRTCReady();
125 91
 }
126 92
 
127 93
 RTC.init = function (options) {
128
-    // In case of IE we continue from 'onReady' callback
129
-// passed to RTCUtils constructor. It will be invoked by Temasys plugin
130
-// once it is initialized.
131
-    var onReady = function () {
132
-        rtcReady = true;
133
-        RTCUtils.eventEmitter.emit(RTCEvents.RTC_READY, true);
134
-    };
135
-
136
-    RTCUtils.init(onReady, options || {});
137
-
138
-// Call onReady() if Temasys plugin is not used
139
-    if (!RTCBrowserType.isTemasysPluginUsed()) {
140
-        onReady();
141
-    }
94
+    RTCUtils.init(options || {});
142 95
 }
143 96
 
144
-RTC.prototype.createLocalStreams = function (streams, change) {
145
-    for (var i = 0; i < streams.length; i++) {
146
-        var localStream = new JitsiLocalTrack(this, streams[i].stream,
147
-            this.eventEmitter, streams[i].videoType,
148
-            streams[i].isGUMStream, streams[i].resolution);
149
-        this.localStreams.push(localStream);
150
-        if (streams[i].isMuted === true)
151
-            localStream.setMute(true);
152
-
153
-        if (streams[i].type == "audio") {
154
-            this.localAudio = localStream;
155
-        } else {
156
-            this.localVideo = localStream;
157
-        }
158
-        var eventType = StreamEventTypes.EVENT_TYPE_LOCAL_CREATED;
159
-        if (change)
160
-            eventType = StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED;
97
+RTC.getDeviceAvailability = function () {
98
+    return RTCUtils.getDeviceAvailability();
99
+}
161 100
 
162
-        this.eventEmitter.emit(eventType, localStream, streams[i].isMuted);
101
+RTC.prototype.addLocalStream = function (stream) {
102
+    this.localStreams.push(stream);
103
+    stream._setRTC(this);
104
+
105
+    if (stream.type == "audio") {
106
+        this.localAudio = stream;
107
+    } else {
108
+        this.localVideo = stream;
163 109
     }
164
-    return this.localStreams;
165 110
 };
166 111
 
167 112
 RTC.prototype.removeLocalStream = function (stream) {
@@ -191,7 +136,7 @@ RTC.getPCConstraints = function () {
191 136
     return RTCUtils.pc_constraints;
192 137
 };
193 138
 
194
-RTC.prototype.getUserMediaWithConstraints = function(um, success_callback,
139
+RTC.getUserMediaWithConstraints = function(um, success_callback,
195 140
                                      failure_callback, resolution,
196 141
                                      bandwidth, fps, desktopStream)
197 142
 {
@@ -335,14 +280,4 @@ RTC.prototype.setVideoMute = function (mute, callback, options) {
335 280
     }
336 281
 };
337 282
 
338
-RTC.prototype.setDeviceAvailability = function (devices) {
339
-    if(!devices)
340
-        return;
341
-    if(devices.audio === true || devices.audio === false)
342
-        this.devices.audio = devices.audio;
343
-    if(devices.video === true || devices.video === false)
344
-        this.devices.video = devices.video;
345
-    this.eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, this.devices);
346
-};
347
-
348 283
 module.exports = RTC;

+ 96
- 79
modules/RTC/RTCUtils.js Vedi File

@@ -3,9 +3,21 @@
3 3
 var logger = require("jitsi-meet-logger").getLogger(__filename);
4 4
 var RTCBrowserType = require("./RTCBrowserType");
5 5
 var Resolutions = require("../../service/RTC/Resolutions");
6
+var RTCEvents = require("../../service/RTC/RTCEvents");
6 7
 var AdapterJS = require("./adapter.screenshare");
7 8
 var SDPUtil = require("../xmpp/SDPUtil");
8 9
 var EventEmitter = require("events");
10
+var JitsiLocalTrack = require("./JitsiLocalTrack");
11
+var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
12
+
13
+var eventEmitter = new EventEmitter();
14
+
15
+var devices = {
16
+    audio: true,
17
+    video: true
18
+};
19
+
20
+var rtcReady = false;
9 21
 
10 22
 function DummyMediaStream(id) {
11 23
     this.id = id;
@@ -143,10 +155,29 @@ function getConstraints(um, resolution, bandwidth, fps, desktopStream) {
143 155
     return constraints;
144 156
 }
145 157
 
158
+function setAvailableDevices(um, available) {
159
+    var devices = {};
160
+    if (um.indexOf("video") != -1) {
161
+        devices.video = available;
162
+    }
163
+    if (um.indexOf("audio") != -1) {
164
+        devices.audio = available;
165
+    }
166
+
167
+    eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, devices);
168
+}
169
+
170
+// In case of IE we continue from 'onReady' callback
171
+// passed to RTCUtils constructor. It will be invoked by Temasys plugin
172
+// once it is initialized.
173
+function onReady () {
174
+    rtcReady = true;
175
+    eventEmitter.emit(RTCEvents.RTC_READY, true);
176
+};
177
+
146 178
 //Options parameter is to pass config options. Currently uses only "useIPv6".
147 179
 var RTCUtils = {
148
-    eventEmitter: new EventEmitter(),
149
-    init: function (onTemasysPluginReady, options) {
180
+    init: function (options) {
150 181
         var self = this;
151 182
         if (RTCBrowserType.isFirefox()) {
152 183
             var FFversion = RTCBrowserType.getFirefoxVersion();
@@ -286,7 +317,7 @@ var RTCUtils = {
286 317
                     attachMediaStream(element, stream);
287 318
                 };
288 319
 
289
-                onTemasysPluginReady(isPlugin);
320
+                onReady(isPlugin);
290 321
             });
291 322
         } else {
292 323
             try {
@@ -296,26 +327,27 @@ var RTCUtils = {
296 327
             return;
297 328
         }
298 329
 
299
-    },
300
-
330
+        // Call onReady() if Temasys plugin is not used
331
+        if (!RTCBrowserType.isTemasysPluginUsed()) {
332
+            onReady();
333
+        }
301 334
 
302
-    getUserMediaWithConstraints: function (RTC, um, success_callback, failure_callback, resolution, bandwidth, fps, desktopStream) {
335
+    },
336
+    getUserMediaWithConstraints: function ( um, success_callback, failure_callback, resolution, bandwidth, fps, desktopStream) {
303 337
         var constraints = getConstraints(
304 338
             um, resolution, bandwidth, fps, desktopStream);
305 339
 
306 340
         logger.info("Get media constraints", constraints);
307 341
 
308
-        var self = this;
309
-
310 342
         try {
311 343
             this.getUserMedia(constraints,
312 344
                 function (stream) {
313 345
                     logger.log('onUserMediaSuccess');
314
-                    self.setAvailableDevices(RTC, um, true);
346
+                    setAvailableDevices(um, true);
315 347
                     success_callback(stream);
316 348
                 },
317 349
                 function (error) {
318
-                    self.setAvailableDevices(RTC, um, false);
350
+                    setAvailableDevices(um, false);
319 351
                     logger.warn('Failed to get access to local media. Error ',
320 352
                         error, constraints);
321 353
                     if (failure_callback) {
@@ -330,54 +362,29 @@ var RTCUtils = {
330 362
         }
331 363
     },
332 364
 
333
-    setAvailableDevices: function (RTC, um, available) {
334
-        var devices = {};
335
-        if (um.indexOf("video") != -1) {
336
-            devices.video = available;
337
-        }
338
-        if (um.indexOf("audio") != -1) {
339
-            devices.audio = available;
340
-        }
341
-        RTC.setDeviceAvailability(devices);
342
-    },
343
-
344 365
     /**
345 366
      * Creates the local MediaStreams.
346
-     * @param RTC the rtc service.
347 367
      * @param devices the devices that will be requested
348
-     * @param usageOptions object with devices that should be requested.
349 368
      * @param resolution resolution constraints
350 369
      * @param dontCreateJitsiTrack if <tt>true</tt> objects with the following structure {stream: the Media Stream,
351
-     * type: "audio" or "video", isMuted: true/false, videoType: "camera" or "desktop"}
370
+     * type: "audio" or "video", videoType: "camera" or "desktop"}
352 371
      * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
353 372
      * @returns {*} Promise object that will receive the new JitsiTracks
354 373
      */
355
-    obtainAudioAndVideoPermissions: function (RTC, devices, usageOptions, resolution, dontCreateJitsiTracks) {
374
+    obtainAudioAndVideoPermissions: function (devices, resolution, dontCreateJitsiTracks) {
356 375
         var self = this;
357 376
         // Get AV
358 377
 
359 378
         return new Promise(function (resolve, reject) {
360 379
             var successCallback = function (stream) {
361
-                var streams = self.successCallback(RTC , stream, usageOptions, resolution);
362
-                resolve(dontCreateJitsiTracks? streams: RTC.createLocalStreams(streams));
380
+                var streams = self.successCallback(stream, resolution);
381
+                resolve(dontCreateJitsiTracks? streams: self.createLocalTracks(streams));
363 382
             };
364 383
 
365 384
             if (!devices)
366 385
                 devices = ['audio', 'video'];
367 386
 
368
-            var newDevices = [];
369
-
370
-
371
-            if (usageOptions)
372
-                for (var i = 0; i < devices.length; i++) {
373
-                    var device = devices[i];
374
-                    if (usageOptions[device] === true)
375
-                        newDevices.push(device);
376
-                }
377
-            else
378
-                newDevices = devices;
379
-
380
-            if (newDevices.length === 0) {
387
+            if (devices.length === 0) {
381 388
                 successCallback();
382 389
                 return;
383 390
             }
@@ -394,7 +401,6 @@ var RTCUtils = {
394 401
                 // the successCallback method.
395 402
                 var obtainVideo = function (audioStream) {
396 403
                     self.getUserMediaWithConstraints(
397
-                        RTC,
398 404
                         ['video'],
399 405
                         function (videoStream) {
400 406
                             return successCallback({
@@ -405,73 +411,68 @@ var RTCUtils = {
405 411
                         function (error, resolution) {
406 412
                             logger.error(
407 413
                                 'failed to obtain video stream - stop', error);
408
-                            self.errorCallback(error, resolve, RTC, resolution, dontCreateJitsiTracks);
414
+                            self.errorCallback(error, resolve, resolution, dontCreateJitsiTracks);
409 415
                         },
410 416
                             resolution || '360');
411 417
                 };
412 418
                 var obtainAudio = function () {
413 419
                     self.getUserMediaWithConstraints(
414
-                        RTC,
415 420
                         ['audio'],
416 421
                         function (audioStream) {
417
-                            if (newDevices.indexOf('video') !== -1)
422
+                            if (devices.indexOf('video') !== -1)
418 423
                                 obtainVideo(audioStream);
419 424
                         },
420 425
                         function (error) {
421 426
                             logger.error(
422 427
                                 'failed to obtain audio stream - stop', error);
423
-                            self.errorCallback(error, resolve, RTC, null, dontCreateJitsiTracks);
428
+                            self.errorCallback(error, resolve, null, dontCreateJitsiTracks);
424 429
                         }
425 430
                     );
426 431
                 };
427
-                if (newDevices.indexOf('audio') !== -1) {
432
+                if (devices.indexOf('audio') !== -1) {
428 433
                     obtainAudio();
429 434
                 } else {
430 435
                     obtainVideo(null);
431 436
                 }
432 437
             } else {
433 438
                 this.getUserMediaWithConstraints(
434
-                    RTC,
435
-                    newDevices,
439
+                    devices,
436 440
                     function (stream) {
437 441
                         successCallback(stream);
438 442
                     },
439 443
                     function (error, resolution) {
440
-                        self.errorCallback(error, resolve, RTC, resolution, dontCreateJitsiTracks);
444
+                        self.errorCallback(error, resolve, resolution, dontCreateJitsiTracks);
441 445
                     },
442
-                        resolution || '360');
446
+                    resolution || '360');
443 447
             }
444 448
         }.bind(this));
445 449
     },
446 450
 
447 451
     /**
448 452
      * Successful callback called from GUM.
449
-     * @param RTC the rtc service
450 453
      * @param stream the new MediaStream
451
-     * @param usageOptions the list of the devices that should be queried.
452 454
      * @param resolution the resolution of the video stream.
453 455
      * @returns {*}
454 456
      */
455
-    successCallback: function (RTC, stream, usageOptions, resolution) {
457
+    successCallback: function (stream, resolution) {
456 458
         // If this is FF or IE, the stream parameter is *not* a MediaStream object,
457 459
         // it's an object with two properties: audioStream, videoStream.
458 460
         if (stream && stream.getAudioTracks && stream.getVideoTracks)
459 461
             logger.log('got', stream, stream.getAudioTracks().length,
460 462
                 stream.getVideoTracks().length);
461
-        return this.handleLocalStream(RTC, stream, usageOptions, resolution);
463
+        return this.handleLocalStream(stream, resolution);
462 464
     },
463 465
 
464 466
     /**
465 467
      * Error callback called from GUM. Retries the GUM call with different resolutions.
466 468
      * @param error the error
467 469
      * @param resolve the resolve funtion that will be called on success.
468
-     * @param RTC the rtc service
469 470
      * @param currentResolution the last resolution used for GUM.
470 471
      * @param dontCreateJitsiTracks if <tt>true</tt> objects with the following structure {stream: the Media Stream,
471
-     * type: "audio" or "video", isMuted: true/false, videoType: "camera" or "desktop"}
472
+     * type: "audio" or "video", videoType: "camera" or "desktop"}
472 473
      * will be returned trough the Promise, otherwise JitsiTrack objects will be returned.
473 474
      */
474
-    errorCallback: function (error, resolve, RTC, currentResolution, dontCreateJitsiTracks) {
475
+    errorCallback: function (error, resolve, currentResolution, dontCreateJitsiTracks) {
475 476
         var self = this;
476 477
         logger.error('failed to obtain audio/video stream - trying audio only', error);
477 478
         var resolution = getPreviousResolution(currentResolution);
@@ -481,27 +482,26 @@ var RTCUtils = {
481 482
             (error.constraintName == "minWidth" || error.constraintName == "maxWidth" ||
482 483
                 error.constraintName == "minHeight" || error.constraintName == "maxHeight")
483 484
             && resolution != null) {
484
-            self.getUserMediaWithConstraints(RTC, ['audio', 'video'],
485
+            self.getUserMediaWithConstraints(['audio', 'video'],
485 486
                 function (stream) {
486
-                    var streams = self.successCallback(RTC, stream, resolution);
487
-                    resolve(dontCreateJitsiTracks? streams: RTC.createLocalStreams(streams));
487
+                    var streams = self.successCallback(stream, resolution);
488
+                    resolve(dontCreateJitsiTracks? streams: self.createLocalTracks(streams));
488 489
                 }, function (error, resolution) {
489
-                    return self.errorCallback(error, resolve, RTC, resolution, dontCreateJitsiTracks);
490
+                    return self.errorCallback(error, resolve, resolution, dontCreateJitsiTracks);
490 491
                 }, resolution);
491 492
         }
492 493
         else {
493 494
             self.getUserMediaWithConstraints(
494
-                RTC,
495 495
                 ['audio'],
496 496
                 function (stream) {
497
-                    var streams = self.successCallback(RTC, stream, resolution);
498
-                    resolve(dontCreateJitsiTracks? streams: RTC.createLocalStreams(streams));
497
+                    var streams = self.successCallback(stream, resolution);
498
+                    resolve(dontCreateJitsiTracks? streams: self.createLocalTracks(streams));
499 499
                 },
500 500
                 function (error) {
501 501
                     logger.error('failed to obtain audio/video stream - stop',
502 502
                         error);
503
-                    var streams = self.successCallback(RTC, null);
504
-                    resolve(dontCreateJitsiTracks? streams: RTC.createLocalStreams(streams));
503
+                    var streams = self.successCallback(null);
504
+                    resolve(dontCreateJitsiTracks? streams: self.createLocalTracks(streams));
505 505
                 }
506 506
             );
507 507
         }
@@ -509,13 +509,11 @@ var RTCUtils = {
509 509
 
510 510
     /**
511 511
      * Handles the newly created Media Streams.
512
-     * @param service the rtc service
513 512
      * @param stream the new Media Streams
514
-     * @param usageOptions the list of the devices that should be queried.
515 513
      * @param resolution the resolution of the video stream.
516 514
      * @returns {*[]} Promise object with the new Media Streams.
517 515
      */
518
-    handleLocalStream: function (service, stream, usageOptions, resolution) {
516
+    handleLocalStream: function (stream, resolution) {
519 517
         var audioStream, videoStream;
520 518
         // If this is FF, the stream parameter is *not* a MediaStream object, it's
521 519
         // an object with two properties: audioStream, videoStream.
@@ -549,17 +547,9 @@ var RTCUtils = {
549 547
                 videoStream = new DummyMediaStream("dummyVideo");
550 548
         }
551 549
 
552
-        var audioMuted = (usageOptions && usageOptions.audio === false),
553
-            videoMuted = (usageOptions && usageOptions.video === false);
554
-
555
-        var audioGUM = (!usageOptions || usageOptions.audio !== false),
556
-            videoGUM = (!usageOptions || usageOptions.video !== false);
557
-
558 550
         return [
559
-                {stream: audioStream, type: "audio", isMuted: audioMuted,
560
-                  isGUMStream: audioGUM, videoType: null},
561
-                {stream: videoStream, type: "video", isMuted: videoMuted,
562
-                  isGUMStream: videoGUM, videoType: "camera",
551
+                {stream: audioStream, type: "audio", videoType: null},
552
+                {stream: videoStream, type: "video", videoType: "camera",
563 553
                   resolution: resolution}
564 554
             ];
565 555
     },
@@ -587,6 +577,33 @@ var RTCUtils = {
587 577
         }
588 578
 
589 579
         return newStream;
580
+    },
581
+    addListener: function (eventType, listener) {
582
+        eventEmitter.on(eventType, listener);
583
+    },
584
+    removeListener: function (eventType, listener) {
585
+        eventEmitter.removeListener(eventType, listener);
586
+    },
587
+    getDeviceAvailability: function () {
588
+        return devices;
589
+    },
590
+    isRTCReady: function () {
591
+        return rtcReady;
592
+    },
593
+    createLocalTracks: function (streams) {
594
+        var newStreams = []
595
+        for (var i = 0; i < streams.length; i++) {
596
+            var localStream = new JitsiLocalTrack(null, streams[i].stream,
597
+                eventEmitter, streams[i].videoType, streams[i].resolution);
598
+            newStreams.push(localStream);
599
+            if (streams[i].isMuted === true)
600
+                localStream.setMute(true);
601
+
602
+            var eventType = StreamEventTypes.EVENT_TYPE_LOCAL_CREATED;
603
+
604
+            eventEmitter.emit(eventType, localStream);
605
+        }
606
+        return newStreams;
590 607
     }
591 608
 }
592 609
 

+ 19
- 6
modules/xmpp/ChatRoom.js Vedi File

@@ -37,7 +37,7 @@ var parser = {
37 37
                 this.JSON2packet(node.children, packet);
38 38
             packet.up();
39 39
         }
40
-        packet.up();
40
+        // packet.up();
41 41
     }
42 42
 };
43 43
 
@@ -87,8 +87,25 @@ ChatRoom.prototype.initPresenceMap = function () {
87 87
         "value": navigator.userAgent,
88 88
         "attributes": {xmlns: 'http://jitsi.org/jitmeet/user-agent'}
89 89
     });
90
+
90 91
 };
91 92
 
93
+ChatRoom.prototype.updateDeviceAvailability = function (devices) {
94
+    this.presMap["nodes"].push( {
95
+        "tagName": "devices",
96
+        "children": [
97
+            {
98
+                "tagName": "audio",
99
+                "value": devices.audio,
100
+            },
101
+            {
102
+                "tagName": "video",
103
+                "value": devices.video,
104
+            }
105
+        ]
106
+    });
107
+}
108
+
92 109
 ChatRoom.prototype.join = function (password, tokenPassword) {
93 110
     if(password)
94 111
         this.password = password;
@@ -611,14 +628,10 @@ ChatRoom.prototype.remoteStreamAdded = function(data, sid, thessrc) {
611 628
     this.eventEmitter.emit(XMPPEvents.REMOTE_STREAM_RECEIVED, data, sid, thessrc);
612 629
 }
613 630
 
614
-ChatRoom.prototype.addLocalStreams = function (localStreams) {
615
-    this.session.addLocalStreams(localStreams);
616
-}
617
-
618 631
 ChatRoom.prototype.getJidBySSRC = function (ssrc) {
619 632
     if (!this.session)
620 633
         return null;
621 634
     return this.session.getSsrcOwner(ssrc);
622 635
 };
623 636
 
624
-module.exports = ChatRoom;
637
+module.exports = ChatRoom;

+ 0
- 10
modules/xmpp/JingleSessionPC.js Vedi File

@@ -164,16 +164,6 @@ JingleSessionPC.prototype.doInitialize = function () {
164 164
     });
165 165
 };
166 166
 
167
-JingleSessionPC.prototype.addLocalStreams = function (localStreams) {
168
-    var self = this;
169
-// add any local and relayed stream
170
-    localStreams.forEach(function(stream) {
171
-        if(!stream.isStarted())
172
-            return;
173
-        self.peerconnection.addStream(stream.getOriginalStream());
174
-    });
175
-}
176
-
177 167
 function onIceConnectionStateChange(sid, session) {
178 168
     switch (session.peerconnection.iceConnectionState) {
179 169
         case 'checking':

Loading…
Annulla
Salva