Pārlūkot izejas kodu

Implements desktop sharing.

master
hristoterezov 9 gadus atpakaļ
vecāks
revīzija
3ec04d5a95

+ 2
- 0
.jshintignore Parādīt failu

@@ -7,3 +7,5 @@ lib-jitsi-meet.js
7 7
 modules/xmpp/strophe.emuc.js
8 8
 modules/UI/prezi/Prezi.js
9 9
 modules/RTC/adapter.screenshare.js
10
+modules/statistics/*
11
+modules/UI/videolayout/*

+ 82
- 10
app.js Parādīt failu

@@ -23,9 +23,24 @@ import AuthHandler from './modules/AuthHandler';
23 23
 
24 24
 import createRoomLocker from './modules/RoomLocker';
25 25
 
26
+const DesktopSharingEventTypes =
27
+    require("./service/desktopsharing/DesktopSharingEventTypes");
28
+
29
+const ConnectionEvents = JitsiMeetJS.events.connection;
30
+const ConnectionErrors = JitsiMeetJS.errors.connection;
31
+
32
+const ConferenceEvents = JitsiMeetJS.events.conference;
33
+const ConferenceErrors = JitsiMeetJS.errors.conference;
34
+
35
+const TrackEvents = JitsiMeetJS.events.track;
36
+const TrackErrors = JitsiMeetJS.errors.track;
37
+
38
+let localVideo, localAudio;
39
+
26 40
 const Commands = {
27 41
     CONNECTION_QUALITY: "connectionQuality",
28
-    EMAIL: "email"
42
+    EMAIL: "email",
43
+    VIDEO_TYPE: "videoType"
29 44
 };
30 45
 
31 46
 function buildRoomName () {
@@ -104,18 +119,25 @@ const APP = {
104 119
     }
105 120
 };
106 121
 
107
-
108
-const ConnectionEvents = JitsiMeetJS.events.connection;
109
-const ConnectionErrors = JitsiMeetJS.errors.connection;
110
-
111
-const ConferenceEvents = JitsiMeetJS.events.conference;
112
-const ConferenceErrors = JitsiMeetJS.errors.conference;
113 122
 function initConference(localTracks, connection) {
114 123
     let room = connection.initJitsiConference(APP.conference.roomName, {
115 124
         openSctp: config.openSctp,
116 125
         disableAudioLevels: config.disableAudioLevels
117 126
     });
118 127
 
128
+    const addTrack = (track) => {
129
+        room.addTrack(track);
130
+        if(track.getType() === "audio")
131
+            return;
132
+        room.removeCommand(Commands.VIDEO_TYPE);
133
+        room.sendCommand(Commands.VIDEO_TYPE, {
134
+            value: track.videoType,
135
+            attributes: {
136
+                xmlns: 'http://jitsi.org/jitmeet/video'
137
+            }
138
+        });
139
+    };
140
+
119 141
     APP.conference.localId = room.myUserId();
120 142
     Object.defineProperty(APP.conference, "membersCount", {
121 143
         get: function () {
@@ -129,6 +151,40 @@ function initConference(localTracks, connection) {
129 151
     APP.conference.listMembersIds = function () {
130 152
         return room.getParticipants().map(p => p.getId());
131 153
     };
154
+    /**
155
+     * Creates video track (desktop or camera).
156
+     * @param type "camera" or "video"
157
+     * @param endedHandler onended function
158
+     * @returns Promise
159
+     */
160
+    APP.conference.createVideoTrack = (type, endedHandler) => {
161
+        return JitsiMeetJS.createLocalTracks({
162
+            devices: [type], resolution: config.resolution
163
+        }).then((tracks) => {
164
+            tracks[0].on(TrackEvents.TRACK_STOPPED, endedHandler);
165
+            return tracks;
166
+        });
167
+    };
168
+
169
+    APP.conference.changeLocalVideo = (track, callback) => {
170
+        const localCallback = (newTrack) => {
171
+            if (newTrack.isLocal() && newTrack === localVideo) {
172
+                if(localVideo.isMuted() &&
173
+                    localVideo.videoType !== track.videoType) {
174
+                        localVideo.mute();
175
+                }
176
+                callback();
177
+                room.off(ConferenceEvents.TRACK_ADDED, localCallback);
178
+            }
179
+        };
180
+
181
+        room.on(ConferenceEvents.TRACK_ADDED, localCallback);
182
+
183
+        localVideo.stop();
184
+        localVideo = track;
185
+        addTrack(track);
186
+        APP.UI.addLocalStream(track);
187
+    };
132 188
 
