diff --git a/openvidu-node-client/src/OpenVidu.ts b/openvidu-node-client/src/OpenVidu.ts index 175f4533..7e131bf2 100644 --- a/openvidu-node-client/src/OpenVidu.ts +++ b/openvidu-node-client/src/OpenVidu.ts @@ -37,11 +37,7 @@ export class OpenVidu { /** * @hidden */ - public hostname: string; - /** - * @hidden - */ - public port: number; + public host: string; /** * @hidden */ @@ -171,7 +167,7 @@ export class OpenVidu { } axios.post( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START, + this.host + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START, data, { headers: { @@ -225,7 +221,7 @@ export class OpenVidu { return new Promise((resolve, reject) => { axios.post( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, + this.host + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, undefined, { headers: { @@ -277,7 +273,7 @@ export class OpenVidu { return new Promise((resolve, reject) => { axios.get( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_RECORDINGS + '/' + recordingId, + this.host + OpenVidu.API_RECORDINGS + '/' + recordingId, { headers: { 'Authorization': this.basicAuth, @@ -319,7 +315,7 @@ export class OpenVidu { return new Promise((resolve, reject) => { axios.get( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_RECORDINGS, + this.host + OpenVidu.API_RECORDINGS, { headers: { Authorization: this.basicAuth @@ -371,7 +367,7 @@ export class OpenVidu { return new Promise((resolve, reject) => { axios.delete( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_RECORDINGS + '/' + recordingId, + this.host + OpenVidu.API_RECORDINGS + '/' + recordingId, { headers: { 'Authorization': this.basicAuth, @@ -414,7 +410,7 @@ export class OpenVidu { public fetch(): Promise { return new Promise((resolve, reject) => { axios.get( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_SESSIONS, + this.host + OpenVidu.API_SESSIONS, { headers: { Authorization: this.basicAuth @@ -586,7 +582,7 @@ export class OpenVidu { return new Promise<{ changes: boolean, sessionChanges: ObjMap }>((resolve, reject) => { axios.get( - 'https://' + this.hostname + (!!this.port ? (':' + this.port) : '') + OpenVidu.API_SESSIONS + '?webRtcStats=true', + this.host + OpenVidu.API_SESSIONS + '?webRtcStats=true', { headers: { Authorization: this.basicAuth @@ -691,11 +687,10 @@ export class OpenVidu { try { url = new URL(this.urlOpenViduServer); } catch (error) { - console.error("URL format incorrect", error); - return; + console.error('URL format incorrect', error); + throw new Error('URL format incorrect: ' + error); } - this.hostname = url.hostname; - this.port = !!url.port ? parseInt(url.port) : undefined; + this.host = url.protocol + '//' + url.host; } } diff --git a/openvidu-node-client/src/Session.ts b/openvidu-node-client/src/Session.ts index 3ffc3c07..a9fead7b 100644 --- a/openvidu-node-client/src/Session.ts +++ b/openvidu-node-client/src/Session.ts @@ -108,7 +108,7 @@ export class Session { }); axios.post( - 'https://' + this.ov.hostname + (!!this.ov.port ? (':' + this.ov.port) : '') + OpenVidu.API_TOKENS, + this.ov.host + OpenVidu.API_TOKENS, data, { headers: { @@ -152,7 +152,7 @@ export class Session { public close(): Promise { return new Promise((resolve, reject) => { axios.delete( - 'https://' + this.ov.hostname + (!!this.ov.port ? (':' + this.ov.port) : '') + OpenVidu.API_SESSIONS + '/' + this.sessionId, + this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId, { headers: { 'Authorization': this.ov.basicAuth, @@ -202,7 +202,7 @@ export class Session { return new Promise((resolve, reject) => { const beforeJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference); axios.get( - 'https://' + this.ov.hostname + (!!this.ov.port ? (':' + this.ov.port) : '') + OpenVidu.API_SESSIONS + '/' + this.sessionId, + this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId, { headers: { 'Authorization': this.ov.basicAuth, @@ -254,7 +254,7 @@ export class Session { return new Promise((resolve, reject) => { const connectionId: string = typeof connection === 'string' ? connection : (connection).connectionId; axios.delete( - 'https://' + this.ov.hostname + (!!this.ov.port ? (':' + this.ov.port) : '') + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, + this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, { headers: { 'Authorization': this.ov.basicAuth, @@ -333,7 +333,7 @@ export class Session { return new Promise((resolve, reject) => { const streamId: string = typeof publisher === 'string' ? publisher : (publisher).streamId; axios.delete( - 'https://' + this.ov.hostname + (!!this.ov.port ? (':' + this.ov.port) : '') + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, + this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, { headers: { 'Authorization': this.ov.basicAuth, @@ -405,7 +405,7 @@ export class Session { }); axios.post( - 'https://' + this.ov.hostname + (!!this.ov.port ? (':' + this.ov.port) : '') + OpenVidu.API_SESSIONS, + this.ov.host + OpenVidu.API_SESSIONS, data, { headers: {