mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: standarize "screen" videoSource for Electron
parent
936d8274f8
commit
5760f4e7ef
|
@ -562,80 +562,100 @@ 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 {
|
} else {
|
||||||
|
|
||||||
if (!!this.advancedConfiguration.screenShareChromeExtension && !(platform.name!.indexOf('Firefox') !== -1) && !navigator.mediaDevices['getDisplayMedia']) {
|
if (platform.name === 'Electron') {
|
||||||
|
|
||||||
// Custom screen sharing extension for Chrome (and Opera) and no support for MediaDevices.getDisplayMedia()
|
const prefix = "screen:";
|
||||||
|
const videoSourceString: string = publisherProperties.videoSource;
|
||||||
screenSharing.getScreenConstraints((error, screenConstraints) => {
|
const electronScreenId = videoSourceString.substr(videoSourceString.lastIndexOf(prefix) + prefix.length);
|
||||||
if (!!error || !!screenConstraints.mandatory && screenConstraints.mandatory.chromeMediaSource === 'screen') {
|
(<any>mediaConstraints['video']) = {
|
||||||
if (error === 'permission-denied' || error === 'PermissionDeniedError') {
|
mandatory: {
|
||||||
const error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop');
|
chromeMediaSource: 'desktop',
|
||||||
console.error(error);
|
chromeMediaSourceId: electronScreenId
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
const extensionId = this.advancedConfiguration.screenShareChromeExtension!.split('/').pop()!!.trim();
|
|
||||||
screenSharing.getChromeExtensionStatus(extensionId, (status) => {
|
|
||||||
if (status === 'installed-disabled') {
|
|
||||||
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_DISABLED, 'You must enable the screen extension');
|
|
||||||
console.error(error);
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
if (status === 'not-installed') {
|
|
||||||
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, (<string>this.advancedConfiguration.screenShareChromeExtension));
|
|
||||||
console.error(error);
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mediaConstraints.video = screenConstraints;
|
|
||||||
resolve(mediaConstraints);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
resolve(mediaConstraints);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (navigator.mediaDevices['getDisplayMedia']) {
|
if (!!this.advancedConfiguration.screenShareChromeExtension && !(platform.name!.indexOf('Firefox') !== -1) && !navigator.mediaDevices['getDisplayMedia']) {
|
||||||
// getDisplayMedia support (Chrome >= 72, Firefox >= 52)
|
|
||||||
resolve(mediaConstraints);
|
|
||||||
} else {
|
|
||||||
// Default screen sharing extension for Chrome/Opera, or is Firefox < 66
|
|
||||||
const firefoxString = platform.name!.indexOf('Firefox') !== -1 ? publisherProperties.videoSource : undefined;
|
|
||||||
|
|
||||||
screenSharingAuto.getScreenId(firefoxString, (error, sourceId, screenConstraints) => {
|
// Custom screen sharing extension for Chrome (and Opera) and no support for MediaDevices.getDisplayMedia()
|
||||||
if (!!error) {
|
|
||||||
if (error === 'not-installed') {
|
screenSharing.getScreenConstraints((error, screenConstraints) => {
|
||||||
const extensionUrl = !!this.advancedConfiguration.screenShareChromeExtension ? this.advancedConfiguration.screenShareChromeExtension :
|
if (!!error || !!screenConstraints.mandatory && screenConstraints.mandatory.chromeMediaSource === 'screen') {
|
||||||
'https://chrome.google.com/webstore/detail/openvidu-screensharing/lfcgfepafnobdloecchnfaclibenjold';
|
if (error === 'permission-denied' || error === 'PermissionDeniedError') {
|
||||||
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, extensionUrl);
|
|
||||||
console.error(error);
|
|
||||||
reject(error);
|
|
||||||
} else if (error === 'installed-disabled') {
|
|
||||||
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_DISABLED, 'You must enable the screen extension');
|
|
||||||
console.error(error);
|
|
||||||
reject(error);
|
|
||||||
} else if (error === 'permission-denied') {
|
|
||||||
const error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop');
|
const error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop');
|
||||||
console.error(error);
|
console.error(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
|
} else {
|
||||||
|
const extensionId = this.advancedConfiguration.screenShareChromeExtension!.split('/').pop()!!.trim();
|
||||||
|
screenSharing.getChromeExtensionStatus(extensionId, (status) => {
|
||||||
|
if (status === 'installed-disabled') {
|
||||||
|
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_DISABLED, 'You must enable the screen extension');
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
if (status === 'not-installed') {
|
||||||
|
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, (<string>this.advancedConfiguration.screenShareChromeExtension));
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mediaConstraints.video = screenConstraints.video;
|
mediaConstraints.video = screenConstraints;
|
||||||
resolve(mediaConstraints);
|
resolve(mediaConstraints);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (navigator.mediaDevices['getDisplayMedia']) {
|
||||||
|
// getDisplayMedia support (Chrome >= 72, Firefox >= 52)
|
||||||
|
resolve(mediaConstraints);
|
||||||
|
} else {
|
||||||
|
// Default screen sharing extension for Chrome/Opera, or is Firefox < 66
|
||||||
|
const firefoxString = platform.name!.indexOf('Firefox') !== -1 ? publisherProperties.videoSource : undefined;
|
||||||
|
|
||||||
|
screenSharingAuto.getScreenId(firefoxString, (error, sourceId, screenConstraints) => {
|
||||||
|
if (!!error) {
|
||||||
|
if (error === 'not-installed') {
|
||||||
|
const extensionUrl = !!this.advancedConfiguration.screenShareChromeExtension ? this.advancedConfiguration.screenShareChromeExtension :
|
||||||
|
'https://chrome.google.com/webstore/detail/openvidu-screensharing/lfcgfepafnobdloecchnfaclibenjold';
|
||||||
|
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, extensionUrl);
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
} else if (error === 'installed-disabled') {
|
||||||
|
const error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_DISABLED, 'You must enable the screen extension');
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
} else if (error === 'permission-denied') {
|
||||||
|
const error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop');
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mediaConstraints.video = screenConstraints.video;
|
||||||
|
resolve(mediaConstraints);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publisherProperties.videoSource = 'screen';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publisherProperties.videoSource = 'screen';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// tslint:disable-next-line:no-string-literal
|
// tslint:disable-next-line:no-string-literal
|
||||||
|
|
|
@ -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 = () => {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue