Browse Source

Reduces amount of checks for desktop sharing enabled state.

master
paweldomas 11 years ago
parent
commit
9797ad7d84
2 changed files with 36 additions and 23 deletions
  1. 6
    2
      app.js
  2. 30
    21
      desktopsharing.js

+ 6
- 2
app.js View File

@@ -942,6 +942,9 @@ $(document).ready(function () {
942 942
     // Set the defaults for prompt dialogs.
943 943
     jQuery.prompt.setDefaults({persistent: false});
944 944
 
945
+    // Set default desktop sharing method
946
+    setDesktopSharing(config.desktopSharing);
947
+
945 948
     resizeLargeVideoContainer();
946 949
     $(window).resize(function () {
947 950
         resizeLargeVideoContainer();
@@ -1221,8 +1224,9 @@ function showToolbar() {
1221 1224
 //        TODO: Enable settings functionality. Need to uncomment the settings button in index.html.
1222 1225
 //        $('#settingsButton').css({visibility:"visible"});
1223 1226
     }
1224
-    // Set desktop sharing method
1225
-    setDesktopSharing(config.desktopSharing);
1227
+
1228
+    // Show/hide desktop sharing button
1229
+    showDesktopSharingButton();
1226 1230
 }
1227 1231
 
1228 1232
 /**

+ 30
- 21
desktopsharing.js View File

@@ -16,20 +16,29 @@ var switchInProgress = false;
16 16
  */
17 17
 var obtainDesktopStream = null;
18 18
 
19
+/**
20
+ * Flag used to cache desktop sharing enabled state. Do not use directly as it can be <tt>null</tt>.
21
+ * @type {null|boolean}
22
+ */
23
+var _desktopSharingEnabled = null;
24
+
19 25
 /**
20 26
  * @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
21 27
  */
22 28
 function isDesktopSharingEnabled() {
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;
29
+    if(_desktopSharingEnabled === null){
30
+        if(obtainDesktopStream === obtainScreenFromExtension) {
31
+            // Parse chrome version
32
+            var userAgent = navigator.userAgent.toLowerCase();
33
+            // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set
34
+            var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
35
+            console.log("Chrome version" + userAgent, ver);
36
+            _desktopSharingEnabled = ver >= 35;
37
+        } else {
38
+            _desktopSharingEnabled = obtainDesktopStream === obtainWebRTCScreen;
39
+        }
32 40
     }
41
+    return _desktopSharingEnabled;
33 42
 }
34 43
 
35 44
 /**
@@ -39,21 +48,21 @@ function isDesktopSharingEnabled() {
39 48
  *        must be enabled), pass any other string or nothing in order to disable this feature completely.
40 49
  */
41 50
 function setDesktopSharing(method) {
42
-    if(method == "ext") {
43
-        if(RTC.browser === 'chrome') {
44
-            obtainDesktopStream = obtainScreenFromExtension;
45
-            console.info("Using Chrome extension for desktop sharing");
46
-        } else {
47
-            console.error("Chrome is required to use extension method");
48
-            obtainDesktopStream = null;
49
-        }
50
-    } else if(method == "webrtc") {
51
-        obtainDesktopStream = obtainWebRTCScreen;
52
-        console.info("Using WebRTC for desktop sharing");
53
-    } else {
51
+    // Check if we are running chrome
52
+    if(!navigator.webkitGetUserMedia){
54 53
         obtainDesktopStream = null;
55 54
         console.info("Desktop sharing disabled");
55
+    } else if(method == "ext") {
56
+        obtainDesktopStream = obtainScreenFromExtension;
57
+        console.info("Using Chrome extension for desktop sharing");
58
+    } else if(method == "webrtc") {
59
+        obtainDesktopStream = obtainWebRTCScreen;
60
+        console.info("Using Chrome WebRTC for desktop sharing");
56 61
     }
62
+
63
+    // Reset enabled cache
64
+    _desktopSharingEnabled = null;
65
+
57 66
     showDesktopSharingButton();
58 67
 }
59 68
 

Loading…
Cancel
Save