openvidu-browser: remove URL API usage

pull/255/head
pabloFuente 2019-05-20 14:11:14 +02:00
parent 227eefd99b
commit 06d455fc43
2 changed files with 68 additions and 89 deletions

View File

@ -111,7 +111,6 @@ export class OpenVidu {
if (platform['isInternetExplorer']) { if (platform['isInternetExplorer']) {
console.info("Detected IE Explorer " + platform.version); console.info("Detected IE Explorer " + platform.version);
this.importIEAdapterJS(); this.importIEAdapterJS();
this.importURLLibrary();
this.setGlobalIEFunctions(); this.setGlobalIEFunctions();
} }
@ -784,26 +783,6 @@ export class OpenVidu {
} }
} }
private importURLLibrary(): void {
const moduleSpecifier = 'https://cdn.jsdelivr.net/npm/url-polyfill@1.1.5/url-polyfill.min.js';
const scriptId = 'url-script-element';
var script = document.createElement('script');
script.async = false;
script.id = scriptId;
script.src = moduleSpecifier;
script.onload = () => {
// URL feature is now available
this.ee.emitEvent(scriptId, []);
document.getElementById(scriptId)!.classList.add(scriptId);
};
var ref = document.querySelector('script');
// Insert the new script node before the first reference node
if (ref && ref.parentNode) {
ref.parentNode.insertBefore(script, ref);
console.info("URL polyfill imported");
}
}
private setGlobalIEFunctions(): void { private setGlobalIEFunctions(): void {
// FIX: the IE plugin seems to require the handler functions to be globally accessible. Store the functions with unique streamId // FIX: the IE plugin seems to require the handler functions to be globally accessible. Store the functions with unique streamId

View File

@ -143,9 +143,9 @@ export class Session implements EventDispatcher {
* *
*/ */
connect(token: string, metadata?: any): Promise<any> { connect(token: string, metadata?: any): Promise<any> {
return new Promise(async (resolve, reject) => { return new Promise((resolve, reject) => {
await this.processToken(token); this.processToken(token);
if (this.openvidu.checkSystemRequirements()) { if (this.openvidu.checkSystemRequirements()) {
// Early configuration to deactivate automatic subscription to streams // Early configuration to deactivate automatic subscription to streams
@ -883,7 +883,7 @@ export class Session implements EventDispatcher {
.then(connection => { .then(connection => {
const stream = connection.stream; const stream = connection.stream;
if (platform['isInternetExplorer']) { if (platform['isInternetExplorer']) {
(<any>stream.getWebRtcPeer()).addIceCandidate(candidate, () => {}, error => { (<any>stream.getWebRtcPeer()).addIceCandidate(candidate, () => { }, error => {
console.error('Error adding candidate for ' + stream.streamId console.error('Error adding candidate for ' + stream.streamId
+ ' stream of endpoint ' + msg.endpointName + ': ' + error); + ' stream of endpoint ' + msg.endpointName + ': ' + error);
}); });
@ -1143,74 +1143,74 @@ export class Session implements EventDispatcher {
}); });
} }
private async processToken(token: string): Promise<void> { private processToken(token: string): void {
return new Promise<void>((resolve, reject) => { const match = token.match(/^(wss?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
if (!!match) {
const processTokenAux: Function = token => { const url = {
const url = new URL(token); protocol: match[1],
this.sessionId = <string>url.searchParams.get('sessionId'); host: match[2],
const secret = url.searchParams.get('secret'); hostname: match[3],
const recorder = url.searchParams.get('recorder'); port: match[4],
const turnUsername = url.searchParams.get('turnUsername'); pathname: match[5],
const turnCredential = url.searchParams.get('turnCredential'); search: match[6],
const role = url.searchParams.get('role'); hash: match[7]
const webrtcStatsInterval = url.searchParams.get('webrtcStatsInterval');
const openviduServerVersion = url.searchParams.get('version');
if (!!secret) {
this.openvidu.secret = secret;
}
if (!!recorder) {
this.openvidu.recorder = true;
}
if (!!turnUsername && !!turnCredential) {
const stunUrl = 'stun:' + url.hostname + ':3478';
const turnUrl1 = 'turn:' + url.hostname + ':3478';
const turnUrl2 = turnUrl1 + '?transport=tcp';
this.openvidu.iceServers = [
{ urls: [stunUrl] },
{ urls: [turnUrl1, turnUrl2], username: turnUsername, credential: turnCredential }
];
console.log('TURN temp credentials [' + turnUsername + ':' + turnCredential + ']');
}
if (!!role) {
this.openvidu.role = role;
}
if (!!webrtcStatsInterval) {
this.openvidu.webrtcStatsInterval = +webrtcStatsInterval;
}
if (!!openviduServerVersion) {
console.info("openvidu-server version: " + openviduServerVersion);
if (openviduServerVersion !== this.openvidu.libraryVersion) {
console.error('OpenVidu Server (' + openviduServerVersion +
') and OpenVidu Browser (' + this.openvidu.libraryVersion +
') versions do NOT match. There may be incompatibilities')
}
}
this.openvidu.wsUri = 'wss://' + url.host + '/openvidu';
this.openvidu.httpUri = 'https://' + url.host;
resolve();
}; };
if (platform['isInternetExplorer']) { const params = token.split('?');
// Wait for URL polyfill to be available const queryParams = decodeURI(params[1])
const scriptId = 'url-script-element'; .split('&')
const script = document.getElementById(scriptId); .map(param => param.split('='))
if (script!.classList.contains(scriptId)) { .reduce((values, [key, value]) => {
// URL polyfill is already available values[key] = value
processTokenAux(token); return values
} else { }, {});
// Wait for the script tag to be loaded
this.openvidu.ee.once(scriptId, () => { this.sessionId = <string>queryParams['sessionId'];
processTokenAux(token); const secret = queryParams['secret'];
}); const recorder = queryParams['recorder'];
} const turnUsername = queryParams['turnUsername'];
} else { const turnCredential = queryParams['turnCredential'];
processTokenAux(token); const role = queryParams['role'];
const webrtcStatsInterval = queryParams['webrtcStatsInterval'];
const openviduServerVersion = queryParams['version'];
if (!!secret) {
this.openvidu.secret = secret;
} }
}); if (!!recorder) {
this.openvidu.recorder = true;
}
if (!!turnUsername && !!turnCredential) {
const stunUrl = 'stun:' + url.hostname + ':3478';
const turnUrl1 = 'turn:' + url.hostname + ':3478';
const turnUrl2 = turnUrl1 + '?transport=tcp';
this.openvidu.iceServers = [
{ urls: [stunUrl] },
{ urls: [turnUrl1, turnUrl2], username: turnUsername, credential: turnCredential }
];
console.log('TURN temp credentials [' + turnUsername + ':' + turnCredential + ']');
}
if (!!role) {
this.openvidu.role = role;
}
if (!!webrtcStatsInterval) {
this.openvidu.webrtcStatsInterval = +webrtcStatsInterval;
}
if (!!openviduServerVersion) {
console.info("openvidu-server version: " + openviduServerVersion);
if (openviduServerVersion !== this.openvidu.libraryVersion) {
console.error('OpenVidu Server (' + openviduServerVersion +
') and OpenVidu Browser (' + this.openvidu.libraryVersion +
') versions do NOT match. There may be incompatibilities')
}
}
this.openvidu.wsUri = 'wss://' + url.host + '/openvidu';
this.openvidu.httpUri = 'https://' + url.host;
} else {
console.error('Token "' + token + '" is not valid')
}
} }
} }