OpenVidu Server URL now is expected as part of the sessionId

pull/20/head
pabloFuente 2017-07-12 18:56:13 +02:00
parent d6fde59ad3
commit 58ec882eff
5 changed files with 470 additions and 868 deletions

File diff suppressed because one or more lines are too long

View File

@ -29,15 +29,9 @@ export class OpenVidu {
openVidu: OpenViduInternal; openVidu: OpenViduInternal;
constructor(); constructor() {
constructor(wsUri: string);
constructor(wsUri?: string) {
if (wsUri) {
this.openVidu = new OpenViduInternal(wsUri);
} else {
this.openVidu = new OpenViduInternal(); this.openVidu = new OpenViduInternal();
} };
}
initSession(apiKey: string, sessionId: string): Session; initSession(apiKey: string, sessionId: string): Session;
initSession(sessionId: string): Session; initSession(sessionId: string): Session;

View File

@ -30,31 +30,7 @@ export class OpenViduInternal {
private camera: Stream; private camera: Stream;
private remoteStreams: Stream[] = []; private remoteStreams: Stream[] = [];
constructor(); constructor() { };
constructor(wsUri: string);
constructor(wsUri?: string) {
if (wsUri) {
this.wsUri = wsUri;
if (this.wsUri.charAt(wsUri.length - 1) != '/') {
this.wsUri += '/';
}
this.checkNgrokUri();
this.wsUri += 'room';
}
}
checkNgrokUri() {
if (this.wsUri.indexOf(".ngrok.io") !== -1) {
// OpenVidu server URL referes to a ngrok IP: secure wss protocol and delete port of URL
this.wsUri = this.wsUri.replace("ws://", "wss://");
let regex = /\.ngrok\.io:\d+/;
this.wsUri = this.wsUri.replace(regex, ".ngrok.io");
} else if (this.wsUri.indexOf("localhost") !== -1) {
// OpenVidu server URL referes to localhost IP
}
}
/* NEW METHODS */ /* NEW METHODS */

View File

@ -29,10 +29,24 @@ export class SessionInternal {
constructor(private openVidu: OpenViduInternal, private sessionId: string) { constructor(private openVidu: OpenViduInternal, private sessionId: string) {
this.localParticipant = new Connection(this.openVidu, true, this); this.localParticipant = new Connection(this.openVidu, true, this);
if (!this.openVidu.getWsUri()) { if (!this.openVidu.getWsUri()) {
this.openVidu.setWsUri(this.sessionId.substring(0, this.sessionId.lastIndexOf('/')) + '/room'); this.openVidu.setWsUri(this.checkNgrokUri(sessionId));
} }
} }
checkNgrokUri(sessionId: string): string {
sessionId = sessionId.substring(0, sessionId.lastIndexOf('/')) + '/room';
if (sessionId.indexOf(".ngrok.io") !== -1) {
// OpenVidu server URL referes to a ngrok IP: secure wss protocol and delete port of URL
sessionId = sessionId.replace("ws://", "wss://");
let regex = /\.ngrok\.io:\d+/;
sessionId = sessionId.replace(regex, ".ngrok.io");
} else if ((sessionId.indexOf("localhost") !== -1) || (sessionId.indexOf("127.0.0.1") != -1)) {
// OpenVidu server URL referes to localhost IP
}
return sessionId;
}
/* NEW METHODS */ /* NEW METHODS */

View File

@ -19,3 +19,6 @@ cp openvidu-browser/src/main/resources/static/js/OpenVidu.js ../openvidu-tutoria
# openvidu-mvc-node # openvidu-mvc-node
cp openvidu-browser/src/main/resources/static/js/OpenVidu.js ../openvidu-tutorials/openvidu-mvc-node/public/OpenVidu.js cp openvidu-browser/src/main/resources/static/js/OpenVidu.js ../openvidu-tutorials/openvidu-mvc-node/public/OpenVidu.js
# openvidu-getaroom
cp openvidu-browser/src/main/resources/static/js/OpenVidu.js ../openvidu-tutorials/openvidu-getaroom/web/OpenVidu.js