From 055e3706698a2c9eba3a1a0842a18f6a01cfaa3d Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Fri, 4 Feb 2022 10:54:17 +0100 Subject: [PATCH] openvidu-components: Removed rest service from library The library will receive tokens and it does not generate them --- .../components/session/session.component.ts | 3 - .../videoconference.component.ts | 62 +++++------- .../lib/services/rest/rest.service.spec.ts | 16 --- .../src/lib/services/rest/rest.service.ts | 75 -------------- .../src/app/openvidu-call/call.component.ts | 4 +- .../src/app/services/rest.service.ts | 98 +++++++++---------- 6 files changed, 75 insertions(+), 183 deletions(-) delete mode 100644 openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.spec.ts delete mode 100644 openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.ts diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/session/session.component.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/session/session.component.ts index 18d75b14..d2251ece 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/session/session.component.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/session/session.component.ts @@ -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'); } diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts index 7d86bbeb..e86f6a4a 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/videoconference/videoconference.component.ts @@ -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(); @Output() onCloseClicked = new EventEmitter(); @@ -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; diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.spec.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.spec.ts deleted file mode 100644 index c0a594f3..00000000 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.spec.ts +++ /dev/null @@ -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(); - }); -}); diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.ts deleted file mode 100644 index 8a11a50f..00000000 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/rest/rest.service.ts +++ /dev/null @@ -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 { - 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 { - 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(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 { - 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(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'); - } -} diff --git a/openvidu-components-angular/src/app/openvidu-call/call.component.ts b/openvidu-components-angular/src/app/openvidu-call/call.component.ts index bd3b4f1e..ac1a55a7 100644 --- a/openvidu-components-angular/src/app/openvidu-call/call.component.ts +++ b/openvidu-components-angular/src/app/openvidu-call/call.component.ts @@ -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; diff --git a/openvidu-components-angular/src/app/services/rest.service.ts b/openvidu-components-angular/src/app/services/rest.service.ts index 2a1bb8da..35ed5377 100644 --- a/openvidu-components-angular/src/app/services/rest.service.ts +++ b/openvidu-components-angular/src/app/services/rest.service.ts @@ -27,54 +27,54 @@ export class RestService { } } - private createSession(sessionId: string, openviduServerUrl: string, openviduSecret: string): Promise { - 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(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 { + // 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(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 { - 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(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 { + // 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(openviduServerUrl + '/openvidu/api/sessions/' + sessionId + '/connection', body, options) + // .pipe( + // catchError((error) => { + // reject(error); + // return observableThrowError(error); + // }) + // ) + // .subscribe((response) => { + // resolve(response.token); + // }); + // }); + // } }