Reduces amount of checks for desktop sharing enabled state.

This commit is contained in:
paweldomas 2014-03-26 12:32:42 +01:00
parent 384eac3807
commit 9797ad7d84
2 changed files with 36 additions and 23 deletions

8
app.js
View File

@ -942,6 +942,9 @@ $(document).ready(function () {
// Set the defaults for prompt dialogs. // Set the defaults for prompt dialogs.
jQuery.prompt.setDefaults({persistent: false}); jQuery.prompt.setDefaults({persistent: false});
// Set default desktop sharing method
setDesktopSharing(config.desktopSharing);
resizeLargeVideoContainer(); resizeLargeVideoContainer();
$(window).resize(function () { $(window).resize(function () {
resizeLargeVideoContainer(); resizeLargeVideoContainer();
@ -1221,8 +1224,9 @@ function showToolbar() {
// TODO: Enable settings functionality. Need to uncomment the settings button in index.html. // TODO: Enable settings functionality. Need to uncomment the settings button in index.html.
// $('#settingsButton').css({visibility:"visible"}); // $('#settingsButton').css({visibility:"visible"});
} }
// Set desktop sharing method
setDesktopSharing(config.desktopSharing); // Show/hide desktop sharing button
showDesktopSharingButton();
} }
/** /**

View File

@ -16,20 +16,29 @@ var switchInProgress = false;
*/ */
var obtainDesktopStream = null; var obtainDesktopStream = null;
/**
* Flag used to cache desktop sharing enabled state. Do not use directly as it can be <tt>null</tt>.
* @type {null|boolean}
*/
var _desktopSharingEnabled = null;
/** /**
* @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled. * @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
*/ */
function isDesktopSharingEnabled() { function isDesktopSharingEnabled() {
if(obtainDesktopStream === obtainScreenFromExtension) { if(_desktopSharingEnabled === null){
// Parse chrome version if(obtainDesktopStream === obtainScreenFromExtension) {
var userAgent = navigator.userAgent.toLowerCase(); // Parse chrome version
// We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set var userAgent = navigator.userAgent.toLowerCase();
var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10); // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set
console.log("Chrome version" + userAgent, ver); var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
return ver >= 35; console.log("Chrome version" + userAgent, ver);
} else { _desktopSharingEnabled = ver >= 35;
return obtainDesktopStream === obtainWebRTCScreen; } 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. * must be enabled), pass any other string or nothing in order to disable this feature completely.
*/ */
function setDesktopSharing(method) { function setDesktopSharing(method) {
if(method == "ext") { // Check if we are running chrome
if(RTC.browser === 'chrome') { if(!navigator.webkitGetUserMedia){
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 {
obtainDesktopStream = null; obtainDesktopStream = null;
console.info("Desktop sharing disabled"); 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(); showDesktopSharingButton();
} }