133 189
     function getDisplayName(id) {
134 190
         if (APP.conference.isLocalId(id)) {
@@ -144,7 +200,13 @@ function initConference(localTracks, connection) {
144 200
     // add local streams when joined to the conference
145 201
     room.on(ConferenceEvents.CONFERENCE_JOINED, function () {
146 202
         localTracks.forEach(function (track) {
147
-            room.addTrack(track);
203
+            if(track.getType() === "audio") {
204
+                localAudio = track;
205
+            }
206
+            else if (track.getType() === "video") {
207
+                localVideo = track;
208
+            }
209
+            addTrack(track);
148 210
             APP.UI.addLocalStream(track);
149 211
         });
150 212
 
@@ -293,6 +355,10 @@ function initConference(localTracks, connection) {
293 355
         }
294 356
     );
295 357
 
358
+    room.addCommandListener(Commands.VIDEO_TYPE, (data, from) => {
359
+        APP.UI.onPeerVideoTypeChanged(from, data.value);
360
+    });
361
+
296 362
 
297 363
     // share email with other users
298 364
     function sendEmail(email) {
@@ -520,7 +586,7 @@ function init() {
520 586
 
521 587
     JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
522 588
 
523
-    JitsiMeetJS.init().then(function () {
589
+    JitsiMeetJS.init(config).then(function () {
524 590
         return Promise.all([createLocalTracks(), connect()]);
525 591
     }).then(function ([tracks, connection]) {
526 592
         console.log('initialized with %s local tracks', tracks.length);
@@ -533,7 +599,13 @@ function init() {
533 599
             APP.settings.setLanguage(language);
534 600
         });
535 601
 
536
-        APP.desktopsharing.init();
602
+        APP.desktopsharing.addListener(
603
+            DesktopSharingEventTypes.NEW_STREAM_CREATED,
604
+            (stream, callback) => {
605
+                APP.conference.changeLocalVideo(stream,
606
+                    callback);
607
+            });
608
+        APP.desktopsharing.init(JitsiMeetJS.isDesktopSharingEnabled());
537 609
         APP.statistics.start();
538 610
         APP.connectionquality.init();
539 611
         APP.keyboardshortcut.init();

libs/lib-jitsi-meet.js
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 6
- 5
modules/UI/UI.js Parādīt failu

@@ -386,13 +386,14 @@ UI.removeUser = function (id, displayName) {
386 386
     VideoLayout.removeParticipantContainer(id);
387 387
 };
388 388
 
389
-function onMucPresenceStatus(jid, info) {
390
-    VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
391
-}
389
+//FIXME: NOT USED. Should start using the lib
390
+// function onMucPresenceStatus(jid, info) {
391
+//     VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
392
+// }
392 393
 
393
-function onPeerVideoTypeChanged(resourceJid, newVideoType) {
394
+UI.onPeerVideoTypeChanged = (resourceJid, newVideoType) => {
394 395
     VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
395
-}
396
+};
396 397
 
397 398
 UI.updateLocalRole = function (isModerator) {
398 399
     VideoLayout.showModeratorIndicator();

+ 1
- 1
modules/UI/util/UIUtil.js Parādīt failu

@@ -116,7 +116,7 @@ import PanelToggler from "../side_pannels/SidePanelToggler";
116 116
         $(selector).hide();
117 117
     },
118 118
 
119
-     redirect (url) {
119
+    redirect (url) {
120 120
          window.location.href = url;
121 121
      }
122 122
 };

+ 1
- 1
modules/UI/videolayout/LargeVideo.js Parādīt failu

@@ -549,7 +549,7 @@ var LargeVideo = {
549 549
         if (!videoType)
550 550
             videoType = currentSmallVideo.getVideoType();
551 551
 
552
-        var isDesktop = videoType === 'screen';
552
+        var isDesktop = videoType === 'desktop';
553 553
 
554 554
         // Change the way we'll be measuring and positioning large video
555 555
         getVideoSize = isDesktop ? getDesktopVideoSize : getCameraVideoSize;

+ 3
- 3
modules/UI/videolayout/LocalVideo.js Parādīt failu

@@ -159,7 +159,7 @@ LocalVideo.prototype.changeVideo = function (stream) {
159 159
     localVideoContainerSelector.off('click');
160 160
     localVideoContainerSelector.on('click', localVideoClick);
161 161
 
162
-    this.flipX = stream.videoType != "screen";
162
+    this.flipX = stream.videoType != "desktop";
163 163
     let localVideo = document.createElement('video');
164 164
     localVideo.id = 'localVideo_' + stream.getId();
165 165
     if (!RTCBrowserType.isIExplorer()) {
@@ -191,14 +191,14 @@ LocalVideo.prototype.changeVideo = function (stream) {
191 191
     return;
192 192
 
193 193
     // Add stream ended handler
194
-    APP.RTC.addMediaStreamInactiveHandler(
194
+    /**APP.RTC.addMediaStreamInactiveHandler(
195 195
         stream.getOriginalStream(), function () {
196 196
         // We have to re-select after attach when Temasys plugin is used,
197 197
         // because <video> element is replaced with <object>
198 198
         localVideo = $('#' + localVideo.id)[0];
199 199
         localVideoContainer.removeChild(localVideo);
200 200
         self.VideoLayout.updateRemovedVideo(self.id);
201
-    });
201
+    });*/
202 202
 };
203 203
 
204 204
 LocalVideo.prototype.joined = function (id) {

+ 2
- 1
modules/UI/videolayout/RemoteVideo.js Parādīt failu

@@ -195,7 +195,8 @@ RemoteVideo.prototype.waitForPlayback = function (sel, stream) {
195 195
     var onPlayingHandler = function () {
196 196
         // FIXME: why do i have to do this for FF?
197 197
         if (RTCBrowserType.isFirefox()) {
198
-            APP.RTC.attachMediaStream(sel, webRtcStream);
198
+            //FIXME: weshould use the lib here
199
+            //APP.RTC.attachMediaStream(sel, webRtcStream);
199 200
         }
200 201
         if (RTCBrowserType.isTemasysPluginUsed()) {
201 202
             sel = self.selectVideoElement();

+ 1
- 6
modules/UI/videolayout/SmallVideo.js Parādīt failu

@@ -58,7 +58,7 @@ SmallVideo.prototype.setDeviceAvailabilityIcons = function (devices) {
58 58
 
59 59
 /**
60 60
  * Sets the type of the video displayed by this instance.
61
- * @param videoType 'camera' or 'screen'
61
+ * @param videoType 'camera' or 'desktop'
62 62
  */
63 63
 SmallVideo.prototype.setVideoType = function (videoType) {
64 64
     this.videoType = videoType;
@@ -345,11 +345,6 @@ SmallVideo.prototype.selectVideoElement = function () {
345 345
     }
346 346
 };
347 347
 
348
-SmallVideo.prototype.getSrc = function () {
349
-    var videoElement = this.selectVideoElement().get(0);
350
-    return APP.RTC.getVideoSrc(videoElement);
351
-};
352
-
353 348
 SmallVideo.prototype.focus = function(isFocused) {
354 349
     if(!isFocused) {
355 350
         this.container.classList.remove("videoContainerFocused");

+ 0
- 407
modules/desktopsharing/ScreenObtainer.js Parādīt failu

@@ -1,407 +0,0 @@
1
-/* global config, APP, chrome, $, alert */
2
-/* jshint -W003 */
3
-var RTCBrowserType = require("../RTC/RTCBrowserType");
4
-var AdapterJS = require("../RTC/adapter.screenshare");
5
-var DesktopSharingEventTypes
6
-    = require("../../service/desktopsharing/DesktopSharingEventTypes");
7
-
8
-/**
9
- * Indicates whether the Chrome desktop sharing extension is installed.
10
- * @type {boolean}
11
- */
12
-var chromeExtInstalled = false;
13
-
14
-/**
15
- * Indicates whether an update of the Chrome desktop sharing extension is
16
- * required.
17
- * @type {boolean}
18
- */
19
-var chromeExtUpdateRequired = false;
20
-
21
-/**
22
- * Whether the jidesha extension for firefox is installed for the domain on
23
- * which we are running. Null designates an unknown value.
24
- * @type {null}
25
- */
26
-var firefoxExtInstalled = null;
27
-
28
-/**
29
- * If set to true, detection of an installed firefox extension will be started
30
- * again the next time obtainScreenOnFirefox is called (e.g. next time the
31
- * user tries to enable screen sharing).
32
- */
33
-var reDetectFirefoxExtension = false;
34
-
35
-/**
36
- * Handles obtaining a stream from a screen capture on different browsers.
37
- */
38
-function ScreenObtainer(){
39
-}
40
-
41
-/**
42
- * The EventEmitter to use to emit events.
43
- * @type {null}
44
- */
45
-ScreenObtainer.prototype.eventEmitter = null;
46
-
47
-/**
48
- * Initializes the function used to obtain a screen capture (this.obtainStream).
49
- *
50
- * If the browser is Chrome, it uses the value of
51
- * 'config.desktopSharingChromeMethod' (or 'config.desktopSharing') to * decide
52
- * whether to use the a Chrome extension (if the value is 'ext'), use the
53
- * "screen" media source (if the value is 'webrtc'), or disable screen capture
54
- * (if the value is other).
55
- * Note that for the "screen" media source to work the
56
- * 'chrome://flags/#enable-usermedia-screen-capture' flag must be set.
57
- */
58
-ScreenObtainer.prototype.init = function(eventEmitter) {
59
-    this.eventEmitter = eventEmitter;
60
-    var obtainDesktopStream = null;
61
-
62
-    if (RTCBrowserType.isFirefox())
63
-        initFirefoxExtensionDetection();
64
-
65
-    // TODO remove this, config.desktopSharing is deprecated.
66
-    var chromeMethod =
67
-        (config.desktopSharingChromeMethod || config.desktopSharing);
68
-
69
-    if (RTCBrowserType.isTemasysPluginUsed()) {
70
-        if (!AdapterJS.WebRTCPlugin.plugin.HasScreensharingFeature) {
71
-            console.info("Screensharing not supported by this plugin version");
72
-        } else if (!AdapterJS.WebRTCPlugin.plugin.isScreensharingAvailable) {
73
-            console.info(
74
-                "Screensharing not available with Temasys plugin on this site");
75
-        } else {
76
-            obtainDesktopStream = obtainWebRTCScreen;
77
-            console.info("Using Temasys plugin for desktop sharing");
78
-        }
79
-    } else if (RTCBrowserType.isChrome()) {
80
-        if (chromeMethod == "ext") {
81
-            if (RTCBrowserType.getChromeVersion() >= 34) {
82
-                obtainDesktopStream = obtainScreenFromExtension;
83
-                console.info("Using Chrome extension for desktop sharing");
84
-                initChromeExtension();
85
-            } else {
86
-                console.info("Chrome extension not supported until ver 34");
87
-            }
88
-        } else if (chromeMethod == "webrtc") {
89
-            obtainDesktopStream = obtainWebRTCScreen;
90
-            console.info("Using Chrome WebRTC for desktop sharing");
91
-        }
92
-    } else if (RTCBrowserType.isFirefox()) {
93
-        if (config.desktopSharingFirefoxDisabled) {
94
-            obtainDesktopStream = null;
95
-        } else if (window.location.protocol === "http:"){
96
-            console.log("Screen sharing is not supported over HTTP. Use of " +
97
-                "HTTPS is required.");
98
-            obtainDesktopStream = null;
99
-        } else {
100
-            obtainDesktopStream = this.obtainScreenOnFirefox;
101
-        }
102
-
103
-    }
104
-
105
-    if (!obtainDesktopStream) {
106
-        console.info("Desktop sharing disabled");
107
-    }
108
-
109
-    ScreenObtainer.prototype.obtainStream = obtainDesktopStream;
110
-};
111
-
112
-ScreenObtainer.prototype.obtainStream = null;
113
-
114
-/**
115
- * Checks whether obtaining a screen capture is supported in the current
116
- * environment.
117
- * @returns {boolean}
118
- */
119
-ScreenObtainer.prototype.isSupported = function() {
120
-    return !!this.obtainStream;
121
-};
122
-
123
-/**
124
- * Obtains a desktop stream using getUserMedia.
125
- * For this to work on Chrome, the
126
- * 'chrome://flags/#enable-usermedia-screen-capture' flag must be enabled.
127
- *
128
- * On firefox, the document's domain must be white-listed in the
129
- * 'media.getusermedia.screensharing.allowed_domains' preference in
130
- * 'about:config'.
131
- */
132
-function obtainWebRTCScreen(streamCallback, failCallback) {
133
-    APP.RTC.getUserMediaWithConstraints(
134
-        ['screen'],
135
-        streamCallback,
136
-        failCallback
137
-    );
138
-}
139
-
140
-/**
141
- * Constructs inline install URL for Chrome desktop streaming extension.
142
- * The 'chromeExtensionId' must be defined in config.js.
143
- * @returns {string}
144
- */
145
-function getWebStoreInstallUrl()
146
-{
147
-    //TODO remove chromeExtensionId (deprecated)
148
-    return "https://chrome.google.com/webstore/detail/" +
149
-        (config.desktopSharingChromeExtId || config.chromeExtensionId);
150
-}
151
-
152
-/**
153
- * Checks whether an update of the Chrome extension is required.
154
- * @param minVersion minimal required version
155
- * @param extVersion current extension version
156
- * @returns {boolean}
157
- */
158
-function isUpdateRequired(minVersion, extVersion) {
159
-    try {
160
-        var s1 = minVersion.split('.');
161
-        var s2 = extVersion.split('.');
162
-
163
-        var len = Math.max(s1.length, s2.length);
164
-        for (var i = 0; i < len; i++) {
165
-            var n1 = 0,
166
-                n2 = 0;
167
-
168
-            if (i < s1.length)
169
-                n1 = parseInt(s1[i]);
170
-            if (i < s2.length)
171
-                n2 = parseInt(s2[i]);
172
-
173
-            if (isNaN(n1) || isNaN(n2)) {
174
-                return true;
175
-            } else if (n1 !== n2) {
176
-                return n1 > n2;
177
-            }
178
-        }
179
-
180
-        // will happen if both versions have identical numbers in
181
-        // their components (even if one of them is longer, has more components)
182
-        return false;
183
-    }
184
-    catch (e) {
185
-        console.error("Failed to parse extension version", e);
186
-        APP.UI.messageHandler.showError("dialog.error",
187
-            "dialog.detectext");
188
-        return true;
189
-    }
190
-}
191
-
192
-function checkChromeExtInstalled(callback) {
193
-    if (!chrome || !chrome.runtime) {
194
-        // No API, so no extension for sure
195
-        callback(false, false);
196
-        return;
197
-    }
198
-    chrome.runtime.sendMessage(
199
-        //TODO: remove chromeExtensionId (deprecated)
200
-        (config.desktopSharingChromeExtId || config.chromeExtensionId),
201
-        { getVersion: true },
202
-        function (response) {
203
-            if (!response || !response.version) {
204
-                // Communication failure - assume that no endpoint exists
205
-                console.warn(
206
-                    "Extension not installed?: ", chrome.runtime.lastError);
207
-                callback(false, false);
208
-                return;
209
-            }
210
-            // Check installed extension version
211
-            var extVersion = response.version;
212
-            console.log('Extension version is: ' + extVersion);
213
-            //TODO: remove minChromeExtVersion (deprecated)
214
-            var updateRequired
215
-                = isUpdateRequired(
216
-                    (config.desktopSharingChromeMinExtVersion ||
217
-                        config.minChromeExtVersion),
218
-                    extVersion);
219
-            callback(!updateRequired, updateRequired);
220
-        }
221
-    );
222
-}
223
-
224
-function doGetStreamFromExtension(streamCallback, failCallback) {
225
-    // Sends 'getStream' msg to the extension.
226
-    // Extension id must be defined in the config.
227
-    chrome.runtime.sendMessage(
228
-        //TODO: remove chromeExtensionId (deprecated)
229
-        (config.desktopSharingChromeExtId || config.chromeExtensionId),
230
-        {
231
-            getStream: true,
232
-            //TODO: remove desktopSharingSources (deprecated).
233
-            sources: (config.desktopSharingChromeSources ||
234
-                config.desktopSharingSources)
235
-        },
236
-        function (response) {
237
-            if (!response) {
238
-                failCallback(chrome.runtime.lastError);
239
-                return;
240
-            }
241
-            console.log("Response from extension: " + response);
242
-            if (response.streamId) {
243
-                APP.RTC.getUserMediaWithConstraints(
244
-                    ['desktop'],
245
-                    function (stream) {
246
-                        streamCallback(stream);
247
-                    },
248
-                    failCallback,
249
-                    null, null, null,
250
-                    response.streamId);
251
-            } else {
252
-                failCallback("Extension failed to get the stream");
253
-            }
254
-        }
255
-    );
256
-}
257
-
258
-/**
259
- * Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop'
260
- * stream for returned stream token.
261
- */
262
-function obtainScreenFromExtension(streamCallback, failCallback) {
263
-    if (chromeExtInstalled) {
264
-        doGetStreamFromExtension(streamCallback, failCallback);
265
-    } else {
266
-        if (chromeExtUpdateRequired) {
267
-            alert(
268
-                'Jitsi Desktop Streamer requires update. ' +
269
-                'Changes will take effect after next Chrome restart.');
270
-        }
271
-
272
-        chrome.webstore.install(
273
-            getWebStoreInstallUrl(),
274
-            function (arg) {
275
-                console.log("Extension installed successfully", arg);
276
-                chromeExtInstalled = true;
277
-                // We need to give a moment for the endpoint to become available
278
-                window.setTimeout(function () {
279
-                    doGetStreamFromExtension(streamCallback, failCallback);
280
-                }, 500);
281
-            },
282
-            function (arg) {
283
-                console.log("Failed to install the extension", arg);
284
-                failCallback(arg);
285
-                APP.UI.messageHandler.showError("dialog.error",
286
-                    "dialog.failtoinstall");
287
-            }
288
-        );
289
-    }
290
-}
291
-
292
-/**
293
- * Initializes <link rel=chrome-webstore-item /> with extension id set in
294
- * config.js to support inline installs. Host site must be selected as main
295
- * website of published extension.
296
- */
297
-function initInlineInstalls()
298
-{
299
-    $("link[rel=chrome-webstore-item]").attr("href", getWebStoreInstallUrl());
300
-}
301
-
302
-function initChromeExtension() {
303
-    // Initialize Chrome extension inline installs
304
-    initInlineInstalls();
305
-    // Check if extension is installed
306
-    checkChromeExtInstalled(function (installed, updateRequired) {
307
-        chromeExtInstalled = installed;
308
-        chromeExtUpdateRequired = updateRequired;
309
-        console.info(
310
-            "Chrome extension installed: " + chromeExtInstalled +
311
-            " updateRequired: " + chromeExtUpdateRequired);
312
-    });
313
-}
314
-
315
-/**
316
- * Obtains a screen capture stream on Firefox.
317
- * @param callback
318
- * @param errorCallback
319
- */
320
-ScreenObtainer.prototype.obtainScreenOnFirefox =
321
-       function (callback, errorCallback) {
322
-    var self = this;
323
-    var extensionRequired = false;
324
-    if (config.desktopSharingFirefoxMaxVersionExtRequired === -1 ||
325
-        (config.desktopSharingFirefoxMaxVersionExtRequired >= 0 &&
326
-            RTCBrowserType.getFirefoxVersion() <=
327
-                config.desktopSharingFirefoxMaxVersionExtRequired)) {
328
-        extensionRequired = true;
329
-        console.log("Jidesha extension required on firefox version " +
330
-            RTCBrowserType.getFirefoxVersion());
331
-    }
332
-
333
-    if (!extensionRequired || firefoxExtInstalled === true) {
334
-        obtainWebRTCScreen(callback, errorCallback);
335
-        return;
336
-    }
337
-
338
-    if (reDetectFirefoxExtension) {
339
-        reDetectFirefoxExtension = false;
340
-        initFirefoxExtensionDetection();
341
-    }
342
-
343
-    // Give it some (more) time to initialize, and assume lack of extension if
344
-    // it hasn't.
345
-    if (firefoxExtInstalled === null) {
346
-        window.setTimeout(
347
-            function() {
348
-                if (firefoxExtInstalled === null)
349
-                    firefoxExtInstalled = false;
350
-                self.obtainScreenOnFirefox(callback, errorCallback);
351
-            },
352
-            300
353
-        );
354
-        console.log("Waiting for detection of jidesha on firefox to finish.");
355
-        return;
356
-    }
357
-
358
-    // We need an extension and it isn't installed.
359
-
360
-    // Make sure we check for the extension when the user clicks again.
361
-    firefoxExtInstalled = null;
362
-    reDetectFirefoxExtension = true;
363
-
364
-    // Prompt the user to install the extension
365
-    this.eventEmitter.emit(DesktopSharingEventTypes.FIREFOX_EXTENSION_NEEDED,
366
-                           config.desktopSharingFirefoxExtensionURL);
367
-
368
-    // Make sure desktopsharing knows that we failed, so that it doesn't get
369
-    // stuck in 'switching' mode.
370
-    errorCallback('Firefox extension required.');
371
-};
372
-
373
-/**
374
- * Starts the detection of an installed jidesha extension for firefox.
375
- */
376
-function initFirefoxExtensionDetection() {
377
-    if (config.desktopSharingFirefoxDisabled) {
378
-        return;
379
-    }
380
-    if (firefoxExtInstalled === false || firefoxExtInstalled === true)
381
-        return;
382
-    if (!config.desktopSharingFirefoxExtId) {
383
-        firefoxExtInstalled = false;
384
-        return;
385
-    }
386
-
387
-    var img = document.createElement('img');
388
-    img.onload = function(){
389
-        console.log("Detected firefox screen sharing extension.");
390
-        firefoxExtInstalled = true;
391
-    };
392
-    img.onerror = function(){
393
-        console.log("Detected lack of firefox screen sharing extension.");
394
-        firefoxExtInstalled = false;
395
-    };
396
-
397
-    // The jidesha extension exposes an empty image file under the url:
398
-    // "chrome://EXT_ID/content/DOMAIN.png"
399
-    // Where EXT_ID is the ID of the extension with "@" replaced by ".", and
400
-    // DOMAIN is a domain whitelisted by the extension.
401
-    var src = "chrome://" +
402
-        (config.desktopSharingFirefoxExtId.replace('@', '.')) +
403
-        "/content/" + document.location.hostname + ".png";
404
-    img.setAttribute('src', src);
405
-}
406
-
407
-module.exports = ScreenObtainer;

+ 26
- 48
modules/desktopsharing/desktopsharing.js Parādīt failu

@@ -2,9 +2,6 @@
2 2
 var EventEmitter = require("events");
3 3
 var DesktopSharingEventTypes
4 4
     = require("../../service/desktopsharing/DesktopSharingEventTypes");
5
-var RTCBrowserType = require("../RTC/RTCBrowserType");
6
-var RTCEvents = require("../../service/RTC/RTCEvents");
7
-var ScreenObtainer = require("./ScreenObtainer");
8 5
 
9 6
 /**
10 7
  * Indicates that desktop stream is currently in use (for toggle purpose).
@@ -20,9 +17,9 @@ var isUsingScreenStream = false;
20 17
 var switchInProgress = false;
21 18
 
22 19
 /**
23
- * Used to obtain the screen sharing stream from the browser.
20
+ * true if desktop sharing is enabled and false otherwise.
24 21
  */
25
-var screenObtainer = new ScreenObtainer();
22
+var isEnabled = false;
26 23
 
27 24
 var eventEmitter = new EventEmitter();
28 25
 
@@ -33,9 +30,9 @@ function streamSwitchDone() {
33 30
         isUsingScreenStream);
34 31
 }
35 32
 
36
-function newStreamCreated(stream) {
33
+function newStreamCreated(track) {
37 34
     eventEmitter.emit(DesktopSharingEventTypes.NEW_STREAM_CREATED,
38
-        stream, isUsingScreenStream, streamSwitchDone);
35
+        track, streamSwitchDone);
39 36
 }
40 37
 
41 38
 function getVideoStreamFailed(error) {
@@ -50,37 +47,31 @@ function getDesktopStreamFailed(error) {
50 47
     switchInProgress = false;
51 48
 }
52 49
 
53
-function onEndedHandler(stream) {
50
+function onEndedHandler() {
54 51
     if (!switchInProgress && isUsingScreenStream) {
55 52
         APP.desktopsharing.toggleScreenSharing();
56 53
     }
57
-
58
-    APP.RTC.removeMediaStreamInactiveHandler(stream, onEndedHandler);
59 54
 }
60 55
 
61 56
 module.exports = {
62 57
     isUsingScreenStream: function () {
63 58
         return isUsingScreenStream;
64 59
     },
65
-
60
+    /**
61
+     * Initializes the desktop sharing module.
62
+     * @param {boolean} <tt>true</tt> if desktop sharing feature is available
63
+     * and enabled.
64
+     */
65
+    init: function (enabled) {
66
+        isEnabled = enabled;
67
+    },
66 68
     /**
67 69
      * @returns {boolean} <tt>true</tt> if desktop sharing feature is available
68 70
      *          and enabled.
69 71
      */
70 72
     isDesktopSharingEnabled: function () {
71
-        return screenObtainer.isSupported();
73
+        return isEnabled;
72 74
     },
73
-    
74
-    init: function () {
75
-        // Called when RTC finishes initialization
76
-        return;
77
-        APP.RTC.addListener(RTCEvents.RTC_READY,
78
-            function() {
79
-                screenObtainer.init(eventEmitter);
80
-                eventEmitter.emit(DesktopSharingEventTypes.INIT);
81
-            });
82
-    },
83
-
84 75
     addListener: function (type, listener) {
85 76
         eventEmitter.on(type, listener);
86 77
     },
@@ -96,38 +87,26 @@ module.exports = {
96 87
         if (switchInProgress) {
97 88
             console.warn("Switch in progress.");
98 89
             return;
99
-        } else if (!screenObtainer.isSupported()) {
90
+        } else if (!this.isDesktopSharingEnabled()) {
100 91
             console.warn("Cannot toggle screen sharing: not supported.");
101 92
             return;
102 93
         }
103 94
         switchInProgress = true;
104
-
95
+        let type, handler;
105 96
         if (!isUsingScreenStream) {
106 97
             // Switch to desktop stream
107
-            screenObtainer.obtainStream(
108
-                function (stream) {
109
-                    // We now use screen stream
110
-                    isUsingScreenStream = true;
111
-                    // Hook 'ended' event to restore camera
112
-                    // when screen stream stops
113
-                    APP.RTC.addMediaStreamInactiveHandler(
114
-                        stream, onEndedHandler);
115
-                    newStreamCreated(stream);
116
-                },
117
-                getDesktopStreamFailed);
98
+            handler = onEndedHandler;
99
+            type = "desktop";
118 100
         } else {
119
-            // Disable screen stream
120
-            APP.RTC.getUserMediaWithConstraints(
121
-                ['video'],
122
-                function (stream) {
123
-                    // We are now using camera stream
124
-                    isUsingScreenStream = false;
125
-                    newStreamCreated(stream);
126
-                },
127
-                getVideoStreamFailed,
128
-                config.resolution || '360'
129
-            );
101
+            handler = () => {};
102
+            type = "video";
130 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);
131 110
     },
132 111
     /*
133 112
      * Exports the event emitter to allow use by ScreenObtainer. Not for outside
@@ -135,4 +114,3 @@ module.exports = {
135 114
      */
136 115
     eventEmitter: eventEmitter
137 116
 };
138
-

Notiek ielāde…
Atcelt
Saglabāt