|
@@ -1,11 +1,13 @@
|
1
|
|
-/* global $, alert, changeLocalVideo, chrome, config, getConferenceHandler, getUserMediaWithConstraints */
|
|
1
|
+/* global $, alert, APP, changeLocalVideo, chrome, config, getConferenceHandler,
|
|
2
|
+ getUserMediaWithConstraints */
|
2
|
3
|
/**
|
3
|
4
|
* Indicates that desktop stream is currently in use(for toggle purpose).
|
4
|
5
|
* @type {boolean}
|
5
|
6
|
*/
|
6
|
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
|
11
|
* @type {boolean}
|
10
|
12
|
*/
|
11
|
13
|
var switchInProgress = false;
|
|
@@ -18,7 +20,21 @@ var switchInProgress = false;
|
18
|
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
|
38
|
* @type {null|boolean}
|
23
|
39
|
*/
|
24
|
40
|
var _desktopSharingEnabled = null;
|
|
@@ -27,7 +43,8 @@ var EventEmitter = require("events");
|
27
|
43
|
|
28
|
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
|
50
|
* Method obtains desktop stream from WebRTC 'screen' source.
|
|
@@ -48,7 +65,8 @@ function obtainWebRTCScreen(streamCallback, failCallback) {
|
48
|
65
|
*/
|
49
|
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,11 +116,10 @@ function isUpdateRequired(minVersion, extVersion)
|
98
|
116
|
}
|
99
|
117
|
}
|
100
|
118
|
|
101
|
|
-
|
102
|
|
-function checkExtInstalled(isInstalledCallback) {
|
|
119
|
+function checkExtInstalled(callback) {
|
103
|
120
|
if (!chrome.runtime) {
|
104
|
121
|
// No API, so no extension for sure
|
105
|
|
- isInstalledCallback(false);
|
|
122
|
+ callback(false, false);
|
106
|
123
|
return;
|
107
|
124
|
}
|
108
|
125
|
chrome.runtime.sendMessage(
|
|
@@ -111,26 +128,24 @@ function checkExtInstalled(isInstalledCallback) {
|
111
|
128
|
function (response) {
|
112
|
129
|
if (!response || !response.version) {
|
113
|
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
|
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
|
149
|
chrome.runtime.sendMessage(
|
135
|
150
|
config.chromeExtensionId,
|
136
|
151
|
{ getStream: true, sources: config.desktopSharingSources },
|
|
@@ -156,38 +171,44 @@ function doGetStreamFromExtension(streamCallback, failCallback) {
|
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
|
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
|
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
|
213
|
function setDesktopSharing(method) {
|
193
|
214
|
// Check if we are running chrome
|
|
@@ -207,8 +228,9 @@ function setDesktopSharing(method) {
|
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
|
235
|
function initInlineInstalls()
|
214
|
236
|
{
|
|
@@ -240,19 +262,22 @@ module.exports = {
|
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
|
268
|
isDesktopSharingEnabled: function () {
|
246
|
269
|
if (_desktopSharingEnabled === null) {
|
247
|
270
|
if (obtainDesktopStream === obtainScreenFromExtension) {
|
248
|
271
|
// Parse chrome version
|
249
|
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
|
275
|
var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
|
252
|
276
|
console.log("Chrome version" + userAgent, ver);
|
253
|
277
|
_desktopSharingEnabled = ver >= 34;
|
254
|
278
|
} else {
|
255
|
|
- _desktopSharingEnabled = obtainDesktopStream === obtainWebRTCScreen;
|
|
279
|
+ _desktopSharingEnabled =
|
|
280
|
+ obtainDesktopStream === obtainWebRTCScreen;
|
256
|
281
|
}
|
257
|
282
|
}
|
258
|
283
|
return _desktopSharingEnabled;
|
|
@@ -263,18 +288,28 @@ module.exports = {
|
263
|
288
|
|
264
|
289
|
// Initialize Chrome extension inline installs
|
265
|
290
|
if (config.chromeExtensionId) {
|
|
291
|
+
|
266
|
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
|
304
|
eventEmitter.emit(DesktopSharingEventTypes.INIT);
|
270
|
305
|
},
|
271
|
306
|
|
272
|
|
- addListener: function(listener, type)
|
|
307
|
+ addListener: function (listener, type)
|
273
|
308
|
{
|
274
|
309
|
eventEmitter.on(type, listener);
|
275
|
310
|
},
|
276
|
311
|
|
277
|
|
- removeListener: function (listener,type) {
|
|
312
|
+ removeListener: function (listener, type) {
|
278
|
313
|
eventEmitter.removeListener(type, listener);
|
279
|
314
|
},
|
280
|
315
|
|
|
@@ -295,11 +330,12 @@ module.exports = {
|
295
|
330
|
function (stream) {
|
296
|
331
|
// We now use screen stream
|
297
|
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
|
335
|
stream.addEventListener('ended',
|
300
|
336
|
function (e) {
|
301
|
337
|
if (!switchInProgress && isUsingScreenStream) {
|
302
|
|
- toggleScreenSharing();
|
|
338
|
+ APP.desktopsharing.toggleScreenSharing();
|
303
|
339
|
}
|
304
|
340
|
}
|
305
|
341
|
);
|