Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Adds support for inline installs of Jitmeet Chrome extension. Automatically hides desktop sharing button based on supported Chrome version.
paweldomasd5a1fe636d36
diff --git a/app.js b/app.jsindex 678126688a..d6d4b8b449 100644--- a/app.js+++ b/app.js@@ -1245,15 +1245,8 @@ function showToolbar() {// TODO: Enable settings functionality. Need to uncomment the settings button in index.html.// $('#settingsButton').css({visibility:"visible"});}- showDesktopSharingButton();-}--function showDesktopSharingButton() {- if(isDesktopSharingEnabled()) {- $('#desktopsharing').css( {display:"inline"} );- } else {- $('#desktopsharing').css( {display:"none"} );- }+ // Set desktop sharing method+ setDesktopSharing(config.desktopSharing);}/*diff --git a/config.js b/config.jsindex 9b53c28724..a05b7b216a 100644--- a/config.js+++ b/config.js@@ -9,6 +9,7 @@ var config = {// useIPv6: true, // ipv6 support. use at your own riskuseNicks: false,bosh: '//lambada.jitsi.net/http-bind', // FIXME: use xep-0156 for that- desktopSharing: false, // Desktop sharing is disabled by default(call setDesktopSharing in the console to enable)- chromeExtensionId: 'nhkhigmiepmkogopmkfipjlfkeablnch' // Id of Jitsi Desktop Streamer chrome extension-};+ desktopSharing: 'ext', // Desktop sharing method. Can be set to 'ext', 'webrtc' or false to disable.+ chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension+ minChromeExtVersion: '0.0.8' // Required version of Chrome extension+};\ No newline at end of filediff --git a/desktopsharing.js b/desktopsharing.jsindex 1918a64267..a6bed61146 100644--- a/desktopsharing.js+++ b/desktopsharing.js@@ -14,18 +14,22 @@ var switchInProgress = false;** @type {function(stream_callback, failure_callback}*/-var obtainDesktopStream = obtainScreenFromExtension;--/**- * Desktop sharing must be enabled in config and works on chrome only.- */-var desktopSharingEnabled = config.desktopSharing;+var obtainDesktopStream = null;/*** @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.*/function isDesktopSharingEnabled() {- return desktopSharingEnabled;+ 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;+ }}/**@@ -36,18 +40,28 @@ function isDesktopSharingEnabled() {*/function setDesktopSharing(method) {if(method == "ext") {- obtainDesktopStream = obtainScreenFromExtension;- desktopSharingEnabled = true;+ if(RTC.browser === 'chrome') {+ obtainDesktopStream = obtainScreenFromExtension;+ } else {+ console.log("Chrome is required to use extension method");+ obtainDesktopStream = null;+ }} else if(method == "webrtc") {obtainDesktopStream = obtainWebRTCScreen;- desktopSharingEnabled = true;} else {obtainDesktopStream = null;- desktopSharingEnabled = false;}showDesktopSharingButton();}+function showDesktopSharingButton() {+ if(isDesktopSharingEnabled()) {+ $('#desktopsharing').css( {display:"inline"} );+ } else {+ $('#desktopsharing').css( {display:"none"} );+ }+}+/** Toggles screen sharing.*/@@ -129,11 +143,59 @@ function obtainWebRTCScreen(streamCallback, failCallback) {* Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.*/function obtainScreenFromExtension(streamCallback, failCallback) {- // Check for extension API- if(!chrome || !chrome.runtime) {- failCallback("Failed to communicate with extension - no API available");- return;+ checkExtInstalled(+ function(isInstalled) {+ if(isInstalled) {+ doGetStreamFromExtension(streamCallback, failCallback);+ } else {+ chrome.webstore.install(+ "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId,+ function(arg) {+ console.log("Extension installed successfully", arg);+ // We need to reload the page in order to get the access to chrome.runtime+ window.location.reload(false);+ },+ function(arg) {+ console.log("Failed to install the extension", arg);+ failCallback(arg);+ }+ );+ }+ }+ );+}++function checkExtInstalled(isInstalledCallback) {+ if(!chrome.runtime) {+ // No API, so no extension for sure+ isInstalledCallback(false);+ return false;}+ chrome.runtime.sendMessage(+ config.chromeExtensionId,+ { getVersion: true },+ function(response){+ if(!response || !response.version) {+ // Communication failure - assume that no endpoint exists+ console.warn("Extension not installed?: "+chrome.runtime.lastError);+ isInstalledCallback(false);+ } else {+ // Check installed extension version+ var extVersion = response.version;+ console.log('Extension version is: '+extVersion);+ var updateRequired = extVersion < config.minChromeExtVersion;+ if(updateRequired) {+ alert(+ 'Jitsi Desktop Streamer requires update. ' ++ 'Changes will take effect after next Chrome restart.' );+ }+ isInstalledCallback(!updateRequired);+ }+ }+ );+}++function doGetStreamFromExtension(streamCallback, failCallback) {// Sends 'getStream' msg to the extension. Extension id must be defined in the config.chrome.runtime.sendMessage(config.chromeExtensionId,diff --git a/index.html b/index.htmlindex 7848594885..15be85df5c 100644--- a/index.html+++ b/index.html@@ -12,6 +12,7 @@<script src="libs/colibri/colibri.focus.js?v=8"></script><!-- colibri focus implementation --><script src="libs/colibri/colibri.session.js?v=1"></script><script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>+ <script src="config.js"></script><!-- adapt to your needs, i.e. set hosts and bosh path --><script src="muc.js?v=9"></script><!-- simple MUC library --><script src="estos_log.js?v=2"></script><!-- simple stanza logger --><script src="desktopsharing.js?v=1"></script><!-- desktop sharing -->@@ -25,9 +26,12 @@<link rel="stylesheet" type="text/css" media="screen" href="css/main.css?v=19"/><link rel="stylesheet" href="css/jquery-impromptu.css?v=4"><link rel="stylesheet" href="css/modaldialog.css?v=3">+ <!--+ Link used for inline installation of chrome desktop streaming extension,+ must contain the same extension id as defined in config.js -->+ <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/diibjkoicjeejcmhdnailmkgecihlobk"><script src="libs/jquery-impromptu.js"></script><script src="libs/jquery.autosize.js"></script>- <script src="config.js"></script><!-- adapt to your needs, i.e. set hosts and bosh path --><script src="libs/prezi_player.js?v=2"></script></head><body>