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.
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();
}
/**

View File

@ -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 <tt>null</tt>.
* @type {null|boolean}
*/
var _desktopSharingEnabled = null;
/**
* @returns {boolean} <tt>true</tt> 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();
}