2016-10-15 00:11:17 +02:00
|
|
|
/*
|
2017-09-19 11:51:02 +02:00
|
|
|
* (C) Copyright 2017 OpenVidu (http://openvidu.io/)
|
2016-10-15 00:11:17 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
2017-05-10 10:55:31 +02:00
|
|
|
import { OpenViduInternal } from '../OpenViduInternal/OpenViduInternal';
|
2016-10-15 00:11:17 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
import { Session } from './Session';
|
|
|
|
import { Publisher } from './Publisher';
|
2017-10-04 10:30:15 +02:00
|
|
|
import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/OpenViduError';
|
2016-10-15 00:11:17 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
import * as adapter from 'webrtc-adapter';
|
2017-10-03 15:02:36 +02:00
|
|
|
import * as screenSharing from '../ScreenSharing/Screen-Capturing.js';
|
|
|
|
import * as screenSharingAuto from '../ScreenSharing/Screen-Capturing-Auto.js';
|
2017-03-28 20:17:44 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
if (window) {
|
|
|
|
window["adapter"] = adapter;
|
|
|
|
}
|
2017-03-28 20:17:44 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
export class OpenVidu {
|
2017-03-28 20:17:44 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
openVidu: OpenViduInternal;
|
2017-03-28 20:17:44 +02:00
|
|
|
|
2017-07-12 18:56:13 +02:00
|
|
|
constructor() {
|
|
|
|
this.openVidu = new OpenViduInternal();
|
2017-09-22 15:57:59 +02:00
|
|
|
console.info("'OpenVidu' initialized");
|
2017-07-12 18:56:13 +02:00
|
|
|
};
|
2017-03-28 20:17:44 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
initSession(apiKey: string, sessionId: string): Session;
|
|
|
|
initSession(sessionId: string): Session;
|
2017-03-28 20:17:44 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
initSession(param1, param2?): any {
|
2017-07-12 18:56:13 +02:00
|
|
|
if (this.checkSystemRequirements()) {
|
2017-05-10 10:55:31 +02:00
|
|
|
if (typeof param2 == "string") {
|
|
|
|
return new Session(this.openVidu.initSession(param2), this);
|
|
|
|
} else {
|
|
|
|
return new Session(this.openVidu.initSession(param1), this);
|
|
|
|
}
|
2017-04-12 00:54:35 +02:00
|
|
|
} else {
|
2017-05-10 10:55:31 +02:00
|
|
|
alert("Browser not supported");
|
2017-04-12 00:54:35 +02:00
|
|
|
}
|
2017-03-28 20:17:44 +02:00
|
|
|
}
|
|
|
|
|
2017-05-19 16:04:56 +02:00
|
|
|
initPublisher(parentId: string): Publisher;
|
2017-05-10 10:55:31 +02:00
|
|
|
initPublisher(parentId: string, cameraOptions: any): Publisher;
|
|
|
|
initPublisher(parentId: string, cameraOptions: any, callback: any): Publisher;
|
2016-10-15 00:11:17 +02:00
|
|
|
|
2017-05-19 16:04:56 +02:00
|
|
|
initPublisher(parentId: string, cameraOptions?: any, callback?: Function): any {
|
|
|
|
if (this.checkSystemRequirements()) {
|
2017-10-03 15:02:36 +02:00
|
|
|
let publisher: Publisher;
|
2017-07-12 18:56:13 +02:00
|
|
|
if (cameraOptions != null) {
|
2017-10-03 15:02:36 +02:00
|
|
|
if (!cameraOptions.screen) {
|
|
|
|
// Webcam and/or microphone is being requested
|
|
|
|
|
|
|
|
let cameraOptionsAux = {
|
|
|
|
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
|
|
|
|
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
|
|
|
|
activeAudio: cameraOptions.activeAudio != null ? cameraOptions.activeAudio : true,
|
|
|
|
activeVideo: cameraOptions.activeVideo != null ? cameraOptions.activeVideo : true,
|
|
|
|
data: true,
|
|
|
|
mediaConstraints: this.openVidu.generateMediaConstraints(cameraOptions)
|
|
|
|
};
|
|
|
|
cameraOptions = cameraOptionsAux;
|
|
|
|
publisher = new Publisher(this.openVidu.initPublisherTagged(parentId, cameraOptions, callback), parentId, false);
|
|
|
|
console.info("'Publisher' initialized");
|
|
|
|
return publisher;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (adapter.browserDetails.browser === 'firefox' && adapter.browserDetails.version >= 52) {
|
2017-10-04 10:30:15 +02:00
|
|
|
publisher = new Publisher(this.openVidu.initPublisherScreen(parentId, callback), parentId, true);
|
2017-10-03 15:02:36 +02:00
|
|
|
screenSharingAuto.getScreenId((error, sourceId, screenConstraints) => {
|
|
|
|
cameraOptions = {
|
|
|
|
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
|
|
|
|
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
|
|
|
|
activeAudio: cameraOptions.activeAudio != null ? cameraOptions.activeAudio : true,
|
|
|
|
activeVideo: cameraOptions.activeVideo != null ? cameraOptions.activeVideo : true,
|
|
|
|
data: true,
|
|
|
|
mediaConstraints: {
|
|
|
|
video: screenConstraints.video,
|
|
|
|
audio: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
publisher.stream.configureScreenOptions(cameraOptions);
|
|
|
|
console.info("'Publisher' initialized");
|
|
|
|
});
|
|
|
|
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') {
|
2017-10-04 10:30:15 +02:00
|
|
|
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);
|
2017-10-03 15:02:36 +02:00
|
|
|
return;
|
|
|
|
} else if (error === 'permission-denied') {
|
2017-10-04 10:30:15 +02:00
|
|
|
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);
|
2017-10-03 15:02:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cameraOptions = {
|
|
|
|
sendAudio: cameraOptions.audio != null ? cameraOptions.audio : true,
|
|
|
|
sendVideo: cameraOptions.video != null ? cameraOptions.video : true,
|
|
|
|
activeAudio: cameraOptions.activeAudio != null ? cameraOptions.activeAudio : true,
|
|
|
|
activeVideo: cameraOptions.activeVideo != null ? cameraOptions.activeVideo : true,
|
|
|
|
data: true,
|
|
|
|
mediaConstraints: {
|
|
|
|
video: screenConstraints.video,
|
|
|
|
audio: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
publisher.stream.configureScreenOptions(cameraOptions);
|
|
|
|
|
|
|
|
}, (error) => {
|
|
|
|
console.error('getScreenId error', error);
|
|
|
|
return;
|
|
|
|
});
|
2017-10-04 10:30:15 +02:00
|
|
|
publisher = new Publisher(this.openVidu.initPublisherScreen(parentId, callback), parentId, true);
|
2017-10-03 15:02:36 +02:00
|
|
|
console.info("'Publisher' initialized");
|
|
|
|
return publisher;
|
|
|
|
} else {
|
|
|
|
console.error('Screen sharing not supported on ' + adapter.browserDetails.browser);
|
|
|
|
}
|
|
|
|
}
|
2017-05-19 16:04:56 +02:00
|
|
|
} else {
|
|
|
|
cameraOptions = {
|
2017-09-29 20:00:00 +02:00
|
|
|
sendAudio: true,
|
|
|
|
sendVideo: true,
|
|
|
|
activeAudio: true,
|
|
|
|
activeVideo: true,
|
2017-05-19 16:04:56 +02:00
|
|
|
data: true,
|
2017-05-10 10:55:31 +02:00
|
|
|
mediaConstraints: {
|
|
|
|
audio: true,
|
|
|
|
video: { width: { ideal: 1280 } }
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 15:02:36 +02:00
|
|
|
publisher = new Publisher(this.openVidu.initPublisherTagged(parentId, cameraOptions, callback), parentId, false);
|
|
|
|
console.info("'Publisher' initialized");
|
|
|
|
return publisher;
|
2016-10-15 00:11:17 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-10 10:55:31 +02:00
|
|
|
alert("Browser not supported");
|
2016-10-15 00:11:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
checkSystemRequirements(): number {
|
|
|
|
let browser = adapter.browserDetails.browser;
|
|
|
|
let version = adapter.browserDetails.version;
|
2016-10-15 00:11:17 +02:00
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
//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;
|
2016-10-15 00:11:17 +02:00
|
|
|
}
|
2017-05-10 10:55:31 +02:00
|
|
|
if (((browser == 'chrome') && (version >= 28)) || ((browser == 'edge') && (version >= 12)) || ((browser == 'firefox') && (version >= 22))) {
|
|
|
|
return 1;
|
2016-10-15 00:11:17 +02:00
|
|
|
} else {
|
2017-05-10 10:55:31 +02:00
|
|
|
return 0;
|
2016-10-15 00:11:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 10:55:31 +02:00
|
|
|
getDevices(callback) {
|
|
|
|
navigator.mediaDevices.enumerateDevices().then((deviceInfos) => {
|
|
|
|
callback(null, deviceInfos);
|
|
|
|
}).catch((error) => {
|
2017-09-22 15:57:59 +02:00
|
|
|
console.error("Error getting devices", error);
|
2017-05-10 10:55:31 +02:00
|
|
|
callback(error, null);
|
2016-10-15 00:11:17 +02:00
|
|
|
});
|
2017-03-13 18:55:50 +01:00
|
|
|
}
|
2017-05-19 16:04:56 +02:00
|
|
|
|
2017-09-22 15:57:59 +02:00
|
|
|
enableProdMode() {
|
2017-10-03 15:02:36 +02:00
|
|
|
console.log = function () { };
|
|
|
|
console.debug = function () { };
|
|
|
|
console.info = function () { };
|
|
|
|
console.warn = function () { };
|
2017-09-22 15:57:59 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 00:11:17 +02:00
|
|
|
}
|