mirror of https://github.com/OpenVidu/openvidu.git
openvidu-components: Disposed MediaStream when component is destroyed
parent
56ce32729d
commit
e3340171a0
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue