openvidu-components: Removed token service

Moved all tokens logic to openvidu service
pull/759/head
Carlos Santos 2022-11-09 10:35:48 +01:00
parent d4cfd3893a
commit 80a0f16778
10 changed files with 80 additions and 127 deletions

View File

@ -7,44 +7,37 @@ import { ChatServiceMock } from '../../services/chat/chat.service.mock';
import { LoggerService } from '../../services/logger/logger.service'; import { LoggerService } from '../../services/logger/logger.service';
import { LoggerServiceMock } from '../../services/logger/logger.service.mock'; import { LoggerServiceMock } from '../../services/logger/logger.service.mock';
import { PlatformService } from '../../services/platform/platform.service';
import { PlatformServiceMock } from '../../services/platform/platform.service.mock';
import { TokenService } from '../../services/token/token.service';
import { TokenServiceMock } from '../../services/token/token.service.mock';
import { WebrtcService } from '../../services/webrtc/webrtc.service';
import { WebrtcServiceMock } from '../../services/webrtc/webrtc.service.mock';
import { ParticipantService } from '../../services/participant/participant.service'; import { ParticipantService } from '../../services/participant/participant.service';
import { ParticipantServiceMock } from '../../services/participant/participant.service.mock'; import { ParticipantServiceMock } from '../../services/participant/participant.service.mock';
import { PlatformService } from '../../services/platform/platform.service';
import { PlatformServiceMock } from '../../services/platform/platform.service.mock';
import { SessionComponent } from './session.component'; import { SessionComponent } from './session.component';
describe('SessionComponent', () => { describe('SessionComponent', () => {
let component: SessionComponent; let component: SessionComponent;
let fixture: ComponentFixture<SessionComponent>; let fixture: ComponentFixture<SessionComponent>;
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ SessionComponent ], declarations: [SessionComponent],
providers: [ providers: [
{ provide: LoggerService, useClass: LoggerServiceMock }, { provide: LoggerService, useClass: LoggerServiceMock },
{ provide: ActionService, useClass: ActionServiceMock }, { provide: ActionService, useClass: ActionServiceMock },
{ provide: ParticipantService, useClass: ParticipantServiceMock }, { provide: ParticipantService, useClass: ParticipantServiceMock },
{ provide: WebrtcService, useClass: WebrtcServiceMock },
{ provide: ChatService, useClass: ChatServiceMock }, { provide: ChatService, useClass: ChatServiceMock },
{ provide: PlatformService, useClass: PlatformServiceMock }, { provide: PlatformService, useClass: PlatformServiceMock }
{ provide: TokenService, useClass: TokenServiceMock } ]
] }).compileComponents();
}) });
.compileComponents();
});
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(SessionComponent); fixture = TestBed.createComponent(SessionComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
}); });

View File

