Adds support for inline installs of Jitmeet Chrome extension. Automatically hides desktop sharing button based on supported Chrome version.

This commit is contained in:
paweldomas 2014-03-17 14:00:47 +01:00
parent 452704d6b3
commit d5a1fe636d
4 changed files with 88 additions and 28 deletions

11
app.js
View File

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

View File

@ -9,6 +9,7 @@ var config = {
// useIPv6: true, // ipv6 support. use at your own risk
useNicks: 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
};

View File

@ -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,

View File

@ -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>