From 9797ad7d84eb59a20786be37b1cb7030e50ef201 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Wed, 26 Mar 2014 12:32:42 +0100 Subject: [PATCH] Reduces amount of checks for desktop sharing enabled state. --- app.js | 8 ++++++-- desktopsharing.js | 51 ++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 9ed8ff46c..c3339ae74 100644 --- a/app.js +++ b/app.js @@ -942,6 +942,9 @@ $(document).ready(function () { // Set the defaults for prompt dialogs. jQuery.prompt.setDefaults({persistent: false}); + // Set default desktop sharing method + setDesktopSharing(config.desktopSharing); + resizeLargeVideoContainer(); $(window).resize(function () { resizeLargeVideoContainer(); @@ -1221,8 +1224,9 @@ function showToolbar() { // TODO: Enable settings functionality. Need to uncomment the settings button in index.html. // $('#settingsButton').css({visibility:"visible"}); } - // Set desktop sharing method - setDesktopSharing(config.desktopSharing); + + // Show/hide desktop sharing button + showDesktopSharingButton(); } /** diff --git a/desktopsharing.js b/desktopsharing.js index 8da4b2af9..43e97bb0c 100644 --- a/desktopsharing.js +++ b/desktopsharing.js @@ -16,20 +16,29 @@ var switchInProgress = false; */ var obtainDesktopStream = null; +/** + * Flag used to cache desktop sharing enabled state. Do not use directly as it can be null. + * @type {null|boolean} + */ +var _desktopSharingEnabled = null; + /** * @returns {boolean} true if desktop sharing feature is available and enabled. */ function isDesktopSharingEnabled() { - if(obtainDesktopStream === obtainScreenFromExtension) { - // Parse chrome version - var userAgent = navigator.userAgent.toLowerCase(); - // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set - var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10); - console.log("Chrome version" + userAgent, ver); - return ver >= 35; - } else { - return obtainDesktopStream === obtainWebRTCScreen; + if(_desktopSharingEnabled === null){ + if(obtainDesktopStream === obtainScreenFromExtension) { + // Parse chrome version + var userAgent = navigator.userAgent.toLowerCase(); + // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set + var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10); + console.log("Chrome version" + userAgent, ver); + _desktopSharingEnabled = ver >= 35; + } else { + _desktopSharingEnabled = obtainDesktopStream === obtainWebRTCScreen; + } } + return _desktopSharingEnabled; } /** @@ -39,21 +48,21 @@ function isDesktopSharingEnabled() { * must be enabled), pass any other string or nothing in order to disable this feature completely. */ function setDesktopSharing(method) { - if(method == "ext") { - if(RTC.browser === 'chrome') { - obtainDesktopStream = obtainScreenFromExtension; - console.info("Using Chrome extension for desktop sharing"); - } else { - console.error("Chrome is required to use extension method"); - obtainDesktopStream = null; - } - } else if(method == "webrtc") { - obtainDesktopStream = obtainWebRTCScreen; - console.info("Using WebRTC for desktop sharing"); - } else { + // Check if we are running chrome + if(!navigator.webkitGetUserMedia){ obtainDesktopStream = null; console.info("Desktop sharing disabled"); + } else if(method == "ext") { + obtainDesktopStream = obtainScreenFromExtension; + console.info("Using Chrome extension for desktop sharing"); + } else if(method == "webrtc") { + obtainDesktopStream = obtainWebRTCScreen; + console.info("Using Chrome WebRTC for desktop sharing"); } + + // Reset enabled cache + _desktopSharingEnabled = null; + showDesktopSharingButton(); }