import { Component, OnDestroy, OnInit } from '@angular/core'; import { ParticipantAbstractModel, ParticipantService, TokenModel } from 'openvidu-angular'; import { Subscription } from 'rxjs'; import { RestService } from 'src/app/services/rest.service'; @Component({ selector: 'app-participantPanelItem-directive', template: `
`, styles: [``] }) export class ParticipantPanelItemDirectiveComponent implements OnInit, OnDestroy { tokens: TokenModel; sessionId = 'participants-panel-directive-example'; OPENVIDU_URL = 'https://localhost:4443'; OPENVIDU_SECRET = 'MY_SECRET'; localParticipant: ParticipantAbstractModel; remoteParticipants: ParticipantAbstractModel[]; localParticipantSubs: Subscription; remoteParticipantsSubs: Subscription; constructor(private restService: RestService, private participantService: ParticipantService) {} ngOnInit(): void { this.subscribeToParticipants(); } ngOnDestroy() { this.localParticipantSubs.unsubscribe(); this.remoteParticipantsSubs.unsubscribe(); } async onJoinButtonClicked() { this.tokens = { webcam: await this.restService.getToken(this.sessionId, this.OPENVIDU_URL, this.OPENVIDU_SECRET), screen: await this.restService.getToken(this.sessionId, this.OPENVIDU_URL, this.OPENVIDU_SECRET) }; } subscribeToParticipants() { this.localParticipantSubs = this.participantService.localParticipantObs.subscribe((p) => { this.localParticipant = p; }); this.remoteParticipantsSubs = this.participantService.remoteParticipantsObs.subscribe((participants) => { this.remoteParticipants = participants; }); } }