From 9cdc5334e0e4c4cbaf5be2528e31d80984882ef1 Mon Sep 17 00:00:00 2001 From: KaustubhKumar05 Date: Tue, 24 Sep 2024 15:38:47 +0530 Subject: [PATCH 1/3] fix: clean up mediastream plugins --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 1 + .../src/plugins/video/HMSMediaStreamPluginsManager.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 5e5090ecd8..7d643c5a2f 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -264,6 +264,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { super.cleanup(); this.transceiver = undefined; await this.pluginsManager.cleanup(); + await this.mediaStreamPluginsManager.cleanup(); this.processedTrack?.stop(); this.isPublished = false; if (isBrowser && isMobile()) { diff --git a/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts b/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts index 1991355757..451050bf8f 100644 --- a/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts +++ b/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts @@ -63,4 +63,8 @@ export class HMSMediaStreamPluginsManager { getPlugins(): string[] { return Array.from(this.plugins).map(plugin => plugin.getName()); } + + async cleanup() { + this.plugins.forEach(plugin => plugin.stop()); + } } From d5896a8b1584fb4457e0b508214e7102cb91bed7 Mon Sep 17 00:00:00 2001 From: KaustubhKumar05 Date: Tue, 24 Sep 2024 16:40:02 +0530 Subject: [PATCH 2/3] fix: cleanup order --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 4 ++-- .../src/plugins/video/HMSMediaStreamPluginsManager.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 7d643c5a2f..aa7a208a23 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -261,10 +261,10 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { */ async cleanup() { this.removeTrackEventListeners(this.nativeTrack); + await this.mediaStreamPluginsManager.cleanup(); + await this.pluginsManager.cleanup(); super.cleanup(); this.transceiver = undefined; - await this.pluginsManager.cleanup(); - await this.mediaStreamPluginsManager.cleanup(); this.processedTrack?.stop(); this.isPublished = false; if (isBrowser && isMobile()) { diff --git a/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts b/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts index 451050bf8f..5bc32bcfcf 100644 --- a/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts +++ b/packages/hms-video-store/src/plugins/video/HMSMediaStreamPluginsManager.ts @@ -65,6 +65,6 @@ export class HMSMediaStreamPluginsManager { } async cleanup() { - this.plugins.forEach(plugin => plugin.stop()); + this.removePlugins(Array.from(this.plugins)); } } From 8ef5451c70a1b3c7d33aa327930845ed871ac02e Mon Sep 17 00:00:00 2001 From: KaustubhKumar05 Date: Tue, 8 Oct 2024 17:45:55 +0530 Subject: [PATCH 3/3] fix: add comment to elaborate on cleanup order --- packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index aa7a208a23..8e4a659448 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -261,6 +261,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { */ async cleanup() { this.removeTrackEventListeners(this.nativeTrack); + // Stopping the plugin before cleaning the track is more predictable when dealing with 3rd party plugins await this.mediaStreamPluginsManager.cleanup(); await this.pluginsManager.cleanup(); super.cleanup();