@ -43,7 +43,6 @@ import { PanelEvent, PanelService } from '../../services/panel/panel.service';
import { ParticipantService } from '../../services/participant/participant.service'; import { ParticipantService } from '../../services/participant/participant.service';
import { PlatformService } from '../../services/platform/platform.service'; import { PlatformService } from '../../services/platform/platform.service';
import { RecordingService } from '../../services/recording/recording.service'; import { RecordingService } from '../../services/recording/recording.service';
import { TokenService } from '../../services/token/token.service';
import { TranslateService } from '../../services/translate/translate.service'; import { TranslateService } from '../../services/translate/translate.service';
import { VirtualBackgroundService } from '../../services/virtual-background/virtual-background.service'; import { VirtualBackgroundService } from '../../services/virtual-background/virtual-background.service';
@ -94,7 +93,6 @@ export class SessionComponent implements OnInit, OnDestroy {
protected participantService: ParticipantService, protected participantService: ParticipantService,
protected loggerSrv: LoggerService, protected loggerSrv: LoggerService,
protected chatService: ChatService, protected chatService: ChatService,
protected tokenService: TokenService,
private libService: OpenViduAngularConfigService, private libService: OpenViduAngularConfigService,
protected layoutService: LayoutService, protected layoutService: LayoutService,
protected panelService: PanelService, protected panelService: PanelService,
@ -167,7 +165,7 @@ export class SessionComponent implements OnInit, OnDestroy {
async ngOnInit() { async ngOnInit() {
if (!this.usedInPrejoinPage) { if (!this.usedInPrejoinPage) {
if (!this.tokenService.getScreenToken()) { if (!this.openviduService.getScreenToken()) {
// Hide screenshare button if screen token does not exist // Hide screenshare button if screen token does not exist
this.libService.screenshareButton.next(false); this.libService.screenshareButton.next(false);
} }
@ -254,16 +252,19 @@ export class SessionComponent implements OnInit, OnDestroy {
private async connectToSession(): Promise<void> { private async connectToSession(): Promise<void> {
try { try {
const webcamToken = this.openviduService.getWebcamToken();
const screenToken = this.openviduService.getScreenToken();
if (this.participantService.haveICameraAndScreenActive()) { if (this.participantService.haveICameraAndScreenActive()) {
await this.openviduService.connectSession(this.openviduService.getWebcamSession(), this.tokenService.getWebcamToken()); await this.openviduService.connectSession(this.openviduService.getWebcamSession(), webcamToken);
await this.openviduService.connectSession(this.openviduService.getScreenSession(), this.tokenService.getScreenToken()); await this.openviduService.connectSession(this.openviduService.getScreenSession(), screenToken);
await this.openviduService.publish(this.participantService.getMyCameraPublisher()); await this.openviduService.publish(this.participantService.getMyCameraPublisher());
await this.openviduService.publish(this.participantService.getMyScreenPublisher()); await this.openviduService.publish(this.participantService.getMyScreenPublisher());
} else if (this.participantService.isOnlyMyScreenActive()) { } else if (this.participantService.isOnlyMyScreenActive()) {
await this.openviduService.connectSession(this.openviduService.getScreenSession(), this.tokenService.getScreenToken()); await this.openviduService.connectSession(this.openviduService.getScreenSession(), screenToken);
await this.openviduService.publish(this.participantService.getMyScreenPublisher()); await this.openviduService.publish(this.participantService.getMyScreenPublisher());
} else { } else {
await this.openviduService.connectSession(this.openviduService.getWebcamSession(), this.tokenService.getWebcamToken()); await this.openviduService.connectSession(this.openviduService.getWebcamSession(), webcamToken);
await this.openviduService.publish(this.participantService.getMyCameraPublisher()); await this.openviduService.publish(this.participantService.getMyCameraPublisher());
} }
} catch (error) { } catch (error) {

View File

@ -16,7 +16,6 @@ import { skip, Subscription } from 'rxjs';
import { ChatService } from '../../services/chat/chat.service'; import { ChatService } from '../../services/chat/chat.service';
import { DocumentService } from '../../services/document/document.service'; import { DocumentService } from '../../services/document/document.service';
import { PanelEvent, PanelService } from '../../services/panel/panel.service'; import { PanelEvent, PanelService } from '../../services/panel/panel.service';
import { TokenService } from '../../services/token/token.service';
import { MediaChange } from '@angular/flex-layout'; import { MediaChange } from '@angular/flex-layout';
import { MatMenuTrigger } from '@angular/material/menu'; import { MatMenuTrigger } from '@angular/material/menu';
@ -373,7 +372,6 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit {
protected documentService: DocumentService, protected documentService: DocumentService,
protected chatService: ChatService, protected chatService: ChatService,
protected panelService: PanelService, protected panelService: PanelService,
protected tokenService: TokenService,
protected participantService: ParticipantService, protected participantService: ParticipantService,
protected openviduService: OpenViduService, protected openviduService: OpenViduService,
protected oVDevicesService: DeviceService, protected oVDevicesService: DeviceService,

View File

@ -38,7 +38,6 @@ import { LoggerService } from '../../services/logger/logger.service';
import { OpenViduService } from '../../services/openvidu/openvidu.service'; import { OpenViduService } from '../../services/openvidu/openvidu.service';
import { ParticipantService } from '../../services/participant/participant.service'; import { ParticipantService } from '../../services/participant/participant.service';
import { StorageService } from '../../services/storage/storage.service'; import { StorageService } from '../../services/storage/storage.service';
import { TokenService } from '../../services/token/token.service';
import { TranslateService } from '../../services/translate/translate.service'; import { TranslateService } from '../../services/translate/translate.service';
/** /**
@ -274,7 +273,7 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni
this.log.w('No tokens received'); this.log.w('No tokens received');
} else { } else {
this.log.w('Tokens received'); this.log.w('Tokens received');
this.tokenService.setWebcamToken(tokens.webcam); this.openviduService.setWebcamToken(tokens.webcam);
const openviduEdition = new URL(tokens.webcam).searchParams.get('edition'); const openviduEdition = new URL(tokens.webcam).searchParams.get('edition');
if (!!openviduEdition) { if (!!openviduEdition) {
@ -285,7 +284,7 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni
} }
if (tokens.screen) { if (tokens.screen) {
this.tokenService.setScreenToken(tokens.screen); this.openviduService.setScreenToken(tokens.screen);
} else { } else {
this.log.w('No screen token found. Screenshare feature will be disabled'); this.log.w('No screen token found. Screenshare feature will be disabled');
} }
@ -438,7 +437,6 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni
private openviduService: OpenViduService, private openviduService: OpenViduService,
private actionService: ActionService, private actionService: ActionService,
private libService: OpenViduAngularConfigService, private libService: OpenViduAngularConfigService,
private tokenService: TokenService,
private translateService: TranslateService private translateService: TranslateService
) { ) {
this.log = this.loggerSrv.get('VideoconferenceComponent'); this.log = this.loggerSrv.get('VideoconferenceComponent');

View File

@ -35,7 +35,6 @@ import { ParticipantService } from './services/participant/participant.service';
import { PlatformService } from './services/platform/platform.service'; import { PlatformService } from './services/platform/platform.service';
import { RecordingService } from './services/recording/recording.service'; import { RecordingService } from './services/recording/recording.service';
import { StorageService } from './services/storage/storage.service'; import { StorageService } from './services/storage/storage.service';
import { TokenService } from './services/token/token.service';
import { AudioWaveComponent } from './components/audio-wave/audio-wave.component'; import { AudioWaveComponent } from './components/audio-wave/audio-wave.component';
import { PanelComponent } from './components/panel/panel.component'; import { PanelComponent } from './components/panel/panel.component';
@ -132,7 +131,6 @@ const privateComponents = [
PlatformService, PlatformService,
ParticipantService, ParticipantService,
StorageService, StorageService,
TokenService,
OpenViduService, OpenViduService,
RecordingService RecordingService
], ],

View File

@ -1,5 +1,14 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Connection, OpenVidu, OpenViduError, OpenViduErrorName, Publisher, PublisherProperties, Session, SignalOptions } from 'openvidu-browser'; import {
Connection,
OpenVidu,
OpenViduError,
OpenViduErrorName,
Publisher,
PublisherProperties,
Session,
SignalOptions
} from 'openvidu-browser';
import { LoggerService } from '../logger/logger.service'; import { LoggerService } from '../logger/logger.service';
@ -12,13 +21,14 @@ import { OpenViduAngularConfigService } from '../config/openvidu-angular.config.
import { DeviceService } from '../device/device.service'; import { DeviceService } from '../device/device.service';
import { ParticipantService } from '../participant/participant.service'; import { ParticipantService } from '../participant/participant.service';
import { PlatformService } from '../platform/platform.service'; import { PlatformService } from '../platform/platform.service';
import { TokenService } from '../token/token.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class OpenViduService { export class OpenViduService {
private ovEdition: OpenViduEdition; private ovEdition: OpenViduEdition;
private webcamToken = '';
private screenToken = '';
protected OV: OpenVidu; protected OV: OpenVidu;
protected OVScreen: OpenVidu; protected OVScreen: OpenVidu;
protected webcamSession: Session; protected webcamSession: Session;
@ -35,8 +45,7 @@ export class OpenViduService {
protected platformService: PlatformService, protected platformService: PlatformService,
protected loggerSrv: LoggerService, protected loggerSrv: LoggerService,
private participantService: ParticipantService, private participantService: ParticipantService,
protected deviceService: DeviceService, protected deviceService: DeviceService
protected tokenService: TokenService
) { ) {
this.log = this.loggerSrv.get('OpenViduService'); this.log = this.loggerSrv.get('OpenViduService');
} }
@ -62,6 +71,34 @@ export class OpenViduService {
} }
} }
/**
* @internal
*/
setWebcamToken(token: string) {
this.webcamToken = token;
}
/**
* @internal
*/
setScreenToken(token: string) {
this.screenToken = token;
}
/**
* @internal
*/
getWebcamToken(): string {
return this.webcamToken;
}
/**
* @internal
*/
getScreenToken(): string {
return this.screenToken;
}
/** /**
* @internal * @internal
*/ */
@ -268,8 +305,7 @@ export class OpenViduService {
// Enabling webcam // Enabling webcam
const hasAudio = this.participantService.hasScreenAudioActive(); const hasAudio = this.participantService.hasScreenAudioActive();
if (!this.isWebcamSessionConnected()) { if (!this.isWebcamSessionConnected()) {
//TODO: should be the token in the participant? await this.connectSession(this.getWebcamSession(), this.getWebcamToken());
await this.connectSession(this.getWebcamSession(), this.tokenService.getWebcamToken());
} }
await this.publish(this.participantService.getMyCameraPublisher()); await this.publish(this.participantService.getMyCameraPublisher());
await this.publishVideoAux(this.participantService.getMyCameraPublisher(), true); await this.publishVideoAux(this.participantService.getMyCameraPublisher(), true);
@ -288,10 +324,10 @@ export class OpenViduService {
private async publishVideoAux(publisher: Publisher, publish: boolean): Promise<void> { private async publishVideoAux(publisher: Publisher, publish: boolean): Promise<void> {
if (!!publisher) { if (!!publisher) {
let resource: boolean | MediaStreamTrack = true; let resource: boolean | MediaStreamTrack = true;
if(publish){ if (publish) {
// Forcing restoration with a custom media stream (the older one instead the default) // Forcing restoration with a custom media stream (the older one instead the default)
const currentDeviceId = this.deviceService.getCameraSelected()?.device; const currentDeviceId = this.deviceService.getCameraSelected()?.device;
const mediaStream = await this.createMediaStream({videoSource: currentDeviceId, audioSource: false}); const mediaStream = await this.createMediaStream({ videoSource: currentDeviceId, audioSource: false });
resource = mediaStream.getVideoTracks()[0]; resource = mediaStream.getVideoTracks()[0];
} }
@ -354,7 +390,7 @@ export class OpenViduService {
this.participantService.activeMyScreenShare(screenPublisher); this.participantService.activeMyScreenShare(screenPublisher);
if (!this.isScreenSessionConnected()) { if (!this.isScreenSessionConnected()) {
await this.connectSession(this.getScreenSession(), this.tokenService.getScreenToken()); await this.connectSession(this.getScreenSession(), this.getScreenToken());
} }
await this.publish(this.participantService.getMyScreenPublisher()); await this.publish(this.participantService.getMyScreenPublisher());
if (!this.participantService.isMyVideoActive()) { if (!this.participantService.isMyVideoActive()) {
@ -373,7 +409,7 @@ export class OpenViduService {
// Enable webcam // Enable webcam
if (!this.isWebcamSessionConnected()) { if (!this.isWebcamSessionConnected()) {
await this.connectSession(this.getWebcamSession(), this.tokenService.getWebcamToken()); await this.connectSession(this.getWebcamSession(), this.getWebcamToken());
} }
await this.publish(this.participantService.getMyCameraPublisher()); await this.publish(this.participantService.getMyCameraPublisher());
this.publishAudioAux(this.participantService.getMyCameraPublisher(), hasAudio); this.publishAudioAux(this.participantService.getMyCameraPublisher(), hasAudio);

View File

@ -1,19 +0,0 @@
import { Injectable } from '@angular/core';
@Injectable()
export class TokenServiceMock {
constructor() {}
setWebcamToken(token: string) {}
setScreenToken(token: string) {}
getWebcamToken(): string {
return '';
}
getScreenToken(): string {
return '';
}
}

View File

@ -1,22 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { LoggerService } from '../logger/logger.service';
import { LoggerServiceMock } from '../logger/logger.service.mock';
import { TokenService } from './token.service';
describe('TokenService', () => {
let service: TokenService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{ provide: LoggerService, useClass: LoggerServiceMock }
]
});
service = TestBed.inject(TokenService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -1,30 +0,0 @@
import { Injectable } from '@angular/core';
/**
* @internal
*/
@Injectable({
providedIn: 'root'
})
export class TokenService {
private webcamToken = '';
private screenToken = '';
constructor() {}
setWebcamToken(token: string) {
this.webcamToken = token;
}
setScreenToken(token: string) {
this.screenToken = token;
}
getWebcamToken(): string {
return this.webcamToken;
}
getScreenToken(): string {
return this.screenToken;
}
}

View File

@ -1,9 +1,9 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs'; import { BehaviorSubject, Observable } from 'rxjs';
import { BackgroundEffect, EffectType } from '../../models/background-effect.model'; import { BackgroundEffect, EffectType } from '../../models/background-effect.model';
import { OpenViduService } from '../openvidu/openvidu.service';
import { ParticipantService } from '../participant/participant.service'; import { ParticipantService } from '../participant/participant.service';
import { StorageService } from '../storage/storage.service'; import { StorageService } from '../storage/storage.service';
import { TokenService } from '../token/token.service';
/** /**
* @internal * @internal
@ -41,7 +41,7 @@ export class VirtualBackgroundService {
constructor( constructor(
private participantService: ParticipantService, private participantService: ParticipantService,
private storageService: StorageService, private storageService: StorageService,
private tokenService: TokenService private openviduService: OpenViduService
) { ) {
this.backgroundSelectedObs = this.backgroundSelected.asObservable(); this.backgroundSelectedObs = this.backgroundSelected.asObservable();
} }
@ -69,7 +69,7 @@ export class VirtualBackgroundService {
if (bg.id !== this.backgroundSelected.getValue()) { if (bg.id !== this.backgroundSelected.getValue()) {
const filter = this.participantService.getMyCameraPublisher().stream.filter; const filter = this.participantService.getMyCameraPublisher().stream.filter;
const isBackgroundSelected = !!filter && filter.type.startsWith('VB:'); const isBackgroundSelected = !!filter && filter.type.startsWith('VB:');
let options = { token: this.tokenService.getWebcamToken(), url: '' }; let options = { token: this.openviduService.getWebcamToken(), url: '' };
if (bg.type === EffectType.IMAGE) { if (bg.type === EffectType.IMAGE) {
options.url = bg.src; options.url = bg.src;
} }