Chrome no longer allows to trigger install from extension msg response callback, so we have to check if extension exists before user clicks "share desktop" button(on startup). Fixes jshint warnings.
This commit is contained in:
parent
44e558e5a0
commit
cd19c0e9e3
|
@ -19,7 +19,7 @@
|
||||||
<script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
|
<script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
|
||||||
<script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
|
<script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
|
||||||
<script src="interface_config.js?v=5"></script>
|
<script src="interface_config.js?v=5"></script>
|
||||||
<script src="libs/app.bundle.js?v=40"></script>
|
<script src="libs/app.bundle.js?v=41"></script>
|
||||||
<script src="analytics.js?v=1"></script><!-- google analytics plugin -->
|
<script src="analytics.js?v=1"></script><!-- google analytics plugin -->
|
||||||
<link rel="stylesheet" href="css/font.css?v=6"/>
|
<link rel="stylesheet" href="css/font.css?v=6"/>
|
||||||
<link rel="stylesheet" href="css/toastr.css?v=1">
|
<link rel="stylesheet" href="css/toastr.css?v=1">
|
||||||
|
|
36468
libs/app.bundle.js
36468
libs/app.bundle.js
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,13 @@
|
||||||
/* global $, alert, changeLocalVideo, chrome, config, getConferenceHandler, getUserMediaWithConstraints */
|
/* global $, alert, APP, changeLocalVideo, chrome, config, getConferenceHandler,
|
||||||
|
getUserMediaWithConstraints */
|
||||||
/**
|
/**
|
||||||
* Indicates that desktop stream is currently in use(for toggle purpose).
|
* Indicates that desktop stream is currently in use(for toggle purpose).
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
var isUsingScreenStream = false;
|
var isUsingScreenStream = false;
|
||||||
/**
|
/**
|
||||||
* Indicates that switch stream operation is in progress and prevent from triggering new events.
|
* Indicates that switch stream operation is in progress and prevent from
|
||||||
|
* triggering new events.
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
var switchInProgress = false;
|
var switchInProgress = false;
|
||||||
|
@ -18,7 +20,21 @@ 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>.
|
* Indicates whether desktop sharing extension is installed.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
var extInstalled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether update of desktop sharing extension is required.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
var extUpdateRequired = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag used to cache desktop sharing enabled state. Do not use directly as
|
||||||
|
* it can be <tt>null</tt>.
|
||||||
|
*
|
||||||
* @type {null|boolean}
|
* @type {null|boolean}
|
||||||
*/
|
*/
|
||||||
var _desktopSharingEnabled = null;
|
var _desktopSharingEnabled = null;
|
||||||
|
@ -27,7 +43,8 @@ var EventEmitter = require("events");
|
||||||
|
|
||||||
var eventEmitter = new EventEmitter();
|
var eventEmitter = new EventEmitter();
|
||||||
|
|
||||||
var DesktopSharingEventTypes = require("../../service/desktopsharing/DesktopSharingEventTypes");
|
var DesktopSharingEventTypes
|
||||||
|
= require("../../service/desktopsharing/DesktopSharingEventTypes");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method obtains desktop stream from WebRTC 'screen' source.
|
* Method obtains desktop stream from WebRTC 'screen' source.
|
||||||
|
@ -48,7 +65,8 @@ function obtainWebRTCScreen(streamCallback, failCallback) {
|
||||||
*/
|
*/
|
||||||
function getWebStoreInstallUrl()
|
function getWebStoreInstallUrl()
|
||||||
{
|
{
|
||||||
return "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId;
|
return "https://chrome.google.com/webstore/detail/" +
|
||||||
|
config.chromeExtensionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,11 +116,10 @@ function isUpdateRequired(minVersion, extVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkExtInstalled(callback) {
|
||||||
function checkExtInstalled(isInstalledCallback) {
|
|
||||||
if (!chrome.runtime) {
|
if (!chrome.runtime) {
|
||||||
// No API, so no extension for sure
|
// No API, so no extension for sure
|
||||||
isInstalledCallback(false);
|
callback(false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chrome.runtime.sendMessage(
|
chrome.runtime.sendMessage(
|
||||||
|
@ -111,26 +128,24 @@ function checkExtInstalled(isInstalledCallback) {
|
||||||
function (response) {
|
function (response) {
|
||||||
if (!response || !response.version) {
|
if (!response || !response.version) {
|
||||||
// Communication failure - assume that no endpoint exists
|
// Communication failure - assume that no endpoint exists
|
||||||
console.warn("Extension not installed?: " + chrome.runtime.lastError);
|
console.warn(
|
||||||
isInstalledCallback(false);
|
"Extension not installed?: ", chrome.runtime.lastError);
|
||||||
} else {
|
callback(false, false);
|
||||||
// Check installed extension version
|
return;
|
||||||
var extVersion = response.version;
|
|
||||||
console.log('Extension version is: ' + extVersion);
|
|
||||||
var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion);
|
|
||||||
if (updateRequired) {
|
|
||||||
alert(
|
|
||||||
'Jitsi Desktop Streamer requires update. ' +
|
|
||||||
'Changes will take effect after next Chrome restart.');
|
|
||||||
}
|
|
||||||
isInstalledCallback(!updateRequired);
|
|
||||||
}
|
}
|
||||||
|
// Check installed extension version
|
||||||
|
var extVersion = response.version;
|
||||||
|
console.log('Extension version is: ' + extVersion);
|
||||||
|
var updateRequired
|
||||||
|
= isUpdateRequired(config.minChromeExtVersion, extVersion);
|
||||||
|
callback(!updateRequired, updateRequired);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function doGetStreamFromExtension(streamCallback, failCallback) {
|
function doGetStreamFromExtension(streamCallback, failCallback) {
|
||||||
// Sends 'getStream' msg to the extension. Extension id must be defined in the config.
|
// Sends 'getStream' msg to the extension.
|
||||||
|
// Extension id must be defined in the config.
|
||||||
chrome.runtime.sendMessage(
|
chrome.runtime.sendMessage(
|
||||||
config.chromeExtensionId,
|
config.chromeExtensionId,
|
||||||
{ getStream: true, sources: config.desktopSharingSources },
|
{ getStream: true, sources: config.desktopSharingSources },
|
||||||
|
@ -156,38 +171,44 @@ function doGetStreamFromExtension(streamCallback, failCallback) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
|
* Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop'
|
||||||
|
* stream for returned stream token.
|
||||||
*/
|
*/
|
||||||
function obtainScreenFromExtension(streamCallback, failCallback) {
|
function obtainScreenFromExtension(streamCallback, failCallback) {
|
||||||
checkExtInstalled(
|
if (extInstalled) {
|
||||||
function (isInstalled) {
|
doGetStreamFromExtension(streamCallback, failCallback);
|
||||||
if (isInstalled) {
|
} else {
|
||||||
doGetStreamFromExtension(streamCallback, failCallback);
|
if (extUpdateRequired) {
|
||||||
} else {
|
alert(
|
||||||
chrome.webstore.install(
|
'Jitsi Desktop Streamer requires update. ' +
|
||||||
getWebStoreInstallUrl(),
|
'Changes will take effect after next Chrome restart.');
|
||||||
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);
|
|
||||||
APP.UI.messageHandler.showError("dialog.error",
|
|
||||||
"dialog.failtoinstall");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
chrome.webstore.install(
|
||||||
|
getWebStoreInstallUrl(),
|
||||||
|
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);
|
||||||
|
APP.UI.messageHandler.showError("dialog.error",
|
||||||
|
"dialog.failtoinstall");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this method to toggle desktop sharing feature.
|
* Call this method to toggle desktop sharing feature.
|
||||||
* @param method pass "ext" to use chrome extension for desktop capture(chrome extension required),
|
* @param method pass "ext" to use chrome extension for desktop capture(chrome
|
||||||
* pass "webrtc" to use WebRTC "screen" desktop source('chrome://flags/#enable-usermedia-screen-capture'
|
* extension required), pass "webrtc" to use WebRTC "screen" desktop
|
||||||
* must be enabled), pass any other string or nothing in order to disable this feature completely.
|
* source('chrome://flags/#enable-usermedia-screen-capture' must be
|
||||||
|
* enabled), pass any other string or nothing in order to disable this
|
||||||
|
* feature completely.
|
||||||
*/
|
*/
|
||||||
function setDesktopSharing(method) {
|
function setDesktopSharing(method) {
|
||||||
// Check if we are running chrome
|
// Check if we are running chrome
|
||||||
|
@ -207,8 +228,9 @@ function setDesktopSharing(method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes <link rel=chrome-webstore-item /> with extension id set in config.js to support inline installs.
|
* Initializes <link rel=chrome-webstore-item /> with extension id set in
|
||||||
* Host site must be selected as main website of published extension.
|
* config.js to support inline installs. Host site must be selected as main
|
||||||
|
* website of published extension.
|
||||||
*/
|
*/
|
||||||
function initInlineInstalls()
|
function initInlineInstalls()
|
||||||
{
|
{
|
||||||
|
@ -240,19 +262,22 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
isDesktopSharingEnabled: function () {
|
isDesktopSharingEnabled: function () {
|
||||||
if (_desktopSharingEnabled === null) {
|
if (_desktopSharingEnabled === null) {
|
||||||
if (obtainDesktopStream === obtainScreenFromExtension) {
|
if (obtainDesktopStream === obtainScreenFromExtension) {
|
||||||
// Parse chrome version
|
// Parse chrome version
|
||||||
var userAgent = navigator.userAgent.toLowerCase();
|
var userAgent = navigator.userAgent.toLowerCase();
|
||||||
// We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set
|
// 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);
|
var ver = parseInt(userAgent.match(/chrome\/(\d+)\./)[1], 10);
|
||||||
console.log("Chrome version" + userAgent, ver);
|
console.log("Chrome version" + userAgent, ver);
|
||||||
_desktopSharingEnabled = ver >= 34;
|
_desktopSharingEnabled = ver >= 34;
|
||||||
} else {
|
} else {
|
||||||
_desktopSharingEnabled = obtainDesktopStream === obtainWebRTCScreen;
|
_desktopSharingEnabled =
|
||||||
|
obtainDesktopStream === obtainWebRTCScreen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _desktopSharingEnabled;
|
return _desktopSharingEnabled;
|
||||||
|
@ -263,18 +288,28 @@ module.exports = {
|
||||||
|
|
||||||
// Initialize Chrome extension inline installs
|
// Initialize Chrome extension inline installs
|
||||||
if (config.chromeExtensionId) {
|
if (config.chromeExtensionId) {
|
||||||
|
|
||||||
initInlineInstalls();
|
initInlineInstalls();
|
||||||
|
|
||||||
|
// Check if extension is installed
|
||||||
|
checkExtInstalled(function (installed, updateRequired) {
|
||||||
|
extInstalled = installed;
|
||||||
|
extUpdateRequired = updateRequired;
|
||||||
|
console.info(
|
||||||
|
"Chrome extension installed: " + extInstalled +
|
||||||
|
" updateRequired: " + extUpdateRequired);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
eventEmitter.emit(DesktopSharingEventTypes.INIT);
|
eventEmitter.emit(DesktopSharingEventTypes.INIT);
|
||||||
},
|
},
|
||||||
|
|
||||||
addListener: function(listener, type)
|
addListener: function (listener, type)
|
||||||
{
|
{
|
||||||
eventEmitter.on(type, listener);
|
eventEmitter.on(type, listener);
|
||||||
},
|
},
|
||||||
|
|
||||||
removeListener: function (listener,type) {
|
removeListener: function (listener, type) {
|
||||||
eventEmitter.removeListener(type, listener);
|
eventEmitter.removeListener(type, listener);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -295,11 +330,12 @@ module.exports = {
|
||||||
function (stream) {
|
function (stream) {
|
||||||
// We now use screen stream
|
// We now use screen stream
|
||||||
isUsingScreenStream = true;
|
isUsingScreenStream = true;
|
||||||
// Hook 'ended' event to restore camera when screen stream stops
|
// Hook 'ended' event to restore camera
|
||||||
|
// when screen stream stops
|
||||||
stream.addEventListener('ended',
|
stream.addEventListener('ended',
|
||||||
function (e) {
|
function (e) {
|
||||||
if (!switchInProgress && isUsingScreenStream) {
|
if (!switchInProgress && isUsingScreenStream) {
|
||||||
toggleScreenSharing();
|
APP.desktopsharing.toggleScreenSharing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue