Merge pull request #1321 from nextcloud/fullscreen-share-firefox

Add support for sharing fullscreen on Firefox.
This commit is contained in:
Joas Schilling 2018-11-29 17:44:39 +01:00 коммит произвёл GitHub
Родитель b99ac0bd0e 19e7a5fd7b
Коммит 1113220307
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 108 добавлений и 56 удалений

131
js/app.js
Просмотреть файл

@ -256,67 +256,106 @@
return;
}
var splitShare = false;
if (window.navigator.userAgent.match('Firefox')) {
var ffver = parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1], 10);
splitShare = (ffver >= 52);
}
// The parent CSS of the menu list items is using "display:block !important",
// so we need to also hide with "!important".
if (webrtc.getLocalScreen()) {
$('#show-window-entry').attr('style','display:none !important');
$('#stop-screen-entry').show();
$('#screensharing-menu').toggleClass('open');
} else {
var screensharingButton = $(this);
screensharingButton.prop('disabled', true);
webrtc.shareScreen(function(err) {
screensharingButton.prop('disabled', false);
if (!err) {
$('#screensharing-button').attr('data-original-title', t('spreed', 'Screensharing options'))
.removeClass('screensharing-disabled icon-screen-off')
.addClass('icon-screen');
return;
}
if (splitShare) {
$('#show-window-entry').show();
$('#stop-screen-entry').attr('style','display:none !important');
$('#screensharing-menu').toggleClass('open');
return;
}
switch (err.name) {
case "HTTPS_REQUIRED":
OC.Notification.showTemporary(t('spreed', 'Screensharing requires the page to be loaded through HTTPS.'));
break;
case "PERMISSION_DENIED":
case "NotAllowedError":
case "CEF_GETSCREENMEDIA_CANCELED": // Experimental, may go away in the future.
break;
case "FF52_REQUIRED":
OC.Notification.showTemporary(t('spreed', 'Sharing your screen only works with Firefox version 52 or newer.'));
break;
case "EXTENSION_UNAVAILABLE":
var extensionURL = null;
if (!!window.chrome && !!window.chrome.webstore) {// Chrome
extensionURL = 'https://chrome.google.com/webstore/detail/screensharing-for-nextclo/kepnpjhambipllfmgmbapncekcmabkol';
}
if (extensionURL) {
var text = t('spreed', 'Screensharing extension is required to share your screen.');
var element = $('<a>').attr('href', extensionURL).attr('target','_blank').text(text);
OC.Notification.showTemporary(element, {isHTML: true});
} else {
OC.Notification.showTemporary(t('spreed', 'Please use a different browser like Firefox or Chrome to share your screen.'));
}
break;
default:
OC.Notification.showTemporary(t('spreed', 'An error occurred while starting screensharing.'));
console.log("Could not start screensharing", err);
break;
}
});
this.startShareScreen();
}
});
}.bind(this));
$("#show-screen-button").on('click', function() {
var currentUser = OCA.SpreedMe.webrtc.connection.getSessionid();
OCA.SpreedMe.sharedScreens.switchScreenToId(currentUser);
var webrtc = OCA.SpreedMe.webrtc;
if (webrtc.getLocalScreen()) {
var currentUser = OCA.SpreedMe.webrtc.connection.getSessionid();
OCA.SpreedMe.sharedScreens.switchScreenToId(currentUser);
} else {
this.startShareScreen('screen');
}
$('#screensharing-menu').toggleClass('open', false);
});
}.bind(this));
$("#show-window-button").on('click', function() {
var webrtc = OCA.SpreedMe.webrtc;
if (webrtc.getLocalScreen()) {
var currentUser = OCA.SpreedMe.webrtc.connection.getSessionid();
OCA.SpreedMe.sharedScreens.switchScreenToId(currentUser);
} else {
this.startShareScreen('window');
}
$('#screensharing-menu').toggleClass('open', false);
}.bind(this));
$("#stop-screen-button").on('click', function() {
OCA.SpreedMe.webrtc.stopScreenShare();
});
},
startShareScreen: function(mode) {
var webrtc = OCA.SpreedMe.webrtc;
var screensharingButton = $('#screensharing-button');
screensharingButton.prop('disabled', true);
webrtc.shareScreen(mode, function(err) {
screensharingButton.prop('disabled', false);
if (!err) {
$('#screensharing-button').attr('data-original-title', t('spreed', 'Screensharing options'))
.removeClass('screensharing-disabled icon-screen-off')
.addClass('icon-screen');
return;
}
switch (err.name) {
case "HTTPS_REQUIRED":
OC.Notification.showTemporary(t('spreed', 'Screensharing requires the page to be loaded through HTTPS.'));
break;
case "PERMISSION_DENIED":
case "NotAllowedError":
case "CEF_GETSCREENMEDIA_CANCELED": // Experimental, may go away in the future.
break;
case "FF52_REQUIRED":
OC.Notification.showTemporary(t('spreed', 'Sharing your screen only works with Firefox version 52 or newer.'));
break;
case "EXTENSION_UNAVAILABLE":
var extensionURL = null;
if (!!window.chrome && !!window.chrome.webstore) {// Chrome
extensionURL = 'https://chrome.google.com/webstore/detail/screensharing-for-nextclo/kepnpjhambipllfmgmbapncekcmabkol';
}
if (extensionURL) {
var text = t('spreed', 'Screensharing extension is required to share your screen.');
var element = $('<a>').attr('href', extensionURL).attr('target','_blank').text(text);
OC.Notification.showTemporary(element, {isHTML: true});
} else {
OC.Notification.showTemporary(t('spreed', 'Please use a different browser like Firefox or Chrome to share your screen.'));
}
break;
default:
OC.Notification.showTemporary(t('spreed', 'An error occurred while starting screensharing.'));
console.log("Could not start screensharing", err);
break;
}
});
},
_onKeyUp: function(event) {
// Define which objects to check for the event properties.
var key = event.which;

Просмотреть файл

@ -3874,8 +3874,8 @@
// cache for constraints and callback
var cache = {};
module.exports = function (constraints, cb) {
var hasConstraints = arguments.length === 2;
module.exports = function (mode, constraints, cb) {
var hasConstraints = arguments.length === 3;
var callback = hasConstraints ? cb : constraints;
var error;
@ -3970,10 +3970,11 @@
} else if (window.navigator.userAgent.match('Firefox')) {
var ffver = parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1], 10);
if (ffver >= 52) {
mode = mode || 'window';
constraints = (hasConstraints && constraints) || {
video: {
mozMediaSource: 'window',
mediaSource: 'window'
mozMediaSource: mode,
mediaSource: mode
}
};
getUserMedia(constraints, function (err, stream) {
@ -7607,9 +7608,9 @@
});
};
LocalMedia.prototype.startScreenShare = function (cb) {
LocalMedia.prototype.startScreenShare = function (mode, cb) {
var self = this;
getScreenMedia(function (err, stream) {
getScreenMedia(mode, function (err, stream) {
if (!err) {
self.localScreens.push(stream);
@ -18295,8 +18296,8 @@
return this.getEl(this.config.remoteVideosEl);
};
SimpleWebRTC.prototype.shareScreen = function (cb) {
this.webrtc.startScreenShare(cb);
SimpleWebRTC.prototype.shareScreen = function (mode, cb) {
this.webrtc.startScreenShare(mode, cb);
};
SimpleWebRTC.prototype.getLocalScreen = function () {

Просмотреть файл

@ -78,7 +78,13 @@ script(
<span><?php p($l->t('Show your screen'));?></span>
</button>
</li>
<li>
<li id="show-window-entry">
<button id="show-window-button">
<span class="icon-screen"></span>
<span><?php p($l->t('Show a single window'));?></span>
</button>
</li>
<li id="stop-screen-entry">
<button id="stop-screen-button">
<span class="icon-screen-off"></span>
<span><?php p($l->t('Stop screensharing'));?></span>

Просмотреть файл

@ -85,7 +85,13 @@ script(
<span><?php p($l->t('Show your screen'));?></span>
</button>
</li>
<li>
<li id="show-window-entry">
<button id="show-window-button">
<span class="icon-screen"></span>
<span><?php p($l->t('Show a single window'));?></span>
</button>
</li>
<li id="stop-screen-entry">
<button id="stop-screen-button">
<span class="icon-screen-off"></span>
<span><?php p($l->t('Stop screensharing'));?></span>