mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server dashboard: port fixed to 443 removed
parent
0fce47082f
commit
a144d27b7b
|
@ -15,6 +15,7 @@ import { OpenViduVideoComponent } from './components/layouts/ov-video.component'
|
||||||
import { SessionDetailsComponent } from './components/session-details/session-details.component';
|
import { SessionDetailsComponent } from './components/session-details/session-details.component';
|
||||||
import { InfoService } from './services/info.service';
|
import { InfoService } from './services/info.service';
|
||||||
import { RestService } from './services/rest.service';
|
import { RestService } from './services/rest.service';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -31,6 +32,7 @@ import { RestService } from './services/rest.service';
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
|
HttpClientModule,
|
||||||
routing,
|
routing,
|
||||||
AppMaterialModule,
|
AppMaterialModule,
|
||||||
FlexLayoutModule
|
FlexLayoutModule
|
||||||
|
|
|
@ -103,20 +103,19 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
||||||
dialogRef = this.dialog.open(CredentialsDialogComponent);
|
dialogRef = this.dialog.open(CredentialsDialogComponent);
|
||||||
dialogRef.componentInstance.myReference = dialogRef;
|
dialogRef.componentInstance.myReference = dialogRef;
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe(secret => {
|
dialogRef.afterClosed().subscribe(async secret => {
|
||||||
if (secret) {
|
if (secret) {
|
||||||
this.restService.getOpenViduToken(secret)
|
try {
|
||||||
.then((token => {
|
const token = await this.restService.getToken(secret);
|
||||||
this.connectToSession(token);
|
this.connectToSession(token);
|
||||||
}))
|
} catch (error) {
|
||||||
.catch(error => {
|
if (error.status === 401) { // User unauthorized error. OpenVidu security is active
|
||||||
if (error === 401) { // User unauthorized error. OpenVidu security is active
|
this.testVideo();
|
||||||
this.testVideo();
|
} else {
|
||||||
} else {
|
console.error(error.error);
|
||||||
console.error(error);
|
this.msgChain.push('Error connecting to session: [' + error.status + '] ' + error.message);
|
||||||
this.msgChain.push('Error connecting to session: ' + error);
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,86 +1,82 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpHeaders, HttpClient } from '@angular/common/http';
|
||||||
|
import { catchError } from 'rxjs/operators';
|
||||||
|
import { throwError } from 'rxjs';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RestService {
|
export class RestService {
|
||||||
|
|
||||||
private openviduPublicUrl: string;
|
private openviduPublicUrl: string;
|
||||||
|
|
||||||
|
constructor(private httpClient: HttpClient) { }
|
||||||
|
|
||||||
getOpenViduPublicUrl(): Promise<string> {
|
getOpenViduPublicUrl(): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!!this.openviduPublicUrl) {
|
if (!!this.openviduPublicUrl) {
|
||||||
resolve(this.openviduPublicUrl);
|
resolve(this.openviduPublicUrl);
|
||||||
} else {
|
} else {
|
||||||
const url = location.protocol + '//' + location.hostname + ((!!location.port) ? (':' + location.port) : '') +
|
this.httpClient.get(location.protocol + '//' + location.hostname + ((!!location.port) ? (':' + location.port) : '') +
|
||||||
'/config/openvidu-publicurl';
|
'/config/openvidu-publicurl', { responseType: 'text' }).pipe(
|
||||||
const http = new XMLHttpRequest();
|
catchError(error => {
|
||||||
|
reject(error);
|
||||||
http.onreadystatechange = () => {
|
return throwError(error);
|
||||||
if (http.readyState === 4) {
|
})
|
||||||
if (http.status === 200) {
|
)
|
||||||
this.openviduPublicUrl = http.responseText;
|
.subscribe(response => {
|
||||||
resolve(http.responseText);
|
this.openviduPublicUrl = response;
|
||||||
} else {
|
resolve(response);
|
||||||
reject('Error getting OpenVidu publicurl');
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
http.open('GET', url, true);
|
|
||||||
http.send();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getOpenViduToken(secret: string): Promise<string> {
|
async getToken(secret: string): Promise<string> {
|
||||||
if (!this.openviduPublicUrl) {
|
const sessionId: string = await this.createSession(secret);
|
||||||
this.getOpenViduPublicUrl().then(() => {
|
return await this.createToken(sessionId, secret);
|
||||||
return this.getOpenViduToken(secret);
|
}
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const url1 = 'https://OPENVIDUAPP:' + secret + '@' + this.openviduPublicUrl.split('://')[1] + 'api/sessions';
|
|
||||||
const http1 = new XMLHttpRequest();
|
|
||||||
const data1 = {};
|
|
||||||
data1['mediaMode'] = 'ROUTED';
|
|
||||||
data1['recordingMode'] = 'MANUAL';
|
|
||||||
data1['RECORDING_LAYOUT'] = 'BEST_FIT';
|
|
||||||
const json1 = JSON.stringify(data1);
|
|
||||||
|
|
||||||
http1.onreadystatechange = () => {
|
createSession(secret: String): Promise<string> {
|
||||||
if (http1.status === 401) {
|
return new Promise((resolve, reject) => {
|
||||||
reject(401);
|
const body = JSON.stringify({});
|
||||||
} else if (http1.readyState === 4) {
|
const options = {
|
||||||
if (http1.status === 200) {
|
headers: new HttpHeaders({
|
||||||
const sessionId = JSON.parse(http1.responseText).id;
|
'Authorization': 'Basic ' + btoa('OPENVIDUAPP:' + secret),
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
})
|
||||||
|
};
|
||||||
|
this.httpClient.post(this.openviduPublicUrl + 'api/sessions', body, options)
|
||||||
|
.pipe(
|
||||||
|
catchError(error => {
|
||||||
|
reject(error);
|
||||||
|
return throwError(error);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.subscribe(response => {
|
||||||
|
resolve(response['id']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const url2 = this.openviduPublicUrl + 'api/tokens';
|
createToken(session, secret): Promise<string> {
|
||||||
const http2 = new XMLHttpRequest();
|
return new Promise((resolve, reject) => {
|
||||||
const data2 = {};
|
const body = JSON.stringify({ session });
|
||||||
data2['session'] = sessionId;
|
const options = {
|
||||||
const json2 = JSON.stringify(data2);
|
headers: new HttpHeaders({
|
||||||
|
'Authorization': 'Basic ' + btoa('OPENVIDUAPP:' + secret),
|
||||||
http2.onreadystatechange = () => {
|
'Content-Type': 'application/json'
|
||||||
if (http2.readyState === 4) {
|
})
|
||||||
if (http2.status === 200) {
|
};
|
||||||
resolve(JSON.parse(http2.responseText).id);
|
this.httpClient.post(this.openviduPublicUrl + 'api/tokens', body, options)
|
||||||
} else {
|
.pipe(
|
||||||
reject(http2.status);
|
catchError(error => {
|
||||||
}
|
reject(error);
|
||||||
};
|
return throwError(error);
|
||||||
}
|
})
|
||||||
http2.open('POST', url2, true);
|
)
|
||||||
http2.setRequestHeader('Content-type', 'application/json');
|
.subscribe(response => {
|
||||||
http2.setRequestHeader('Authorization', 'Basic ' + btoa('OPENVIDUAPP:' + secret));
|
resolve(response['token']);
|
||||||
http2.send(json2);
|
});
|
||||||
} else {
|
});
|
||||||
reject(http1.status);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
http1.open('POST', url1, true);
|
|
||||||
http1.setRequestHeader('Content-type', 'application/json');
|
|
||||||
http1.send(json1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue