Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Reduces amount of checks for desktop sharing enabled state.

paweldomas9797ad7d84eb
diff --git a/app.js b/app.js
index 9ed8ff46c8..c3339ae749 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 8da4b2af9e..43e97bb0c3 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 <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();
}