openvidu-browser: standarize "screen" videoSource for Electron

pull/375/head
pabloFuente 2019-05-31 12:48:14 +02:00
parent 936d8274f8
commit 5760f4e7ef
3 changed files with 80 additions and 55 deletions

View File

@ -562,12 +562,30 @@ export class OpenVidu {
if (!!publisherProperties.videoSource && typeof publisherProperties.videoSource === 'string') { if (!!publisherProperties.videoSource && typeof publisherProperties.videoSource === 'string') {
if (publisherProperties.videoSource === 'screen' || if (publisherProperties.videoSource === 'screen' ||
(platform.name!.indexOf('Firefox') !== -1 && publisherProperties.videoSource === 'window')) { (platform.name!.indexOf('Firefox') !== -1 && publisherProperties.videoSource === 'window') ||
(platform.name === 'Electron' && publisherProperties.videoSource.startsWith('screen:'))) {
if (!this.checkScreenSharingCapabilities()) { if (!this.checkScreenSharingCapabilities()) {
const error = new OpenViduError(OpenViduErrorName.SCREEN_SHARING_NOT_SUPPORTED, 'You can only screen share in desktop Chrome, Firefox or Opera. Detected browser: ' + platform.name); const error = new OpenViduError(OpenViduErrorName.SCREEN_SHARING_NOT_SUPPORTED, 'You can only screen share in desktop Chrome, Firefox or Opera. Detected browser: ' + platform.name);
console.error(error); console.error(error);
reject(error); reject(error);
} else {
if (platform.name === 'Electron') {
const prefix = "screen:";
const videoSourceString: string = publisherProperties.videoSource;
const electronScreenId = videoSourceString.substr(videoSourceString.lastIndexOf(prefix) + prefix.length);
(<any>mediaConstraints['video']) = {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: electronScreenId
}
};
resolve(mediaConstraints);
} else { } else {
if (!!this.advancedConfiguration.screenShareChromeExtension && !(platform.name!.indexOf('Firefox') !== -1) && !navigator.mediaDevices['getDisplayMedia']) { if (!!this.advancedConfiguration.screenShareChromeExtension && !(platform.name!.indexOf('Firefox') !== -1) && !navigator.mediaDevices['getDisplayMedia']) {
@ -600,6 +618,7 @@ export class OpenVidu {
resolve(mediaConstraints); resolve(mediaConstraints);
} }
}); });
} else { } else {
if (navigator.mediaDevices['getDisplayMedia']) { if (navigator.mediaDevices['getDisplayMedia']) {
@ -637,6 +656,7 @@ export class OpenVidu {
publisherProperties.videoSource = 'screen'; publisherProperties.videoSource = 'screen';
} }
}
} else { } else {
// tslint:disable-next-line:no-string-literal // tslint:disable-next-line:no-string-literal
mediaConstraints.video['deviceId'] = { exact: publisherProperties.videoSource }; mediaConstraints.video['deviceId'] = { exact: publisherProperties.videoSource };

View File

@ -618,7 +618,7 @@ export class Publisher extends StreamManager {
startTime = Date.now(); startTime = Date.now();
this.setPermissionDialogTimer(timeForDialogEvent); this.setPermissionDialogTimer(timeForDialogEvent);
if (this.stream.isSendScreen() && navigator.mediaDevices['getDisplayMedia']) { if (this.stream.isSendScreen() && navigator.mediaDevices['getDisplayMedia'] && platform.name !== 'Electron') {
navigator.mediaDevices['getDisplayMedia']({ video: true }) navigator.mediaDevices['getDisplayMedia']({ video: true })
.then(mediaStream => { .then(mediaStream => {
@ -627,6 +627,7 @@ export class Publisher extends StreamManager {
.catch(error => { .catch(error => {
getMediaError(error); getMediaError(error);
}); });
} else { } else {
let userMediaFunc = () => { let userMediaFunc = () => {

View File

@ -513,8 +513,12 @@ export class Stream implements EventDispatcher {
* @hidden * @hidden
*/ */
isSendScreen(): boolean { isSendScreen(): boolean {
return (!!this.outboundStreamOpts && let screen = this.outboundStreamOpts.publisherProperties.videoSource === 'screen';
this.outboundStreamOpts.publisherProperties.videoSource === 'screen'); if (platform.name === 'Electron') {
screen = typeof this.outboundStreamOpts.publisherProperties.videoSource === 'string' &&
this.outboundStreamOpts.publisherProperties.videoSource.startsWith('screen:');
}
return !!this.outboundStreamOpts && screen;
} }
/** /**