浏览代码

fixes after rebase

master
isymchych 9 年前
父节点
当前提交
6ee6b6e9e5
共有 6 个文件被更改,包括 152 次插入95 次删除
  1. 50
    63
      app.js
  2. 55
    7
      libs/lib-jitsi-meet.js
  3. 2
    2
      modules/UI/UI.js
  4. 12
    6
      modules/UI/videolayout/LargeVideo.js
  5. 4
    3
      modules/UI/videolayout/VideoLayout.js
  6. 29
    14
      modules/desktopsharing/desktopsharing.js

+ 50
- 63
app.js 查看文件

@@ -36,15 +36,12 @@ const ConnectionErrors = JitsiMeetJS.errors.connection;
36 36
 const ConferenceEvents = JitsiMeetJS.events.conference;
37 37
 const ConferenceErrors = JitsiMeetJS.errors.conference;
38 38
 
39
-const TrackEvents = JitsiMeetJS.events.track;
40
-const TrackErrors = JitsiMeetJS.errors.track;
41
-
42 39
 let localVideo, localAudio;
43 40
 
44 41
 const Commands = {
45 42
     CONNECTION_QUALITY: "connectionQuality",
46 43
     EMAIL: "email",
47
-    VIDEO_TYPE: "videoType"
44
+    VIDEO_TYPE: "videoType",
48 45
     ETHERPAD: "etherpad",
49 46
     PREZI: "prezi",
50 47
     STOP_PREZI: "stop-prezi"
@@ -88,6 +85,18 @@ const APP = {
88 85
     statistics,
89 86
     settings,
90 87
 
88
+    createLocalTracks (...devices) {
89
+        return JitsiMeetJS.createLocalTracks({
90
+            // copy array to avoid mutations inside library
91
+            devices: devices.slice(0),
92
+            resolution: config.resolution
93
+        }).catch(function (err) {
94
+            console.error('failed to create local tracks', ...devices, err);
95
+            APP.statistics.onGetUserMediaFailed(err);
96
+            return [];
97
+        });
98
+    },
99
+
91 100
     init () {
92 101
         let roomName = buildRoomName();
93 102
         this.conference = {
@@ -137,8 +146,10 @@ function initConference(localTracks, connection) {
137 146
 
138 147
     const addTrack = (track) => {
139 148
         room.addTrack(track);
140
-        if(track.getType() === "audio")
149
+        if (track.isAudioTrack()) {
141 150
             return;
151
+        }
152
+
142 153
         room.removeCommand(Commands.VIDEO_TYPE);
143 154
         room.sendCommand(Commands.VIDEO_TYPE, {
144 155
             value: track.videoType,
@@ -161,40 +172,6 @@ function initConference(localTracks, connection) {
161 172
     APP.conference.listMembersIds = function () {
162 173
         return room.getParticipants().map(p => p.getId());
163 174
     };
164
-    /**
165
-     * Creates video track (desktop or camera).
166
-     * @param type "camera" or "video"
167
-     * @param endedHandler onended function
168
-     * @returns Promise
169
-     */
170
-    APP.conference.createVideoTrack = (type, endedHandler) => {
171
-        return JitsiMeetJS.createLocalTracks({
172
-            devices: [type], resolution: config.resolution
173
-        }).then((tracks) => {
174
-            tracks[0].on(TrackEvents.TRACK_STOPPED, endedHandler);
175
-            return tracks;
176
-        });
177
-    };
178
-
179
-    APP.conference.changeLocalVideo = (track, callback) => {
180
-        const localCallback = (newTrack) => {
181
-            if (newTrack.isLocal() && newTrack === localVideo) {
182
-                if(localVideo.isMuted() &&
183
-                    localVideo.videoType !== track.videoType) {
184
-                        localVideo.mute();
185
-                }
186
-                callback();
187
-                room.off(ConferenceEvents.TRACK_ADDED, localCallback);
188
-            }
189
-        };
190
-
191
-        room.on(ConferenceEvents.TRACK_ADDED, localCallback);
192
-
193
-        localVideo.stop();
194
-        localVideo = track;
195
-        addTrack(track);
196
-        APP.UI.addLocalStream(track);
197
-    };
198 175
 
199 176
     APP.conference.sipGatewayEnabled = () => {
200 177
         return room.isSIPCallingSupported();
@@ -205,7 +182,7 @@ function initConference(localTracks, connection) {
205 182
             return APP.settings.getDisplayName();
206 183
         }
207 184
 
208
-        var participant = room.getParticipantById(id);
185
+        let participant = room.getParticipantById(id);
209 186
         if (participant && participant.getDisplayName()) {
210 187
             return participant.getDisplayName();
211 188
         }
@@ -214,10 +191,10 @@ function initConference(localTracks, connection) {
214 191
     // add local streams when joined to the conference
215 192
     room.on(ConferenceEvents.CONFERENCE_JOINED, function () {
216 193
         localTracks.forEach(function (track) {
217
-            if(track.getType() === "audio") {
194
+            if(track.isAudioTrack()) {
218 195
                 localAudio = track;
219 196
             }
220
-            else if (track.getType() === "video") {
197
+            else if (track.isVideoTrack()) {
221 198
                 localVideo = track;
222 199
             }
223 200
             addTrack(track);
@@ -246,7 +223,7 @@ function initConference(localTracks, connection) {
246 223
             APP.conference.isModerator = room.isModerator();
247 224
             APP.UI.updateLocalRole(room.isModerator());
248 225
         } else {
249
-            var user = room.getParticipantById(id);
226
+            let user = room.getParticipantById(id);
250 227
             if (user) {
251 228
                 APP.UI.updateUserRole(user);
252 229
             }
@@ -401,8 +378,8 @@ function initConference(localTracks, connection) {
401 378
         });
402 379
     });
403 380
 
404
-    room.addCommandListener(Commands.VIDEO_TYPE, (data, from) => {
405
-        APP.UI.onPeerVideoTypeChanged(from, data.value);
381
+    room.addCommandListener(Commands.VIDEO_TYPE, ({value}, from) => {
382
+        APP.UI.onPeerVideoTypeChanged(from, value);
406 383
     });
407 384
 
408 385
 
@@ -416,7 +393,7 @@ function initConference(localTracks, connection) {
416 393
         });
417 394
     }
418 395
 
419
-    var email = APP.settings.getEmail();
396
+    let email = APP.settings.getEmail();
420 397
     email && sendEmail(email);
421 398
     APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
422 399
         APP.settings.setEmail(email);
@@ -534,6 +511,29 @@ function initConference(localTracks, connection) {
534 511
         APP.UI.updateDTMFSupport(isDTMFSupported);
535 512
     });
536 513
 
514
+    APP.desktopsharing.addListener(
515
+        DesktopSharingEventTypes.NEW_STREAM_CREATED,
516
+        (track, callback) => {
517
+            const localCallback = (newTrack) => {
518
+                if (newTrack.isLocal() && newTrack === localVideo) {
519
+                    if(localVideo.isMuted() &&
520
+                       localVideo.videoType !== track.videoType) {
521
+                        localVideo.mute();
522
+                    }
523
+                    callback();
524
+                    room.off(ConferenceEvents.TRACK_ADDED, localCallback);
525
+                }
526
+            };
527
+
528
+            room.on(ConferenceEvents.TRACK_ADDED, localCallback);
529
+
530
+            localVideo.stop();
531
+            localVideo = track;
532
+            addTrack(track);
533
+            APP.UI.addLocalStream(track);
534
+        }
535
+    );
536
+
537 537
     $(window).bind('beforeunload', function () {
538 538
         room.leave();
539 539
     });
@@ -603,16 +603,6 @@ function initConference(localTracks, connection) {
603 603
     });
604 604
 }
605 605
 
606
-function createLocalTracks () {
607
-    return JitsiMeetJS.createLocalTracks({
608
-        devices: ['audio', 'video']
609
-    }).catch(function (err) {
610
-        console.error('failed to create local tracks', err);
611
-        APP.statistics.onGetUserMediaFailed(err);
612
-        return [];
613
-    });
614
-}
615
-
616 606
 function connect() {
617 607
     return openConnection({retry: true}).catch(function (err) {
618 608
         if (err === ConnectionErrors.PASSWORD_REQUIRED) {
@@ -630,7 +620,10 @@ function init() {
630 620
     JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
631 621
 
632 622
     JitsiMeetJS.init(config).then(function () {
633
-        return Promise.all([createLocalTracks(), connect()]);
623
+        return Promise.all([
624
+            APP.createLocalTracks('audio', 'video'),
625
+            connect()
626
+        ]);
634 627
     }).then(function ([tracks, connection]) {
635 628
         console.log('initialized with %s local tracks', tracks.length);
636 629
         return initConference(tracks, connection);
@@ -642,12 +635,6 @@ function init() {
642 635
             APP.settings.setLanguage(language);
643 636
         });
644 637
 
645
-        APP.desktopsharing.addListener(
646
-            DesktopSharingEventTypes.NEW_STREAM_CREATED,
647
-            (stream, callback) => {
648
-                APP.conference.changeLocalVideo(stream,
649
-                    callback);
650
-            });
651 638
         APP.desktopsharing.init(JitsiMeetJS.isDesktopSharingEnabled());
652 639
         APP.statistics.start();
653 640
         APP.connectionquality.init();

+ 55
- 7
libs/lib-jitsi-meet.js 查看文件

@@ -579,6 +579,15 @@ JitsiConference.prototype.toggleRecording = function (token, followEntity) {
579 579
         reject(new Error("The conference is not created yet!"))});
580 580
 }
581 581
 
582
+/**
583
+ * Returns true if the SIP calls are supported and false otherwise
584
+ */
585
+JitsiConference.prototype.isSIPCallingSupported = function () {
586
+    if(this.room)
587
+        return this.room.isSIPCallingSupported();
588
+    return false;
589
+}
590
+
582 591
 /**
583 592
  * Dials a number.
584 593
  * @param number the number
@@ -1059,6 +1068,13 @@ var LibJitsiMeet = {
1059 1068
     init: function (options) {
1060 1069
         return RTC.init(options || {});
1061 1070
     },
1071
+    /**
1072
+     * Returns whether the desktop sharing is enabled or not.
1073
+     * @returns {boolean}
1074
+     */
1075
+    isDesktopSharingEnabled: function () {
1076
+        return RTC.isDesktopSharingEnabled();
1077
+    },
1062 1078
     setLogLevel: function (level) {
1063 1079
         Logger.setLogLevel(level);
1064 1080
     },
@@ -1799,6 +1815,7 @@ module.exports = JitsiRemoteTrack;
1799 1815
 var RTCBrowserType = require("./RTCBrowserType");
1800 1816
 var JitsiTrackEvents = require("../../JitsiTrackEvents");
1801 1817
 var EventEmitter = require("events");
1818
+var RTC = require("./RTCUtils");
1802 1819
 
1803 1820
 /**
1804 1821
  * This implements 'onended' callback normally fired by WebRTC after the stream
@@ -1989,13 +2006,21 @@ JitsiTrack.prototype.isScreenSharing = function(){
1989 2006
  * Returns id of the track.
1990 2007
  * @returns {string} id of the track or null if this is fake track.
1991 2008
  */
1992
-JitsiTrack.prototype.getId = function () {
2009
+JitsiTrack.prototype._getId = function () {
1993 2010
     var tracks = this.stream.getTracks();
1994 2011
     if(!tracks || tracks.length === 0)
1995 2012
         return null;
1996 2013
     return tracks[0].id;
1997 2014
 };
1998 2015
 
2016
+/**
2017
+ * Returns id of the track.
2018
+ * @returns {string} id of the track or null if this is fake track.
2019
+ */
2020
+JitsiTrack.prototype.getId = function () {
2021
+    return RTC.getStreamID(this.stream);
2022
+};
2023
+
1999 2024
 /**
2000 2025
  * Checks whether the MediaStream is avtive/not ended.
2001 2026
  * When there is no check for active we don't have information and so
@@ -2247,6 +2272,14 @@ RTC.stopMediaStream = function (mediaStream) {
2247 2272
     RTCUtils.stopMediaStream(mediaStream);
2248 2273
 };
2249 2274
 
2275
+/**
2276
+ * Returns whether the desktop sharing is enabled or not.
2277
+ * @returns {boolean}
2278
+ */
2279
+RTC.isDesktopSharingEnabled = function () {
2280
+    return RTCUtils.isDesktopSharingEnabled();
2281
+}
2282
+
2250 2283
 RTC.prototype.getVideoElementName = function () {
2251 2284
     return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video';
2252 2285
 };
@@ -3105,7 +3138,7 @@ var RTCUtils = {
3105 3138
                 var deviceGUM = {
3106 3139
                     "audio": GUM.bind(self, ["audio"]),
3107 3140
                     "video": GUM.bind(self, ["video"]),
3108
-                    "desktop": screenObtainer.obtainStream
3141
+                    "desktop": screenObtainer.obtainStream.bind(screenObtainer)
3109 3142
                 };
3110 3143
                 // With FF/IE we can't split the stream into audio and video because FF
3111 3144
                 // doesn't support media stream constructors. So, we need to get the
@@ -3211,6 +3244,13 @@ var RTCUtils = {
3211 3244
         if (mediaStream.stop) {
3212 3245
             mediaStream.stop();
3213 3246
         }
3247
+    },
3248
+    /**
3249
+     * Returns whether the desktop sharing is enabled or not.
3250
+     * @returns {boolean}
3251
+     */
3252
+    isDesktopSharingEnabled: function () {
3253
+        return screenObtainer.isSupported();
3214 3254
     }
3215 3255
 
3216 3256
 };
@@ -6344,7 +6384,7 @@ ChatRoom.prototype.onPresence = function (pres) {
6344 6384
 
6345 6385
 ChatRoom.prototype.processNode = function (node, from) {
6346 6386
     if(this.presHandlers[node.tagName])
6347
-        this.presHandlers[node.tagName](node, from);
6387
+        this.presHandlers[node.tagName](node, Strophe.getResourceFromJid(from));
6348 6388
 };
6349 6389
 
6350 6390
 ChatRoom.prototype.sendMessage = function (body, nickname) {
@@ -6722,6 +6762,15 @@ ChatRoom.prototype.toggleRecording = function (token, followEntity) {
6722 6762
         reject(new Error("The conference is not created yet!"))});
6723 6763
 }
6724 6764
 
6765
+/**
6766
+ * Returns true if the SIP calls are supported and false otherwise
6767
+ */
6768
+ChatRoom.prototype.isSIPCallingSupported = function () {
6769
+    if(this.moderator)
6770
+        return this.moderator.isSipGatewayEnabled();
6771
+    return false;
6772
+}
6773
+
6725 6774
 /**
6726 6775
  * Dials a number.
6727 6776
  * @param number the number
@@ -9088,11 +9137,11 @@ SDP.prototype.toJingle = function (elem, thecreator) {
9088 9137
                     var msid = null;
9089 9138
                     if(mline.media == "audio")
9090 9139
                     {
9091
-                        msid = APP.RTC.localAudio.getId();
9140
+                        msid = APP.RTC.localAudio._getId();
9092 9141
                     }
9093 9142
                     else
9094 9143
                     {
9095
-                        msid = APP.RTC.localVideo.getId();
9144
+                        msid = APP.RTC.localVideo._getId();
9096 9145
                     }
9097 9146
                     if(msid != null)
9098 9147
                     {
@@ -9488,7 +9537,6 @@ SDP.prototype.jingle2media = function (content) {
9488 9537
 
9489 9538
 module.exports = SDP;
9490 9539
 
9491
-
9492 9540
 }).call(this,"/modules/xmpp/SDP.js")
9493 9541
 },{"./SDPUtil":32,"jitsi-meet-logger":48}],31:[function(require,module,exports){
9494 9542
 var SDPUtil = require("./SDPUtil");
@@ -10521,7 +10569,7 @@ function Moderator(roomName, xmpp, emitter) {
10521 10569
     // Sip gateway can be enabled by configuring Jigasi host in config.js or
10522 10570
     // it will be enabled automatically if focus detects the component through
10523 10571
     // service discovery.
10524
-    this.sipGatewayEnabled =
10572
+    this.sipGatewayEnabled = this.xmppService.options.hosts &&
10525 10573
         this.xmppService.options.hosts.call_control !== undefined;
10526 10574
 
10527 10575
     this.eventEmitter = emitter;

+ 2
- 2
modules/UI/UI.js 查看文件

@@ -396,8 +396,8 @@ UI.removeUser = function (id, displayName) {
396 396
 //     VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
397 397
 // }
398 398
 
399
-UI.onPeerVideoTypeChanged = (resourceJid, newVideoType) => {
400
-    VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
399
+UI.onPeerVideoTypeChanged = (id, newVideoType) => {
400
+    VideoLayout.onVideoTypeChanged(id, newVideoType);
401 401
 };
402 402
 
403 403
 UI.updateLocalRole = function (isModerator) {

+ 12
- 6
modules/UI/videolayout/LargeVideo.js 查看文件

@@ -159,6 +159,7 @@ class VideoContainer extends LargeContainer {
159 159
     constructor (onPlay) {
160 160
         super();
161 161
         this.stream = null;
162
+        this.videoType = null;
162 163
 
163 164
         this.$avatar = $('#activeSpeaker');
164 165
         this.$wrapper = $('#largeVideoWrapper');
@@ -180,7 +181,7 @@ class VideoContainer extends LargeContainer {
180 181
 
181 182
     getVideoSize (containerWidth, containerHeight) {
182 183
         let { width, height } = this.getStreamSize();
183
-        if (this.stream && this.stream.isScreenSharing()) {
184
+        if (this.stream && this.isScreenSharing()) {
184 185
             return getDesktopVideoSize(width, height, containerWidth, containerHeight);
185 186
         } else {
186 187
             return getCameraVideoSize(width, height, containerWidth, containerHeight);
@@ -188,7 +189,7 @@ class VideoContainer extends LargeContainer {
188 189
     }
189 190
 
190 191
     getVideoPosition (width, height, containerWidth, containerHeight) {
191
-        if (this.stream && this.stream.isScreenSharing()) {
192
+        if (this.stream && this.isScreenSharing()) {
192 193
             return getDesktopVideoPosition(width, height, containerWidth, containerHeight);
193 194
         } else {
194 195
             return getCameraVideoPosition(width, height, containerWidth, containerHeight);
@@ -218,17 +219,22 @@ class VideoContainer extends LargeContainer {
218 219
         });
219 220
     }
220 221
 
221
-    setStream (stream) {
222
+    setStream (stream, videoType) {
222 223
         this.stream = stream;
224
+        this.videoType = videoType;
223 225
 
224 226
         stream.attach(this.$video);
225 227
 
226
-        let flipX = stream.isLocal() && !stream.isScreenSharing();
228
+        let flipX = stream.isLocal() && !this.isScreenSharing();
227 229
         this.$video.css({
228 230
             transform: flipX ? 'scaleX(-1)' : 'none'
229 231
         });
230 232
     }
231 233
 
234
+    isScreenSharing () {
235
+        return this.videoType === 'desktop';
236
+    }
237
+
232 238
     showAvatar (show) {
233 239
         this.$avatar.css("visibility", show ? "visible" : "hidden");
234 240
     }
@@ -332,7 +338,7 @@ export default class LargeVideoManager {
332 338
         return this.videoContainer.id;
333 339
     }
334 340
 
335
-    updateLargeVideo (stream) {
341
+    updateLargeVideo (stream, videoType) {
336 342
         let id = getStreamId(stream);
337 343
 
338 344
         let container = this.getContainer(this.state);
@@ -340,7 +346,7 @@ export default class LargeVideoManager {
340 346
         container.hide().then(() => {
341 347
             console.info("hover in %s", id);
342 348
             this.state = VideoContainerType;
343
-            this.videoContainer.setStream(stream);
349
+            this.videoContainer.setStream(stream, videoType);
344 350
             this.videoContainer.show();
345 351
         });
346 352
     }

+ 4
- 3
modules/UI/videolayout/VideoLayout.js 查看文件

@@ -153,7 +153,7 @@ var VideoLayout = {
153 153
         localVideoThumbnail.createConnectionIndicator();
154 154
 
155 155
         let localId = APP.conference.localId;
156
-        this.onVideoTypeChanged(localId, stream.getType());
156
+        this.onVideoTypeChanged(localId, stream.videoType);
157 157
 
158 158
         let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
159 159
         AudioLevels.updateAudioLevelCanvas(null, thumbWidth, thumbHeight);
@@ -218,7 +218,7 @@ var VideoLayout = {
218 218
     electLastVisibleVideo () {
219 219
         // pick the last visible video in the row
220 220
         // if nobody else is left, this picks the local video
221
-        let thumbs = BottomToolbar.getThumbs(true).filter('id!="mixedstream"');
221
+        let thumbs = BottomToolbar.getThumbs(true).filter('[id!="mixedstream"]');
222 222
 
223 223
         let lastVisible = thumbs.filter(':visible:last');
224 224
         if (lastVisible.length) {
@@ -973,7 +973,8 @@ var VideoLayout = {
973 973
 
974 974
             let smallVideo = this.getSmallVideo(id);
975 975
 
976
-            largeVideo.updateLargeVideo(smallVideo.stream);
976
+            let videoType = this.getRemoteVideoType(id);
977
+            largeVideo.updateLargeVideo(smallVideo.stream, videoType);
977 978
 
978 979
             smallVideo.enableDominantSpeaker(true);
979 980
         } else if (currentId) {

+ 29
- 14
modules/desktopsharing/desktopsharing.js 查看文件

@@ -1,8 +1,10 @@
1
-/* global APP, config */
1
+/* global APP, JitsiMeetJS, config */
2 2
 var EventEmitter = require("events");
3 3
 var DesktopSharingEventTypes
4 4
     = require("../../service/desktopsharing/DesktopSharingEventTypes");
5 5
 
6
+const TrackEvents = JitsiMeetJS.events.track;
7
+
6 8
 /**
7 9
  * Indicates that desktop stream is currently in use (for toggle purpose).
8 10
  * @type {boolean}
@@ -35,15 +37,15 @@ function newStreamCreated(track) {
35 37
         track, streamSwitchDone);
36 38
 }
37 39
 
38
-function getVideoStreamFailed(error) {
39
-    console.error("Failed to obtain the stream to switch to", error);
40
+function getVideoStreamFailed() {
41
+    console.error("Failed to obtain the stream to switch to");
40 42
     switchInProgress = false;
41 43
     isUsingScreenStream = false;
42 44
     newStreamCreated(null);
43 45
 }
44 46
 
45
-function getDesktopStreamFailed(error) {
46
-    console.error("Failed to obtain the stream to switch to", error);
47
+function getDesktopStreamFailed() {
48
+    console.error("Failed to obtain the stream to switch to");
47 49
     switchInProgress = false;
48 50
 }
49 51
 
@@ -92,21 +94,34 @@ module.exports = {
92 94
             return;
93 95
         }
94 96
         switchInProgress = true;
95
-        let type, handler;
97
+        let type;
96 98
         if (!isUsingScreenStream) {
97 99
             // Switch to desktop stream
98
-            handler = onEndedHandler;
99 100
             type = "desktop";
100 101
         } else {
101
-            handler = () => {};
102 102
             type = "video";
103 103
         }
104
-        APP.conference.createVideoTrack(type, handler).then(
105
-            (tracks) => {
106
-                // We now use screen stream
107
-                isUsingScreenStream = type === "desktop";
108
-                newStreamCreated(tracks[0]);
109
-            }).catch(getDesktopStreamFailed);
104
+        APP.createLocalTracks(type).then(function (tracks) {
105
+            if (!tracks.length) {
106
+                if (type === 'desktop') {
107
+                    getDesktopStreamFailed();
108
+                } else {
109
+                    getVideoStreamFailed();
110
+                }
111
+
112
+                return;
113
+            }
114
+
115
+            let stream = tracks[0];
116
+
117
+            // We now use screen stream
118
+            isUsingScreenStream = type === "desktop";
119
+            if (isUsingScreenStream) {
120
+                stream.on(TrackEvents.TRACK_STOPPED, onEndedHandler);
121
+            }
122
+
123
+            newStreamCreated(stream);
124
+        });
110 125
     },
111 126
     /*
112 127
      * Exports the event emitter to allow use by ScreenObtainer. Not for outside

正在加载...
取消
保存