|
@@ -2,12 +2,15 @@
|
2
|
2
|
/* jshint -W003 */
|
3
|
3
|
var RTCBrowserType = require("../RTC/RTCBrowserType");
|
4
|
4
|
var AdapterJS = require("../RTC/adapter.screenshare");
|
|
5
|
+var DesktopSharingEventTypes
|
|
6
|
+ = require("../../service/desktopsharing/DesktopSharingEventTypes");
|
5
|
7
|
|
6
|
8
|
/**
|
7
|
9
|
* Indicates whether the Chrome desktop sharing extension is installed.
|
8
|
10
|
* @type {boolean}
|
9
|
11
|
*/
|
10
|
12
|
var chromeExtInstalled = false;
|
|
13
|
+
|
11
|
14
|
/**
|
12
|
15
|
* Indicates whether an update of the Chrome desktop sharing extension is
|
13
|
16
|
* required.
|
|
@@ -15,27 +18,54 @@ var chromeExtInstalled = false;
|
15
|
18
|
*/
|
16
|
19
|
var chromeExtUpdateRequired = false;
|
17
|
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
|
+
|
18
|
35
|
/**
|
19
|
36
|
* Handles obtaining a stream from a screen capture on different browsers.
|
20
|
37
|
*/
|
21
|
38
|
function ScreenObtainer(){
|
22
|
39
|
}
|
23
|
40
|
|
|
41
|
+/**
|
|
42
|
+ * The EventEmitter to use to emit events.
|
|
43
|
+ * @type {null}
|
|
44
|
+ */
|
|
45
|
+ScreenObtainer.prototype.eventEmitter = null;
|
|
46
|
+
|
24
|
47
|
/**
|
25
|
48
|
* Initializes the function used to obtain a screen capture (this.obtainStream).
|
26
|
49
|
*
|
27
|
|
- * If the browser is Chrome, it uses the value of 'config.desktopSharing' to
|
28
|
|
- * decide whether to use the a Chrome extension (if the value is 'ext'), use
|
29
|
|
- * the "screen" media source (if the value is 'webrtc'), or disable screen
|
30
|
|
- * capture (if the value is other).
|
|
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).
|
31
|
55
|
* Note that for the "screen" media source to work the
|
32
|
56
|
* 'chrome://flags/#enable-usermedia-screen-capture' flag must be set.
|
33
|
57
|
*/
|
34
|
|
-ScreenObtainer.prototype.init = function() {
|
|
58
|
+ScreenObtainer.prototype.init = function(eventEmitter) {
|
|
59
|
+ this.eventEmitter = eventEmitter;
|
35
|
60
|
var obtainDesktopStream = null;
|
36
|
61
|
|
37
|
|
- // When TemasysWebRTC plugin is used we always use getUserMedia, so we don't
|
38
|
|
- // care about the value of config.desktopSharing.
|
|
62
|
+ if (RTCBrowserType.isFirefox())
|
|
63
|
+ initFirefoxExtensionDetection();
|
|
64
|
+
|
|
65
|
+ // TODO remove this, config.desktopSharing is deprecated.
|
|
66
|
+ var chromeMethod =
|
|
67
|
+ (config.desktopSharingChromeMethod || config.desktopSharing);
|
|
68
|
+
|
39
|
69
|
if (RTCBrowserType.isTemasysPluginUsed()) {
|
40
|
70
|
if (!AdapterJS.WebRTCPlugin.plugin.HasScreensharingFeature) {
|
41
|
71
|
console.info("Screensharing not supported by this plugin version");
|
|
@@ -47,7 +77,7 @@ ScreenObtainer.prototype.init = function() {
|
47
|
77
|
console.info("Using Temasys plugin for desktop sharing");
|
48
|
78
|
}
|
49
|
79
|
} else if (RTCBrowserType.isChrome()) {
|
50
|
|
- if (config.desktopSharing == "ext") {
|
|
80
|
+ if (chromeMethod == "ext") {
|
51
|
81
|
if (RTCBrowserType.getChromeVersion() >= 34) {
|
52
|
82
|
obtainDesktopStream = obtainScreenFromExtension;
|
53
|
83
|
console.info("Using Chrome extension for desktop sharing");
|
|
@@ -55,19 +85,28 @@ ScreenObtainer.prototype.init = function() {
|
55
|
85
|
} else {
|
56
|
86
|
console.info("Chrome extension not supported until ver 34");
|
57
|
87
|
}
|
58
|
|
- } else if (config.desktopSharing == "webrtc") {
|
|
88
|
+ } else if (chromeMethod == "webrtc") {
|
59
|
89
|
obtainDesktopStream = obtainWebRTCScreen;
|
60
|
90
|
console.info("Using Chrome WebRTC for desktop sharing");
|
61
|
91
|
}
|
62
|
92
|
} else if (RTCBrowserType.isFirefox()) {
|
63
|
|
- obtainDesktopStream = obtainWebRTCScreen;
|
|
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
|
+
|
64
|
103
|
}
|
65
|
104
|
|
66
|
105
|
if (!obtainDesktopStream) {
|
67
|
106
|
console.info("Desktop sharing disabled");
|
68
|
107
|
}
|
69
|
108
|
|
70
|
|
- ScreenObtainer.prototype.obtainStream = obtainDesktopStream.bind(this);
|
|
109
|
+ ScreenObtainer.prototype.obtainStream = obtainDesktopStream;
|
71
|
110
|
};
|
72
|
111
|
|
73
|
112
|
ScreenObtainer.prototype.obtainStream = null;
|
|
@@ -105,8 +144,9 @@ function obtainWebRTCScreen(streamCallback, failCallback) {
|
105
|
144
|
*/
|
106
|
145
|
function getWebStoreInstallUrl()
|
107
|
146
|
{
|
|
147
|
+ //TODO remove chromeExtensionId (deprecated)
|
108
|
148
|
return "https://chrome.google.com/webstore/detail/" +
|
109
|
|
- config.chromeExtensionId;
|
|
149
|
+ (config.desktopSharingChromeExtId || config.chromeExtensionId);
|
110
|
150
|
}
|
111
|
151
|
|
112
|
152
|
/**
|
|
@@ -156,7 +196,8 @@ function checkChromeExtInstalled(callback) {
|
156
|
196
|
return;
|
157
|
197
|
}
|
158
|
198
|
chrome.runtime.sendMessage(
|
159
|
|
- config.chromeExtensionId,
|
|
199
|
+ //TODO: remove chromeExtensionId (deprecated)
|
|
200
|
+ (config.desktopSharingChromeExtId || config.chromeExtensionId),
|
160
|
201
|
{ getVersion: true },
|
161
|
202
|
function (response) {
|
162
|
203
|
if (!response || !response.version) {
|
|
@@ -169,8 +210,12 @@ function checkChromeExtInstalled(callback) {
|
169
|
210
|
// Check installed extension version
|
170
|
211
|
var extVersion = response.version;
|
171
|
212
|
console.log('Extension version is: ' + extVersion);
|
|
213
|
+ //TODO: remove minChromeExtVersion (deprecated)
|
172
|
214
|
var updateRequired
|
173
|
|
- = isUpdateRequired(config.minChromeExtVersion, extVersion);
|
|
215
|
+ = isUpdateRequired(
|
|
216
|
+ (config.desktopSharingChromeMinExtVersion ||
|
|
217
|
+ config.minChromeExtVersion),
|
|
218
|
+ extVersion);
|
174
|
219
|
callback(!updateRequired, updateRequired);
|
175
|
220
|
}
|
176
|
221
|
);
|
|
@@ -181,7 +226,12 @@ function doGetStreamFromExtension(streamCallback, failCallback) {
|
181
|
226
|
// Extension id must be defined in the config.
|
182
|
227
|
chrome.runtime.sendMessage(
|
183
|
228
|
config.chromeExtensionId,
|
184
|
|
- { getStream: true, sources: config.desktopSharingSources },
|
|
229
|
+ {
|
|
230
|
+ getStream: true,
|
|
231
|
+ //TODO: remove desktopSharingSources (deprecated).
|
|
232
|
+ sources: (config.desktopSharingChromeSources ||
|
|
233
|
+ config.desktopSharingSources)
|
|
234
|
+ },
|
185
|
235
|
function (response) {
|
186
|
236
|
if (!response) {
|
187
|
237
|
failCallback(chrome.runtime.lastError);
|
|
@@ -261,5 +311,96 @@ function initChromeExtension() {
|
261
|
311
|
});
|
262
|
312
|
}
|
263
|
313
|
|
|
314
|
+/**
|
|
315
|
+ * Obtains a screen capture stream on Firefox.
|
|
316
|
+ * @param callback
|
|
317
|
+ * @param errorCallback
|
|
318
|
+ */
|
|
319
|
+ScreenObtainer.prototype.obtainScreenOnFirefox =
|
|
320
|
+ function (callback, errorCallback) {
|
|
321
|
+ var self = this;
|
|
322
|
+ var extensionRequired = false;
|
|
323
|
+ if (config.desktopSharingFirefoxMaxVersionExtRequired === -1 ||
|
|
324
|
+ (config.desktopSharingFirefoxMaxVersionExtRequired >= 0 &&
|
|
325
|
+ RTCBrowserType.getFirefoxVersion() <=
|
|
326
|
+ config.desktopSharingFirefoxMaxVersionExtRequired)) {
|
|
327
|
+ extensionRequired = true;
|
|
328
|
+ console.log("Jidesha extension required on firefox version " +
|
|
329
|
+ RTCBrowserType.getFirefoxVersion());
|
|
330
|
+ }
|
|
331
|
+
|
|
332
|
+ if (!extensionRequired || firefoxExtInstalled === true) {
|
|
333
|
+ obtainWebRTCScreen(callback, errorCallback);
|
|
334
|
+ return;
|
|
335
|
+ }
|
|
336
|
+
|
|
337
|
+ if (reDetectFirefoxExtension) {
|
|
338
|
+ reDetectFirefoxExtension = false;
|
|
339
|
+ initFirefoxExtensionDetection();
|
|
340
|
+ }
|
|
341
|
+
|
|
342
|
+ // Give it some (more) time to initialize, and assume lack of extension if
|
|
343
|
+ // it hasn't.
|
|
344
|
+ if (firefoxExtInstalled === null) {
|
|
345
|
+ window.setTimeout(
|
|
346
|
+ function() {
|
|
347
|
+ if (firefoxExtInstalled === null)
|
|
348
|
+ firefoxExtInstalled = false;
|
|
349
|
+ self.obtainScreenOnFirefox(callback, errorCallback);
|
|
350
|
+ },
|
|
351
|
+ 300
|
|
352
|
+ );
|
|
353
|
+ console.log("Waiting for detection of jidesha on firefox to finish.");
|
|
354
|
+ return;
|
|
355
|
+ }
|
|
356
|
+
|
|
357
|
+ // We need an extension and it isn't installed.
|
|
358
|
+
|
|
359
|
+ // Make sure we check for the extension when the user clicks again.
|
|
360
|
+ firefoxExtInstalled = null;
|
|
361
|
+ reDetectFirefoxExtension = true;
|
|
362
|
+
|
|
363
|
+ // Prompt the user to install the extension
|
|
364
|
+ this.eventEmitter.emit(DesktopSharingEventTypes.FIREFOX_EXTENSION_NEEDED,
|
|
365
|
+ config.desktopSharingFirefoxExtensionURL);
|
|
366
|
+
|
|
367
|
+ // Make sure desktopsharing knows that we failed, so that it doesn't get
|
|
368
|
+ // stuck in 'switching' mode.
|
|
369
|
+ errorCallback('Firefox extension required.');
|
|
370
|
+};
|
|
371
|
+
|
|
372
|
+/**
|
|
373
|
+ * Starts the detection of an installed jidesha extension for firefox.
|
|
374
|
+ */
|
|
375
|
+function initFirefoxExtensionDetection() {
|
|
376
|
+ if (config.desktopSharingFirefoxDisabled) {
|
|
377
|
+ return;
|
|
378
|
+ }
|
|
379
|
+ if (firefoxExtInstalled === false || firefoxExtInstalled === true)
|
|
380
|
+ return;
|
|
381
|
+ if (!config.desktopSharingFirefoxExtId) {
|
|
382
|
+ firefoxExtInstalled = false;
|
|
383
|
+ return;
|
|
384
|
+ }
|
|
385
|
+
|
|
386
|
+ var img = document.createElement('img');
|
|
387
|
+ img.onload = function(){
|
|
388
|
+ console.log("Detected firefox screen sharing extension.");
|
|
389
|
+ firefoxExtInstalled = true;
|
|
390
|
+ };
|
|
391
|
+ img.onerror = function(){
|
|
392
|
+ console.log("Detected lack of firefox screen sharing extension.");
|
|
393
|
+ firefoxExtInstalled = false;
|
|
394
|
+ };
|
|
395
|
+
|
|
396
|
+ // The jidesha extension exposes an empty image file under the url:
|
|
397
|
+ // "chrome://EXT_ID/content/DOMAIN.png"
|
|
398
|
+ // Where EXT_ID is the ID of the extension with "@" replaced by ".", and
|
|
399
|
+ // DOMAIN is a domain whitelisted by the extension.
|
|
400
|
+ var src = "chrome://" +
|
|
401
|
+ (config.desktopSharingFirefoxExtId.replace('@', '.')) +
|
|
402
|
+ "/content/" + document.location.hostname + ".png";
|
|
403
|
+ img.setAttribute('src', src);
|
|
404
|
+}
|
264
|
405
|
|
265
|
406
|
module.exports = ScreenObtainer;
|