|
@@ -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;
|