mirror of https://github.com/OpenVidu/openvidu.git
openvidu-components: Removed rest service from library
The library will receive tokens and it does not generate thempull/707/head
parent
00087a7dc7
commit
055e370669
|
@ -8,7 +8,6 @@ import { ChatService } from '../../services/chat/chat.service';
|
|||
import { LoggerService } from '../../services/logger/logger.service';
|
||||
import { WebrtcService } from '../../services/webrtc/webrtc.service';
|
||||
import { TokenService } from '../../services/token/token.service';
|
||||
import { PlatformService } from '../../services/platform/platform.service';
|
||||
import { ActionService } from '../../services/action/action.service';
|
||||
import { Signal } from '../../models/signal.model';
|
||||
import { ParticipantService } from '../../services/participant/participant.service';
|
||||
|
@ -60,8 +59,6 @@ export class SessionComponent implements OnInit {
|
|||
protected tokenService: TokenService,
|
||||
protected layoutService: LayoutService,
|
||||
protected menuService: SidenavMenuService,
|
||||
|
||||
protected platformService: PlatformService
|
||||
) {
|
||||
this.log = this.loggerSrv.get('SessionComponent');
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Component, ContentChild, EventEmitter, Input, OnInit, Output, TemplateRef, ViewChild, ViewContainerRef } from '@angular/core';
|
||||
import { RestService } from '../../services/rest/rest.service';
|
||||
import { Component, ContentChild, EventEmitter, Input, OnInit, Output, TemplateRef } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'ov-videoconference',
|
||||
|
@ -16,9 +15,9 @@ export class VideoconferenceComponent implements OnInit {
|
|||
|
||||
@Input() sessionName: string;
|
||||
@Input() userName: string;
|
||||
@Input() openviduServerUrl: string;
|
||||
@Input() openviduSecret: string;
|
||||
@Input() tokens: { webcam: string; screen: string };
|
||||
|
||||
// @Input() openviduServerUrl: string;
|
||||
// @Input() openviduSecret: string;
|
||||
|
||||
@Output() onJoinClicked = new EventEmitter<any>();
|
||||
@Output() onCloseClicked = new EventEmitter<any>();
|
||||
|
@ -30,44 +29,31 @@ export class VideoconferenceComponent implements OnInit {
|
|||
error: boolean = false;
|
||||
errorMessage: string = '';
|
||||
|
||||
constructor(private restService: RestService) {}
|
||||
constructor() {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
@Input()
|
||||
set tokens(tokens: { webcam: string; screen: string }) {
|
||||
if (!tokens || (!tokens.webcam && !tokens.screen)) {
|
||||
//No tokens received
|
||||
// throw new Error('No tokens received');
|
||||
console.warn('No tokens received');
|
||||
|
||||
} else {
|
||||
if (tokens.webcam || tokens.screen) {
|
||||
this._tokens = {
|
||||
webcam: tokens.webcam,
|
||||
screen: tokens.screen
|
||||
};
|
||||
this.joinSessionClicked = true;
|
||||
this.isSessionAlive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _onJoinClicked() {
|
||||
|
||||
this.onJoinClicked.emit();
|
||||
// if (!this.tokens || (!this.tokens?.webcam && !this.tokens?.screen)) {
|
||||
// //No tokens received
|
||||
|
||||
// if (!!this.sessionName && !!this.openviduServerUrl && !!this.openviduSecret) {
|
||||
// // Generate tokens
|
||||
// this._tokens = {
|
||||
// webcam: await this.restService.getToken(this.sessionName, this.openviduServerUrl, this.openviduSecret),
|
||||
// screen: await this.restService.getToken(this.sessionName, this.openviduServerUrl, this.openviduSecret)
|
||||
// };
|
||||
// } else {
|
||||
// // No tokens received and can't generate them
|
||||
// this.error = true;
|
||||
// this.errorMessage = `Cannot access to OpenVidu Server with url '${this.openviduServerUrl}' to genere tokens for session '${this.sessionName}'`;
|
||||
// throw this.errorMessage;
|
||||
// }
|
||||
// } else if (!this.tokens?.webcam || !this.tokens?.screen) {
|
||||
// // 1 token received
|
||||
// const aditionalToken = await this.restService.getToken(this.sessionName, this.openviduServerUrl, this.openviduSecret);
|
||||
// this._tokens = {
|
||||
// webcam: !!this.tokens.webcam ? this.tokens.webcam : aditionalToken,
|
||||
// screen: !!this.tokens.screen ? this.tokens.screen : aditionalToken
|
||||
// };
|
||||
// } else {
|
||||
// // 2 tokens received.
|
||||
// this._tokens = {
|
||||
// webcam: this.tokens.webcam,
|
||||
// screen: this.tokens.screen
|
||||
// };
|
||||
// }
|
||||
this.joinSessionClicked = true;
|
||||
this.isSessionAlive = true;
|
||||
}
|
||||
onLeaveSessionClicked() {
|
||||
this.isSessionAlive = false;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RestService } from './rest.service';
|
||||
|
||||
describe('RestService', () => {
|
||||
let service: RestService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RestService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -1,75 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { catchError, throwError } from 'rxjs';
|
||||
import { Buffer} from 'buffer';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RestService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
async getToken(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
if (!!openviduServerUrl && !!openviduSecret) {
|
||||
const _sessionId = await this.createSession(sessionId, openviduServerUrl, openviduSecret);
|
||||
return await this.createToken(_sessionId, openviduServerUrl, openviduSecret);
|
||||
} else {
|
||||
return Promise.reject(`Error requesting a token to ${openviduServerUrl} with session id: ${sessionId}`);
|
||||
}
|
||||
}
|
||||
|
||||
private createSession(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = JSON.stringify({ customSessionId: sessionId });
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
Authorization: 'Basic ' + this.btoa('OPENVIDUAPP:' + openviduSecret),
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
};
|
||||
return this.http
|
||||
.post<any>(openviduServerUrl + '/openvidu/api/sessions', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
if (error.status === 409) {
|
||||
resolve(sessionId);
|
||||
}
|
||||
if (error.statusText === 'Unknown Error') {
|
||||
reject({ status: 401, message: 'ERR_CERT_AUTHORITY_INVALID' });
|
||||
}
|
||||
return throwError(() => new Error(error));
|
||||
})
|
||||
)
|
||||
.subscribe((response) => {
|
||||
resolve(response.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private createToken(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = JSON.stringify({});
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
Authorization: 'Basic ' + this.btoa('OPENVIDUAPP:' + openviduSecret),
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
};
|
||||
return this.http
|
||||
.post<any>(openviduServerUrl + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
reject(error);
|
||||
return throwError(() => new Error(error));
|
||||
})
|
||||
)
|
||||
.subscribe((response) => {
|
||||
resolve(response.token);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private btoa(str: string): string {
|
||||
return Buffer.from(str).toString('base64');
|
||||
}
|
||||
}
|
|
@ -27,8 +27,8 @@ export class CallComponent implements OnInit {
|
|||
screen: await this.restService.getToken(this.sessionId)
|
||||
};
|
||||
|
||||
this.joinSessionClicked = true;
|
||||
this.isSessionAlive = true;
|
||||
// this.joinSessionClicked = true;
|
||||
// this.isSessionAlive = true;
|
||||
}
|
||||
onCloseClicked() {
|
||||
this.closeClicked = true;
|
||||
|
|
|
@ -27,54 +27,54 @@ export class RestService {
|
|||
}
|
||||
}
|
||||
|
||||
private createSession(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = JSON.stringify({ customSessionId: sessionId });
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + openviduSecret),
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
};
|
||||
return this.http
|
||||
.post<any>(openviduServerUrl + '/openvidu/api/sessions', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
if (error.status === 409) {
|
||||
resolve(sessionId);
|
||||
}
|
||||
if (error.statusText === 'Unknown Error') {
|
||||
reject({ status: 401, message: 'ERR_CERT_AUTHORITY_INVALID' });
|
||||
}
|
||||
return observableThrowError(error);
|
||||
})
|
||||
)
|
||||
.subscribe((response) => {
|
||||
resolve(response.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
// private createSession(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const body = JSON.stringify({ customSessionId: sessionId });
|
||||
// const options = {
|
||||
// headers: new HttpHeaders({
|
||||
// Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + openviduSecret),
|
||||
// 'Content-Type': 'application/json'
|
||||
// })
|
||||
// };
|
||||
// return this.http
|
||||
// .post<any>(openviduServerUrl + '/openvidu/api/sessions', body, options)
|
||||
// .pipe(
|
||||
// catchError((error) => {
|
||||
// if (error.status === 409) {
|
||||
// resolve(sessionId);
|
||||
// }
|
||||
// if (error.statusText === 'Unknown Error') {
|
||||
// reject({ status: 401, message: 'ERR_CERT_AUTHORITY_INVALID' });
|
||||
// }
|
||||
// return observableThrowError(error);
|
||||
// })
|
||||
// )
|
||||
// .subscribe((response) => {
|
||||
// resolve(response.id);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
private createToken(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = JSON.stringify({});
|
||||
const options = {
|
||||
headers: new HttpHeaders({
|
||||
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + openviduSecret),
|
||||
'Content-Type': 'application/json'
|
||||
})
|
||||
};
|
||||
return this.http
|
||||
.post<any>(openviduServerUrl + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
reject(error);
|
||||
return observableThrowError(error);
|
||||
})
|
||||
)
|
||||
.subscribe((response) => {
|
||||
resolve(response.token);
|
||||
});
|
||||
});
|
||||
}
|
||||
// private createToken(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise<string> {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const body = JSON.stringify({});
|
||||
// const options = {
|
||||
// headers: new HttpHeaders({
|
||||
// Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + openviduSecret),
|
||||
// 'Content-Type': 'application/json'
|
||||
// })
|
||||
// };
|
||||
// return this.http
|
||||
// .post<any>(openviduServerUrl + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
||||
// .pipe(
|
||||
// catchError((error) => {
|
||||
// reject(error);
|
||||
// return observableThrowError(error);
|
||||
// })
|
||||
// )
|
||||
// .subscribe((response) => {
|
||||
// resolve(response.token);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue