|
@@ -14,18 +14,22 @@ var switchInProgress = false;
|
14
|
14
|
*
|
15
|
15
|
* @type {function(stream_callback, failure_callback}
|
16
|
16
|
*/
|
17
|
|
-var obtainDesktopStream = obtainScreenFromExtension;
|
18
|
|
-
|
19
|
|
-/**
|
20
|
|
- * Desktop sharing must be enabled in config and works on chrome only.
|
21
|
|
- */
|
22
|
|
-var desktopSharingEnabled = config.desktopSharing;
|
|
17
|
+var obtainDesktopStream = null;
|
23
|
18
|
|
24
|
19
|
/**
|
25
|
20
|
* @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
|
26
|
21
|
*/
|
27
|
22
|
function isDesktopSharingEnabled() {
|
28
|
|
- return desktopSharingEnabled;
|
|
23
|
+ if(obtainDesktopStream === obtainScreenFromExtension) {
|
|
24
|
+ // Parse chrome version
|
|
25
|
+ var userAgent = navigator.userAgent.toLowerCase();
|
|
26
|
+ // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set
|
|
27
|
+ var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
|
|
28
|
+ console.log("Chrome version" + userAgent, ver);
|
|
29
|
+ return ver >= 35;
|
|
30
|
+ } else {
|
|
31
|
+ return obtainDesktopStream === obtainWebRTCScreen;
|
|
32
|
+ }
|
29
|
33
|
}
|
30
|
34
|
|
31
|
35
|
/**
|
|
@@ -36,18 +40,28 @@ function isDesktopSharingEnabled() {
|
36
|
40
|
*/
|
37
|
41
|
function setDesktopSharing(method) {
|
38
|
42
|
if(method == "ext") {
|
39
|
|
- obtainDesktopStream = obtainScreenFromExtension;
|
40
|
|
- desktopSharingEnabled = true;
|
|
43
|
+ if(RTC.browser === 'chrome') {
|
|
44
|
+ obtainDesktopStream = obtainScreenFromExtension;
|
|
45
|
+ } else {
|
|
46
|
+ console.log("Chrome is required to use extension method");
|
|
47
|
+ obtainDesktopStream = null;
|
|
48
|
+ }
|
41
|
49
|
} else if(method == "webrtc") {
|
42
|
50
|
obtainDesktopStream = obtainWebRTCScreen;
|
43
|
|
- desktopSharingEnabled = true;
|
44
|
51
|
} else {
|
45
|
52
|
obtainDesktopStream = null;
|
46
|
|
- desktopSharingEnabled = false;
|
47
|
53
|
}
|
48
|
54
|
showDesktopSharingButton();
|
49
|
55
|
}
|
50
|
56
|
|
|
57
|
+function showDesktopSharingButton() {
|
|
58
|
+ if(isDesktopSharingEnabled()) {
|
|
59
|
+ $('#desktopsharing').css( {display:"inline"} );
|
|
60
|
+ } else {
|
|
61
|
+ $('#desktopsharing').css( {display:"none"} );
|
|
62
|
+ }
|
|
63
|
+}
|
|
64
|
+
|
51
|
65
|
/*
|
52
|
66
|
* Toggles screen sharing.
|
53
|
67
|
*/
|
|
@@ -129,11 +143,59 @@ function obtainWebRTCScreen(streamCallback, failCallback) {
|
129
|
143
|
* Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
|
130
|
144
|
*/
|
131
|
145
|
function obtainScreenFromExtension(streamCallback, failCallback) {
|
132
|
|
- // Check for extension API
|
133
|
|
- if(!chrome || !chrome.runtime) {
|
134
|
|
- failCallback("Failed to communicate with extension - no API available");
|
135
|
|
- return;
|
|
146
|
+ checkExtInstalled(
|
|
147
|
+ function(isInstalled) {
|
|
148
|
+ if(isInstalled) {
|
|
149
|
+ doGetStreamFromExtension(streamCallback, failCallback);
|
|
150
|
+ } else {
|
|
151
|
+ chrome.webstore.install(
|
|
152
|
+ "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId,
|
|
153
|
+ function(arg) {
|
|
154
|
+ console.log("Extension installed successfully", arg);
|
|
155
|
+ // We need to reload the page in order to get the access to chrome.runtime
|
|
156
|
+ window.location.reload(false);
|
|
157
|
+ },
|
|
158
|
+ function(arg) {
|
|
159
|
+ console.log("Failed to install the extension", arg);
|
|
160
|
+ failCallback(arg);
|
|
161
|
+ }
|
|
162
|
+ );
|
|
163
|
+ }
|
|
164
|
+ }
|
|
165
|
+ );
|
|
166
|
+}
|
|
167
|
+
|
|
168
|
+function checkExtInstalled(isInstalledCallback) {
|
|
169
|
+ if(!chrome.runtime) {
|
|
170
|
+ // No API, so no extension for sure
|
|
171
|
+ isInstalledCallback(false);
|
|
172
|
+ return false;
|
136
|
173
|
}
|
|
174
|
+ chrome.runtime.sendMessage(
|
|
175
|
+ config.chromeExtensionId,
|
|
176
|
+ { getVersion: true },
|
|
177
|
+ function(response){
|
|
178
|
+ if(!response || !response.version) {
|
|
179
|
+ // Communication failure - assume that no endpoint exists
|
|
180
|
+ console.warn("Extension not installed?: "+chrome.runtime.lastError);
|
|
181
|
+ isInstalledCallback(false);
|
|
182
|
+ } else {
|
|
183
|
+ // Check installed extension version
|
|
184
|
+ var extVersion = response.version;
|
|
185
|
+ console.log('Extension version is: '+extVersion);
|
|
186
|
+ var updateRequired = extVersion < config.minChromeExtVersion;
|
|
187
|
+ if(updateRequired) {
|
|
188
|
+ alert(
|
|
189
|
+ 'Jitsi Desktop Streamer requires update. ' +
|
|
190
|
+ 'Changes will take effect after next Chrome restart.' );
|
|
191
|
+ }
|
|
192
|
+ isInstalledCallback(!updateRequired);
|
|
193
|
+ }
|
|
194
|
+ }
|
|
195
|
+ );
|
|
196
|
+}
|
|
197
|
+
|
|
198
|
+function doGetStreamFromExtension(streamCallback, failCallback) {
|
137
|
199
|
// Sends 'getStream' msg to the extension. Extension id must be defined in the config.
|
138
|
200
|
chrome.runtime.sendMessage(
|
139
|
201
|
config.chromeExtensionId,
|