diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts index 8964088a..52e0c0b9 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/components/pre-join/pre-join.component.ts @@ -98,15 +98,9 @@ export class PreJoinComponent implements OnInit, OnDestroy { this.isLoading = false; } - ngOnDestroy() { - if (this.localParticipantSubscription) { - this.localParticipantSubscription.unsubscribe(); - } - - if (this.screenShareStateSubscription) { - this.screenShareStateSubscription.unsubscribe(); - } - + async ngOnDestroy() { + if (this.localParticipantSubscription) this.localParticipantSubscription.unsubscribe(); + if (this.screenShareStateSubscription) this.screenShareStateSubscription.unsubscribe(); if (this.backgroundEffectsButtonSub) this.backgroundEffectsButtonSub.unsubscribe(); if (this.minimalSub) this.minimalSub.unsubscribe(); } @@ -124,12 +118,11 @@ export class PreJoinComponent implements OnInit, OnDestroy { // Reapply Virtual Background to new Publisher if necessary const backgroundSelected = this.backgroundService.backgroundSelected.getValue(); - const backgroundWasApplied = !!backgroundSelected && backgroundSelected !== 'no_effect'; - if (backgroundWasApplied) { + if (this.backgroundService.isBackgroundApplied()) { await this.backgroundService.removeBackground(); } await this.openviduService.republishTrack(pp); - if (backgroundWasApplied) { + if (this.backgroundService.isBackgroundApplied()) { await this.backgroundService.applyBackground(this.backgroundService.backgrounds.find(b => b.id === backgroundSelected)); } 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 87c597cc..656b3df6 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 @@ -414,11 +414,11 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni } } - ngOnDestroy(): void { + async ngOnDestroy() { if (this.prejoinSub) this.prejoinSub.unsubscribe(); if (this.participantNameSub) this.participantNameSub.unsubscribe(); this.deviceSrv.clear(); - this.openviduService.clear(); + await this.openviduService.clear(); } /** diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/openvidu/openvidu.service.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/openvidu/openvidu.service.ts index 28de1bcb..59c26a9c 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/openvidu/openvidu.service.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/openvidu/openvidu.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Connection, OpenVidu, Publisher, PublisherProperties, Session, SignalOptions } from 'openvidu-browser'; +import { Connection, OpenVidu, Publisher, PublisherProperties, Session, SignalOptions, Stream } from 'openvidu-browser'; import { LoggerService } from '../logger/logger.service'; @@ -84,11 +84,11 @@ export class OpenViduService { /** * @internal */ - clear() { + async clear() { this.videoSource = undefined; this.audioSource = undefined; - this.stopTracks(this.participantService.getMyCameraPublisher()?.stream?.getMediaStream()); - this.stopTracks(this.participantService.getMyScreenPublisher()?.stream?.getMediaStream()); + await this.participantService.getMyCameraPublisher()?.stream?.disposeMediaStream(); + await this.participantService.getMyScreenPublisher()?.stream?.disposeMediaStream(); } /** @@ -592,12 +592,4 @@ export class OpenViduService { } } } - - private stopTracks(mediaStream: MediaStream) { - if (mediaStream) { - mediaStream?.getAudioTracks().forEach((track) => track.stop()); - mediaStream?.getVideoTracks().forEach((track) => track.stop()); - // this.webcamMediaStream?.getAudioTracks().forEach((track) => track.stop()); - } - } } diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/virtual-background/virtual-background.service.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/virtual-background/virtual-background.service.ts index 10cc26e9..c33f1942 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/services/virtual-background/virtual-background.service.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/services/virtual-background/virtual-background.service.ts @@ -42,6 +42,11 @@ export class VirtualBackgroundService { return this.backgrounds; } + isBackgroundApplied(): boolean { + const bgSelected = this.backgroundSelected.getValue(); + return !!bgSelected && bgSelected !== 'no_effect'; + } + async applyBackground(effect: BackgroundEffect) { if (effect.id !== this.backgroundSelected.getValue()) { const filter = this.participantService.getMyCameraPublisher().stream.filter; @@ -62,7 +67,7 @@ export class VirtualBackgroundService { } async removeBackground() { - if (!!this.backgroundSelected.getValue() && this.backgroundSelected.getValue() !== 'no_effect') { + if (!!this.isBackgroundApplied()) { this.backgroundSelected.next('no_effect'); await this.participantService.getMyCameraPublisher().stream.removeFilter(); }