Преглед изворни кода

Chrome no longer allows to trigger install from extension msg response callback, so we have to check if extension exists before user clicks "share desktop" button(on startup). Fixes jshint warnings.

master
paweldomas пре 10 година
родитељ
комит
cd19c0e9e3
3 измењених фајлова са 26072 додато и 26000 уклоњено
  1. 1
    1
      index.html
  2. 25979
    25943
      libs/app.bundle.js
  3. 92
    56
      modules/desktopsharing/desktopsharing.js

+ 1
- 1
index.html Прегледај датотеку

19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
19
     <script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
20
     <script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
21
     <script src="interface_config.js?v=5"></script>
21
     <script src="interface_config.js?v=5"></script>
22
-    <script src="libs/app.bundle.js?v=40"></script>
22
+    <script src="libs/app.bundle.js?v=41"></script>
23
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
23
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
24
     <link rel="stylesheet" href="css/font.css?v=6"/>
24
     <link rel="stylesheet" href="css/font.css?v=6"/>
25
     <link rel="stylesheet" href="css/toastr.css?v=1">
25
     <link rel="stylesheet" href="css/toastr.css?v=1">

+ 25979
- 25943
libs/app.bundle.js
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 92
- 56
modules/desktopsharing/desktopsharing.js Прегледај датотеку

1
-/* global $, alert, changeLocalVideo, chrome, config, getConferenceHandler, getUserMediaWithConstraints */
1
+/* global $, alert, APP, changeLocalVideo, chrome, config, getConferenceHandler,
2
+ getUserMediaWithConstraints */
2
 /**
3
 /**
3
  * Indicates that desktop stream is currently in use(for toggle purpose).
4
  * Indicates that desktop stream is currently in use(for toggle purpose).
4
  * @type {boolean}
5
  * @type {boolean}
5
  */
6
  */
6
 var isUsingScreenStream = false;
7
 var isUsingScreenStream = false;
7
 /**
8
 /**
8
- * Indicates that switch stream operation is in progress and prevent from triggering new events.
9
+ * Indicates that switch stream operation is in progress and prevent from
10
+ * triggering new events.
9
  * @type {boolean}
11
  * @type {boolean}
10
  */
12
  */
11
 var switchInProgress = false;
13
 var switchInProgress = false;
18
 var obtainDesktopStream = null;
20
 var obtainDesktopStream = null;
19
 
21
 
20
 /**
22
 /**
21
- * Flag used to cache desktop sharing enabled state. Do not use directly as it can be <tt>null</tt>.
23
+ * Indicates whether desktop sharing extension is installed.
24
+ * @type {boolean}
25
+ */
26
+var extInstalled = false;
27
+
28
+/**
29
+ * Indicates whether update of desktop sharing extension is required.
30
+ * @type {boolean}
31
+ */
32
+var extUpdateRequired = false;
33
+
34
+/**
35
+ * Flag used to cache desktop sharing enabled state. Do not use directly as
36
+ * it can be <tt>null</tt>.
37
+ *
22
  * @type {null|boolean}
38
  * @type {null|boolean}
23
  */
39
  */
24
 var _desktopSharingEnabled = null;
40
 var _desktopSharingEnabled = null;
27
 
43
 
28
 var eventEmitter = new EventEmitter();
44
 var eventEmitter = new EventEmitter();
29
 
45
 
30
-var DesktopSharingEventTypes = require("../../service/desktopsharing/DesktopSharingEventTypes");
46
+var DesktopSharingEventTypes
47
+    = require("../../service/desktopsharing/DesktopSharingEventTypes");
31
 
48
 
32
 /**
49
 /**
33
  * Method obtains desktop stream from WebRTC 'screen' source.
50
  * Method obtains desktop stream from WebRTC 'screen' source.
48
  */
65
  */
49
 function getWebStoreInstallUrl()
66
 function getWebStoreInstallUrl()
50
 {
67
 {
51
-    return "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId;
68
+    return "https://chrome.google.com/webstore/detail/" +
69
+        config.chromeExtensionId;
52
 }
70
 }
53
 
71
 
