'BROWSER_NOT_SUPPORTED' and 'SCREEN_SHARING_NOT_SUPPORTED' errors

pull/39/head
pabloFuente 2018-03-15 12:43:30 +01:00
parent e043eca95d
commit 644b22fe37
6 changed files with 1267 additions and 162 deletions

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ import { LocalRecorder } from '../OpenViduInternal/LocalRecorder';
import * as adapter from 'webrtc-adapter';
import * as screenSharing from '../ScreenSharing/Screen-Capturing.js';
import * as screenSharingAuto from '../ScreenSharing/Screen-Capturing-Auto.js';
import * as DetectRTC from '../KurentoUtils/DetectRTC';
if (window) {
window["adapter"] = adapter;
@ -43,14 +44,10 @@ export class OpenVidu {
initSession(sessionId: string): Session;
initSession(param1, param2?): any {
if (this.checkSystemRequirements()) {
if (typeof param2 == "string") {
return new Session(this.openVidu.initSession(param2), this);
} else {
return new Session(this.openVidu.initSession(param1), this);
}
if (typeof param2 == "string") {
return new Session(this.openVidu.initSession(param2), this);
} else {
alert("Browser not supported");
return new Session(this.openVidu.initSession(param1), this);
}
}
@ -59,139 +56,139 @@ export class OpenVidu {
initPublisher(parentId: string, cameraOptions: any, callback: any): Publisher;
initPublisher(parentId: string, cameraOptions?: any, callback?: Function): any {
if (this.checkSystemRequirements()) {
let publisher: Publisher;
if (cameraOptions != null) {
cameraOptions.audio = cameraOptions.audio != null ? cameraOptions.audio : true;
cameraOptions.video = cameraOptions.video != null ? cameraOptions.video : true;
let publisher: Publisher;
if (cameraOptions != null) {
if (!cameraOptions.screen) {
cameraOptions.audio = cameraOptions.audio != null ? cameraOptions.audio : true;
cameraOptions.video = cameraOptions.video != null ? cameraOptions.video : true;
// Webcam and/or microphone is being requested
if (!cameraOptions.screen) {
let cameraOptionsAux = {
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true,
activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true,
dataChannel: true,
mediaConstraints: this.openVidu.generateMediaConstraints(cameraOptions)
};
cameraOptions = cameraOptionsAux;
// Webcam and/or microphone is being requested
publisher = new Publisher(this.openVidu.initPublisherTagged(parentId, cameraOptions, true, callback), parentId, false);
console.info("'Publisher' initialized");
return publisher;
} else {
publisher = new Publisher(this.openVidu.initPublisherScreen(parentId, true, callback), parentId, true);
if (adapter.browserDetails.browser === 'firefox' && adapter.browserDetails.version >= 52) {
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
cameraOptions = {
sendAudio: cameraOptions.audio,
sendVideo: cameraOptions.video,
activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true,
activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true,
dataChannel: true,
mediaConstraints: {
video: screenConstraints.video,
audio: false
}
}
publisher.stream.configureScreenOptions(cameraOptions);
console.info("'Publisher' initialized");
publisher.stream.ee.emitEvent('can-request-screen');
});
return publisher;
} else if (adapter.browserDetails.browser === 'chrome') {
// Screen is being requested
/*screenSharing.isChromeExtensionAvailable((availability) => {
switch (availability) {
case 'available':
console.warn('EXTENSION AVAILABLE!!!');
screenSharing.getScreenConstraints((error, screenConstraints) => {
if (!error) {
console.warn(screenConstraints);
}
});
break;
case 'unavailable':
console.warn('EXTENSION NOT AVAILABLE!!!');
break;
case 'isFirefox':
console.warn('IT IS FIREFOX!!!');
screenSharing.getScreenConstraints((error, screenConstraints) => {
if (!error) {
console.warn(screenConstraints);
}
});
break;
}
});*/
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
if (error === 'not-installed') {
let error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, 'https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk');
console.error(error);
if (callback) callback(error);
return;
} else if (error === 'permission-denied') {
let error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop');
console.error(error);
if (callback) callback(error);
return;
}
cameraOptions = {
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true,
activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true,
dataChannel: true,
mediaConstraints: {
video: screenConstraints.video,
audio: false
}
}
publisher.stream.configureScreenOptions(cameraOptions);
publisher.stream.ee.emitEvent('can-request-screen');
}, (error) => {
console.error('getScreenId error', error);
return;
});
console.info("'Publisher' initialized");
return publisher;
} else {
console.error('Screen sharing not supported on ' + adapter.browserDetails.browser);
}
}
} else {
cameraOptions = {
sendAudio: true,
sendVideo: true,
activeAudio: true,
activeVideo: true,
let cameraOptionsAux = {
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true,
activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true,
dataChannel: true,
mediaConstraints: {
audio: true,
video: { width: { ideal: 1280 } }
}
}
mediaConstraints: this.openVidu.generateMediaConstraints(cameraOptions)
};
cameraOptions = cameraOptionsAux;
publisher = new Publisher(this.openVidu.initPublisherTagged(parentId, cameraOptions, true, callback), parentId, false);
console.info("'Publisher' initialized");
return publisher;
} else {
// Screen share is being requested
publisher = new Publisher(this.openVidu.initPublisherScreen(parentId, true, callback), parentId, true);
if (DetectRTC.browser.name === 'Firefox' && DetectRTC.browser.version >= 52) {
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
cameraOptions = {
sendAudio: cameraOptions.audio,
sendVideo: cameraOptions.video,
activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true,
activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true,
dataChannel: true,
mediaConstraints: {
video: screenConstraints.video,
audio: false
}
}
publisher.stream.configureScreenOptions(cameraOptions);
console.info("'Publisher' initialized");
publisher.stream.ee.emitEvent('can-request-screen');
});
return publisher;
} else if (DetectRTC.browser.name === 'Chrome') {
// Screen is being requested
/*screenSharing.isChromeExtensionAvailable((availability) => {
switch (availability) {
case 'available':
console.warn('EXTENSION AVAILABLE!!!');
screenSharing.getScreenConstraints((error, screenConstraints) => {
if (!error) {
console.warn(screenConstraints);
}
});
break;
case 'unavailable':
console.warn('EXTENSION NOT AVAILABLE!!!');
break;
case 'isFirefox':
console.warn('IT IS FIREFOX!!!');
screenSharing.getScreenConstraints((error, screenConstraints) => {
if (!error) {
console.warn(screenConstraints);
}
});
break;
}
});*/
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
if (error === 'not-installed') {
let error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, 'https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk');
console.error(error);
if (callback) callback(error);
return;
} else if (error === 'permission-denied') {
let error = new OpenViduError(OpenViduErrorName.SCREEN_CAPTURE_DENIED, 'You must allow access to one window of your desktop');
console.error(error);
if (callback) callback(error);
return;
}
cameraOptions = {
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
activeAudio: cameraOptions.audioActive != null ? cameraOptions.audioActive : true,
activeVideo: cameraOptions.videoActive != null ? cameraOptions.videoActive : true,
dataChannel: true,
mediaConstraints: {
video: screenConstraints.video,
audio: false
}
}
publisher.stream.configureScreenOptions(cameraOptions);
publisher.stream.ee.emitEvent('can-request-screen');
}, (error) => {
console.error('getScreenId error', error);
return;
});
console.info("'Publisher' initialized");
return publisher;
} else {
console.error('Screen sharing not supported on ' + DetectRTC.browser.name);
if (!!callback) callback(new OpenViduError(OpenViduErrorName.SCREEN_SHARING_NOT_SUPPORTED, 'Screen sharing not supported on ' + DetectRTC.browser.name + ' ' + DetectRTC.browser.version));
}
}
} else {
alert("Browser not supported");
cameraOptions = {
sendAudio: true,
sendVideo: true,
activeAudio: true,
activeVideo: true,
dataChannel: true,
mediaConstraints: {
audio: true,
video: { width: { ideal: 1280 } }
}
}
publisher = new Publisher(this.openVidu.initPublisherTagged(parentId, cameraOptions, true, callback), parentId, false);
console.info("'Publisher' initialized");
return publisher;
}
}
@ -202,7 +199,7 @@ export class OpenVidu {
return publisher;
} else {
publisher = new Publisher(this.openVidu.initPublisherScreen(publisher.stream.getParentId(), false), publisher.stream.getParentId(), true);
if (adapter.browserDetails.browser === 'firefox' && adapter.browserDetails.version >= 52) {
if (DetectRTC.browser.name === 'Firefox' && DetectRTC.browser.version >= 52) {
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
publisher.stream.outboundOptions.mediaConstraints.video = screenConstraints.video;
@ -212,7 +209,7 @@ export class OpenVidu {
publisher.stream.ee.emitEvent('can-request-screen');
});
return publisher;
} else if (adapter.browserDetails.browser === 'chrome') {
} else if (DetectRTC.browser.name === 'Chrome') {
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
if (error === 'not-installed') {
let error = new OpenViduError(OpenViduErrorName.SCREEN_EXTENSION_NOT_INSTALLED, 'https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk');
@ -234,23 +231,21 @@ export class OpenVidu {
console.info("'Publisher' initialized");
return publisher;
} else {
console.error('Screen sharing not supported on ' + adapter.browserDetails.browser);
console.error('Screen sharing not supported on ' + DetectRTC.browser.name);
}
}
}
checkSystemRequirements(): number {
let browser = adapter.browserDetails.browser;
let version = adapter.browserDetails.version;
//Bug fix: 'navigator.userAgent' in Firefox for Ubuntu 14.04 does not return "Firefox/[version]" in the string, so version returned is null
if ((browser == 'firefox') && (version == null)) {
return 1;
}
if (((browser == 'chrome') && (version >= 28)) || ((browser == 'edge') && (version >= 12)) || ((browser == 'firefox') && (version >= 22))) {
return 1;
} else {
let defaultWebRTCSupport: boolean = DetectRTC.isWebRTCSupported;
let browser = DetectRTC.browser.name;
let version = DetectRTC.browser.version;
if ((browser !== 'Chrome') && (browser !== 'Firefox') && (browser !== 'Opera')) {
return 0;
} else {
return defaultWebRTCSupport ? 1 : 0;
}
}

View File

@ -1,12 +1,14 @@
import { SessionInternal, SessionOptions, SignalOptions } from '../OpenViduInternal/SessionInternal';
import { Stream } from '../OpenViduInternal/Stream';
import { Connection } from "../OpenViduInternal/Connection";
import { Connection } from '../OpenViduInternal/Connection';
import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/OpenViduError';
import { OpenVidu } from './OpenVidu';
import { Publisher } from './Publisher';
import { Subscriber } from './Subscriber';
import EventEmitter = require('wolfy87-eventemitter');
import * as DetectRTC from '../KurentoUtils/DetectRTC';
export class Session {
@ -48,21 +50,29 @@ export class Session {
connect(param1, param2, param3?) {
// Early configuration to deactivate automatic subscription to streams
if (param3) {
this.session.configure({
sessionId: this.session.getSessionId(),
participantId: param1,
metadata: this.session.stringClientMetadata(param2),
subscribeToStreams: false
});
this.session.connect(param1, param3);
if (this.openVidu.checkSystemRequirements()) {
this.session.configure({
sessionId: this.session.getSessionId(),
participantId: param1,
metadata: this.session.stringClientMetadata(param2),
subscribeToStreams: false
});
this.session.connect(param1, param3);
} else {
param3(new OpenViduError(OpenViduErrorName.BROWSER_NOT_SUPPORTED, 'Browser ' + DetectRTC.browser.name + ' ' + DetectRTC.browser.version + ' is not supported in OpenVidu'));
}
} else {
this.session.configure({
sessionId: this.session.getSessionId(),
participantId: param1,
metadata: '',
subscribeToStreams: false
});
this.session.connect(param1, param2);
if (this.openVidu.checkSystemRequirements()) {
this.session.configure({
sessionId: this.session.getSessionId(),
participantId: param1,
metadata: '',
subscribeToStreams: false
});
this.session.connect(param1, param2);
} else {
param2(new OpenViduError(OpenViduErrorName.BROWSER_NOT_SUPPORTED, 'Browser ' + DetectRTC.browser.name + ' ' + DetectRTC.browser.version + ' is not supported in OpenVidu'));
}
}
}

View File

@ -1,9 +1,11 @@
export const enum OpenViduErrorName {
BROWSER_NOT_SUPPORTED = 'BROWSER_NOT_SUPPORTED',
CAMERA_ACCESS_DENIED = 'CAMERA_ACCESS_DENIED',
MICROPHONE_ACCESS_DENIED = 'MICROPHONE_ACCESS_DENIED',
SCREEN_CAPTURE_DENIED = 'SCREEN_CAPTURE_DENIED',
NO_VIDEO_DEVICE = 'NO_VIDEO_DEVICE',
NO_INPUT_DEVICE = 'NO_INPUT_DEVICE',
SCREEN_SHARING_NOT_SUPPORTED = 'SCREEN_SHARING_NOT_SUPPORTED',
SCREEN_EXTENSION_NOT_INSTALLED = 'SCREEN_EXTENSION_NOT_INSTALLED',
GENERIC_ERROR = 'GENERIC_ERROR'
}

View File

@ -278,7 +278,7 @@ export class Stream {
if (this.local && !this.displayMyRemote()) {
this.video.muted = true;
this.video.onplaying = () => {
this.video.oncanplay = () => {
console.info("Local 'Stream' with id [" + this.streamId + "] video is now playing");
this.ee.emitEvent('video-is-playing', [{
element: this.video
@ -609,7 +609,7 @@ export class Stream {
if (!!this.video) {
// let thumbnailId = this.video.thumb;
this.video.onplaying = () => {
this.video.oncanplay = () => {
if (this.local && this.displayMyRemote()) {
console.info("Your own remote 'Stream' with id [" + this.streamId + "] video is now playing");
this.ee.emitEvent('remote-video-is-playing', [{

View File

@ -1,5 +1,6 @@
import { Stream } from './Stream';
import * as adapter from 'webrtc-adapter';
import * as DetectRTC from '../KurentoUtils/DetectRTC';
export class WebRtcStats {
@ -93,7 +94,7 @@ export class WebRtcStats {
let f = (stats) => {
if (adapter.browserDetails.browser === 'firefox') {
if (DetectRTC.browser.name === 'Firefox') {
stats.forEach((stat) => {
let json = {};
@ -190,7 +191,7 @@ export class WebRtcStats {
sendPost(JSON.stringify(json));
}
});
} else if (adapter.browserDetails.browser === 'chrome') {
} else if (DetectRTC.browser.name === 'Chrome') {
for (let key of Object.keys(stats)) {
let stat = stats[key];
if (stat.type === 'ssrc') {
@ -286,7 +287,7 @@ export class WebRtcStats {
}
private standardizeReport(response) {
if (adapter.browserDetails.browser === 'firefox') {
if (DetectRTC.browser.name === 'Firefox') {
return response;
}
@ -307,13 +308,13 @@ export class WebRtcStats {
}
private getStatsAgnostic(pc, selector, successCb, failureCb) {
if (adapter.browserDetails.browser === 'firefox') {
if (DetectRTC.browser.name === 'Firefox') {
// getStats takes args in different order in Chrome and Firefox
return pc.getStats(selector, (response) => {
var report = this.standardizeReport(response);
successCb(report);
}, failureCb);
} else if (adapter.browserDetails.browser === 'chrome') {
} else if (DetectRTC.browser.name === 'Chrome') {
// In Chrome, the first two arguments are reversed
return pc.getStats((response) => {
var report = this.standardizeReport(response);