change hostname not to be static

pull/255/head
Julian Gong 2019-05-20 08:07:36 -05:00
parent 44f6c790f5
commit 46bf79bddf
3 changed files with 23 additions and 20 deletions

View File

@ -37,7 +37,7 @@ export class OpenVidu {
/** /**
* @hidden * @hidden
*/ */
static hostname: string; private hostname: string;
/** /**
* @hidden * @hidden
*/ */
@ -104,7 +104,7 @@ export class OpenVidu {
*/ */
public createSession(properties?: SessionProperties): Promise<Session> { public createSession(properties?: SessionProperties): Promise<Session> {
return new Promise<Session>((resolve, reject) => { return new Promise<Session>((resolve, reject) => {
const session = new Session(properties); const session = new Session(this.hostname, properties);
session.getSessionIdHttp() session.getSessionIdHttp()
.then(sessionId => { .then(sessionId => {
this.activeSessions.push(session); this.activeSessions.push(session);
@ -174,7 +174,7 @@ export class OpenVidu {
} }
axios.post( axios.post(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START,
data, data,
{ {
headers: { headers: {
@ -228,7 +228,7 @@ export class OpenVidu {
return new Promise<Recording>((resolve, reject) => { return new Promise<Recording>((resolve, reject) => {
axios.post( axios.post(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId,
undefined, undefined,
{ {
headers: { headers: {
@ -280,7 +280,7 @@ export class OpenVidu {
return new Promise<Recording>((resolve, reject) => { return new Promise<Recording>((resolve, reject) => {
axios.get( axios.get(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + '/' + recordingId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + '/' + recordingId,
{ {
headers: { headers: {
'Authorization': OpenVidu.basicAuth, 'Authorization': OpenVidu.basicAuth,
@ -322,7 +322,7 @@ export class OpenVidu {
return new Promise<Recording[]>((resolve, reject) => { return new Promise<Recording[]>((resolve, reject) => {
axios.get( axios.get(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS,
{ {
headers: { headers: {
Authorization: OpenVidu.basicAuth Authorization: OpenVidu.basicAuth
@ -374,7 +374,7 @@ export class OpenVidu {
return new Promise<Error>((resolve, reject) => { return new Promise<Error>((resolve, reject) => {
axios.delete( axios.delete(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + '/' + recordingId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_RECORDINGS + '/' + recordingId,
{ {
headers: { headers: {
'Authorization': OpenVidu.basicAuth, 'Authorization': OpenVidu.basicAuth,
@ -417,7 +417,7 @@ export class OpenVidu {
public fetch(): Promise<boolean> { public fetch(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
axios.get( axios.get(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS,
{ {
headers: { headers: {
Authorization: OpenVidu.basicAuth Authorization: OpenVidu.basicAuth
@ -444,7 +444,7 @@ export class OpenVidu {
} }
}); });
if (!!storedSession) { if (!!storedSession) {
const fetchedSession: Session = new Session().resetSessionWithJson(session); const fetchedSession: Session = new Session(this.hostname).resetSessionWithJson(session);
const changed: boolean = !storedSession.equalTo(fetchedSession); const changed: boolean = !storedSession.equalTo(fetchedSession);
if (changed) { if (changed) {
storedSession = fetchedSession; storedSession = fetchedSession;
@ -587,7 +587,7 @@ export class OpenVidu {
return new Promise<{ changes: boolean, sessionChanges: ObjMap<boolean> }>((resolve, reject) => { return new Promise<{ changes: boolean, sessionChanges: ObjMap<boolean> }>((resolve, reject) => {
axios.get( axios.get(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '?webRtcStats=true', 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '?webRtcStats=true',
{ {
headers: { headers: {
Authorization: OpenVidu.basicAuth Authorization: OpenVidu.basicAuth
@ -616,7 +616,7 @@ export class OpenVidu {
} }
}); });
if (!!storedSession) { if (!!storedSession) {
const fetchedSession: Session = new Session().resetSessionWithJson(session); const fetchedSession: Session = new Session(this.hostname).resetSessionWithJson(session);
fetchedSession.activeConnections.forEach(connection => { fetchedSession.activeConnections.forEach(connection => {
addWebRtcStatsToConnections(connection, session.connections.content); addWebRtcStatsToConnections(connection, session.connections.content);
}); });
@ -690,10 +690,10 @@ export class OpenVidu {
private setHostnameAndPort(): void { private setHostnameAndPort(): void {
const urlSplitted = this.urlOpenViduServer.split(':'); const urlSplitted = this.urlOpenViduServer.split(':');
if (urlSplitted.length === 3) { // URL has format: http:// + hostname + :port if (urlSplitted.length === 3) { // URL has format: http:// + hostname + :port
OpenVidu.hostname = this.urlOpenViduServer.split(':')[1].replace(/\//g, ''); this.hostname = this.urlOpenViduServer.split(':')[1].replace(/\//g, '');
OpenVidu.port = parseInt(this.urlOpenViduServer.split(':')[2].replace(/\//g, '')); OpenVidu.port = parseInt(this.urlOpenViduServer.split(':')[2].replace(/\//g, ''));
} else if (urlSplitted.length === 2) { // URL has format: hostname + :port } else if (urlSplitted.length === 2) { // URL has format: hostname + :port
OpenVidu.hostname = this.urlOpenViduServer.split(':')[0].replace(/\//g, ''); this.hostname = this.urlOpenViduServer.split(':')[0].replace(/\//g, '');
OpenVidu.port = parseInt(this.urlOpenViduServer.split(':')[1].replace(/\//g, '')); OpenVidu.port = parseInt(this.urlOpenViduServer.split(':')[1].replace(/\//g, ''));
} else { } else {
console.error("URL format incorrect: it must contain hostname and port (current value: '" + this.urlOpenViduServer + "')"); console.error("URL format incorrect: it must contain hostname and port (current value: '" + this.urlOpenViduServer + "')");

View File

@ -65,7 +65,7 @@ export class Session {
/** /**
* @hidden * @hidden
*/ */
constructor(propertiesOrJson?) { constructor(private hostname: string, propertiesOrJson?) {
if (!!propertiesOrJson) { if (!!propertiesOrJson) {
// Defined parameter // Defined parameter
if (!!propertiesOrJson.sessionId) { if (!!propertiesOrJson.sessionId) {
@ -108,7 +108,7 @@ export class Session {
}); });
axios.post( axios.post(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_TOKENS, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_TOKENS,
data, data,
{ {
headers: { headers: {
@ -152,7 +152,7 @@ export class Session {
public close(): Promise<any> { public close(): Promise<any> {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
axios.delete( axios.delete(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId,
{ {
headers: { headers: {
'Authorization': OpenVidu.basicAuth, 'Authorization': OpenVidu.basicAuth,
@ -202,7 +202,7 @@ export class Session {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
const beforeJSON: string = JSON.stringify(this); const beforeJSON: string = JSON.stringify(this);
axios.get( axios.get(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId,
{ {
headers: { headers: {
'Authorization': OpenVidu.basicAuth, 'Authorization': OpenVidu.basicAuth,
@ -254,7 +254,7 @@ export class Session {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId; const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId;
axios.delete( axios.delete(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId,
{ {
headers: { headers: {
'Authorization': OpenVidu.basicAuth, 'Authorization': OpenVidu.basicAuth,
@ -333,7 +333,7 @@ export class Session {
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId; const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId;
axios.delete( axios.delete(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId,
{ {
headers: { headers: {
'Authorization': OpenVidu.basicAuth, 'Authorization': OpenVidu.basicAuth,
@ -405,7 +405,7 @@ export class Session {
}); });
axios.post( axios.post(
'https://' + OpenVidu.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS, 'https://' + this.hostname + ':' + OpenVidu.port + OpenVidu.API_SESSIONS,
data, data,
{ {
headers: { headers: {

3
package-lock.json generated Normal file
View File

@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}