54
 /**
72
 /**
98
     }
116
     }
99
 }
117
 }
100
 
118
 
101
-
102
-function checkExtInstalled(isInstalledCallback) {
119
+function checkExtInstalled(callback) {
103
     if (!chrome.runtime) {
120
     if (!chrome.runtime) {
104
         // No API, so no extension for sure
121
         // No API, so no extension for sure
105
-        isInstalledCallback(false);
122
+        callback(false, false);
106
         return;
123
         return;
107
     }
124
     }
108
     chrome.runtime.sendMessage(
125
     chrome.runtime.sendMessage(
111
         function (response) {
128
         function (response) {
112
             if (!response || !response.version) {
129
             if (!response || !response.version) {
113
                 // Communication failure - assume that no endpoint exists
130
                 // Communication failure - assume that no endpoint exists
114
-                console.warn("Extension not installed?: " + chrome.runtime.lastError);
115
-                isInstalledCallback(false);
116
-            } else {
117
-                // Check installed extension version
118
-                var extVersion = response.version;
119
-                console.log('Extension version is: ' + extVersion);
120
-                var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion);
121
-                if (updateRequired) {
122
-                    alert(
123
-                        'Jitsi Desktop Streamer requires update. ' +
124
-                        'Changes will take effect after next Chrome restart.');
125
-                }
126
-                isInstalledCallback(!updateRequired);
131
+                console.warn(
132
+                    "Extension not installed?: ", chrome.runtime.lastError);
133
+                callback(false, false);
134
+                return;
127
             }
135
             }
136
+            // Check installed extension version
137
+            var extVersion = response.version;
138
+            console.log('Extension version is: ' + extVersion);
139
+            var updateRequired
140
+                = isUpdateRequired(config.minChromeExtVersion, extVersion);
141
+            callback(!updateRequired, updateRequired);
128
         }
142
         }
129
     );
143
     );
130
 }
144
 }
131
 
145
 
132
 function doGetStreamFromExtension(streamCallback, failCallback) {
146
 function doGetStreamFromExtension(streamCallback, failCallback) {
133
-    // Sends 'getStream' msg to the extension. Extension id must be defined in the config.
147
+    // Sends 'getStream' msg to the extension.
148
+    // Extension id must be defined in the config.
134
     chrome.runtime.sendMessage(
149
     chrome.runtime.sendMessage(
135
         config.chromeExtensionId,
150
         config.chromeExtensionId,
136
         { getStream: true, sources: config.desktopSharingSources },
151
         { getStream: true, sources: config.desktopSharingSources },
156
     );
171
     );
157
 }
172
 }
158
 /**
173
 /**
159
- * Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
174
+ * Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop'
175
+ * stream for returned stream token.
160
  */
176
  */
161
 function obtainScreenFromExtension(streamCallback, failCallback) {
177
 function obtainScreenFromExtension(streamCallback, failCallback) {
162
-    checkExtInstalled(
163
-        function (isInstalled) {
164
-            if (isInstalled) {
165
-                doGetStreamFromExtension(streamCallback, failCallback);
166
-            } else {
167
-                chrome.webstore.install(
168
-                    getWebStoreInstallUrl(),
169
-                    function (arg) {
170
-                        console.log("Extension installed successfully", arg);
171
-                        // We need to reload the page in order to get the access to chrome.runtime
172
-                        window.location.reload(false);
173
-                    },
174
-                    function (arg) {
175
-                        console.log("Failed to install the extension", arg);
176
-                        failCallback(arg);
177
-                        APP.UI.messageHandler.showError("dialog.error",
178
-                            "dialog.failtoinstall");
179
-                    }
180
-                );
181
-            }
178
+    if (extInstalled) {
179
+        doGetStreamFromExtension(streamCallback, failCallback);
180
+    } else {
181
+        if (extUpdateRequired) {
182
+            alert(
183
+                'Jitsi Desktop Streamer requires update. ' +
184
+                'Changes will take effect after next Chrome restart.');
182
         }
185
         }
183
-    );
186
+
187
+        chrome.webstore.install(
188
+            getWebStoreInstallUrl(),
189
+            function (arg) {
190
+                console.log("Extension installed successfully", arg);
191
+                // We need to reload the page in order to get the access to
192
+                // chrome.runtime
193
+                window.location.reload(false);
194
+            },
195
+            function (arg) {
196
+                console.log("Failed to install the extension", arg);
197
+                failCallback(arg);
198
+                APP.UI.messageHandler.showError("dialog.error",
199
+                    "dialog.failtoinstall");
200
+            }
201
+        );
202
+    }
184
 }
203
 }
185
 
204
 
186
 /**
205
 /**
187
  * Call this method to toggle desktop sharing feature.
206
  * Call this method to toggle desktop sharing feature.
188
- * @param method pass "ext" to use chrome extension for desktop capture(chrome extension required),
189
- *        pass "webrtc" to use WebRTC "screen" desktop source('chrome://flags/#enable-usermedia-screen-capture'
190
- *        must be enabled), pass any other string or nothing in order to disable this feature completely.
207
+ * @param method pass "ext" to use chrome extension for desktop capture(chrome
208
+ *        extension required), pass "webrtc" to use WebRTC "screen" desktop
209
+ *        source('chrome://flags/#enable-usermedia-screen-capture' must be
210
+ *        enabled), pass any other string or nothing in order to disable this
211
+ *        feature completely.
191
  */
