Procházet zdrojové kódy

Adds support for inline installs of Jitmeet Chrome extension. Automatically hides desktop sharing button based on supported Chrome version.

j8
paweldomas před 11 roky
rodič
revize
d5a1fe636d
4 změnil soubory, kde provedl 88 přidání a 28 odebrání
  1. 2
    9
      app.js
  2. 4
    3
      config.js
  3. 77
    15
      desktopsharing.js
  4. 5
    1
      index.html

+ 2
- 9
app.js Zobrazit soubor

@@ -1245,15 +1245,8 @@ function showToolbar() {
1245 1245
 //        TODO: Enable settings functionality. Need to uncomment the settings button in index.html.
1246 1246
 //        $('#settingsButton').css({visibility:"visible"});
1247 1247
     }
1248
-    showDesktopSharingButton();
1249
-}
1250
-
1251
-function showDesktopSharingButton() {
1252
-    if(isDesktopSharingEnabled()) {
1253
-        $('#desktopsharing').css( {display:"inline"} );
1254
-    } else {
1255
-        $('#desktopsharing').css( {display:"none"} );
1256
-    }
1248
+    // Set desktop sharing method
1249
+    setDesktopSharing(config.desktopSharing);
1257 1250
 }
1258 1251
 
1259 1252
 /*

+ 4
- 3
config.js Zobrazit soubor

@@ -9,6 +9,7 @@ var config = {
9 9
 //  useIPv6: true, // ipv6 support. use at your own risk
10 10
     useNicks: false,
11 11
     bosh: '//lambada.jitsi.net/http-bind', // FIXME: use xep-0156 for that
12
-    desktopSharing: false, // Desktop sharing is disabled by default(call setDesktopSharing in the console to enable)
13
-    chromeExtensionId: 'nhkhigmiepmkogopmkfipjlfkeablnch' // Id of Jitsi Desktop Streamer chrome extension
14
-};
12
+    desktopSharing: 'ext', // Desktop sharing method. Can be set to 'ext', 'webrtc' or false to disable.
13
+    chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension
14
+    minChromeExtVersion: '0.0.8' // Required version of Chrome extension
15
+};

+ 77
- 15
desktopsharing.js Zobrazit soubor

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

+ 5
- 1
index.html Zobrazit soubor

@@ -12,6 +12,7 @@
12 12
     <script src="libs/colibri/colibri.focus.js?v=8"></script><!-- colibri focus implementation -->
13 13
     <script src="libs/colibri/colibri.session.js?v=1"></script>
14 14
     <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
15
+    <script src="config.js"></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
15 16
     <script src="muc.js?v=9"></script><!-- simple MUC library -->
16 17
     <script src="estos_log.js?v=2"></script><!-- simple stanza logger -->
17 18
     <script src="desktopsharing.js?v=1"></script><!-- desktop sharing -->
@@ -25,9 +26,12 @@
25 26
     <link rel="stylesheet" type="text/css" media="screen" href="css/main.css?v=19"/>
26 27
     <link rel="stylesheet" href="css/jquery-impromptu.css?v=4">
27 28
     <link rel="stylesheet" href="css/modaldialog.css?v=3">
29
+    <!--
30
+        Link used for inline installation of chrome desktop streaming extension,
31
+        must contain the same extension id as defined in config.js -->
32
+    <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/diibjkoicjeejcmhdnailmkgecihlobk">
28 33
     <script src="libs/jquery-impromptu.js"></script>
29 34
     <script src="libs/jquery.autosize.js"></script>
30
-    <script src="config.js"></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
31 35
     <script src="libs/prezi_player.js?v=2"></script>
32 36
   </head>
33 37
   <body>

Načítá se…
Zrušit
Uložit