openvidu-browser now allows OpenVidu initialization without URL (ngrok support)

pull/20/head
pabloFuente 2017-06-14 14:14:45 +02:00
parent dbe48b543b
commit c1410a6f82
4 changed files with 51 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

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

View File

@ -22,6 +22,7 @@ export type Callback<T> = (error?: any, openVidu?: T) => void;
export class OpenViduInternal { export class OpenViduInternal {
private wsUri;
private session: SessionInternal; private session: SessionInternal;
private jsonRpcClient: any; private jsonRpcClient: any;
private rpcParams: any; private rpcParams: any;
@ -29,12 +30,17 @@ export class OpenViduInternal {
private camera: Stream; private camera: Stream;
private remoteStreams: Stream[] = []; private remoteStreams: Stream[] = [];
constructor(private wsUri: string) { constructor();
if (this.wsUri.charAt(wsUri.length - 1) != '/') { constructor(wsUri: string);
this.wsUri += '/'; constructor(wsUri?: string) {
if (wsUri) {
this.wsUri = wsUri;
if (this.wsUri.charAt(wsUri.length - 1) != '/') {
this.wsUri += '/';
}
this.checkNgrokUri();
this.wsUri += 'room';
} }
this.checkNgrokUri();
this.wsUri += 'room';
} }
@ -113,7 +119,13 @@ export class OpenViduInternal {
} }
/* NEW METHODS */ /* NEW METHODS */
getWsUri() {
return this.wsUri;
}
setWsUri(wsUri: string) {
this.wsUri = wsUri;
}
getOpenViduServerURL() { getOpenViduServerURL() {
return 'https://' + this.wsUri.split("wss://")[1].split("/room")[0]; return 'https://' + this.wsUri.split("wss://")[1].split("/room")[0];

View File

@ -28,6 +28,9 @@ 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()) {
this.openVidu.setWsUri(this.sessionId.substring(0, this.sessionId.lastIndexOf('/')) + '/room');
}
} }