212
  */
192
 function setDesktopSharing(method) {
213
 function setDesktopSharing(method) {
193
     // Check if we are running chrome
214
     // Check if we are running chrome
207
 }
228
 }
208
 
229
 
209
 /**
230
 /**
210
- * Initializes <link rel=chrome-webstore-item /> with extension id set in config.js to support inline installs.
211
- * Host site must be selected as main website of published extension.
231
+ * Initializes <link rel=chrome-webstore-item /> with extension id set in
232
+ * config.js to support inline installs. Host site must be selected as main
233
+ * website of published extension.
212
  */
234
  */
213
 function initInlineInstalls()
235
 function initInlineInstalls()
214
 {
236
 {
240
     },
262
     },
241
 
263
 
242
     /**
264
     /**
243
-     * @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
265
+     * @returns {boolean} <tt>true</tt> if desktop sharing feature is available
266
+     *          and enabled.
244
      */
267
      */
245
     isDesktopSharingEnabled: function () {
268
     isDesktopSharingEnabled: function () {
246
         if (_desktopSharingEnabled === null) {
269
         if (_desktopSharingEnabled === null) {
247
             if (obtainDesktopStream === obtainScreenFromExtension) {
270
             if (obtainDesktopStream === obtainScreenFromExtension) {
248
                 // Parse chrome version
271
                 // Parse chrome version
249
                 var userAgent = navigator.userAgent.toLowerCase();
272
                 var userAgent = navigator.userAgent.toLowerCase();
250
-                // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set
273
+                // We can assume that user agent is chrome, because it's
274
+                // enforced when 'ext' streaming method is set
251
                 var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
275
                 var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
252
                 console.log("Chrome version" + userAgent, ver);
276
                 console.log("Chrome version" + userAgent, ver);
253
                 _desktopSharingEnabled = ver >= 34;
277
                 _desktopSharingEnabled = ver >= 34;
254
             } else {
278
             } else {
255
-                _desktopSharingEnabled = obtainDesktopStream === obtainWebRTCScreen;
279
+                _desktopSharingEnabled =
280
+                    obtainDesktopStream === obtainWebRTCScreen;
256
             }
281
             }
257
         }
282
         }
258
         return _desktopSharingEnabled;
283
         return _desktopSharingEnabled;
263
 
288
 
264
         // Initialize Chrome extension inline installs
289
         // Initialize Chrome extension inline installs
265
         if (config.chromeExtensionId) {
290
         if (config.chromeExtensionId) {
291
+
266
             initInlineInstalls();
292
             initInlineInstalls();
293
+
294
+            // Check if extension is installed
295
+            checkExtInstalled(function (installed, updateRequired) {
296
+                extInstalled = installed;
297
+                extUpdateRequired = updateRequired;
298
+                console.info(
299
+                    "Chrome extension installed: " + extInstalled +
300
+                    " updateRequired: " + extUpdateRequired);
301
+            });
267
         }
302
         }
268
 
303
 
269
         eventEmitter.emit(DesktopSharingEventTypes.INIT);
304
         eventEmitter.emit(DesktopSharingEventTypes.INIT);
270
     },
305
     },
271
 
306
 
272
-    addListener: function(listener, type)
307
+    addListener: function (listener, type)
273
     {
308
     {
274
         eventEmitter.on(type, listener);
309
         eventEmitter.on(type, listener);
275
     },
310
     },
276
 
311
 
277
-    removeListener: function (listener,type) {
312
+    removeListener: function (listener, type) {
278
         eventEmitter.removeListener(type, listener);
313
         eventEmitter.removeListener(type, listener);
279
     },
314
     },
280
 
315
 
295
                 function (stream) {
330
                 function (stream) {
296
                     // We now use screen stream
331
                     // We now use screen stream
297
                     isUsingScreenStream = true;
332
                     isUsingScreenStream = true;
298
-                    // Hook 'ended' event to restore camera when screen stream stops
333
+                    // Hook 'ended' event to restore camera
334
+                    // when screen stream stops
299
                     stream.addEventListener('ended',
335
                     stream.addEventListener('ended',
300
                         function (e) {
336
                         function (e) {
301
                             if (!switchInProgress && isUsingScreenStream) {
337
                             if (!switchInProgress && isUsingScreenStream) {
302
-                                toggleScreenSharing();
338
+                                APP.desktopsharing.toggleScreenSharing();
303
                             }
339
                             }
304
                         }
340
                         }
305
                     );
341
                     );

Loading…
Откажи
Сачувај