From 40df8ebe69f0a6983f28e81ac67129aa4ec7f37e Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Tue, 14 Jan 2025 18:21:43 +0530 Subject: [PATCH] fix: video not publishing on sfu migration --- .../src/media/tracks/HMSLocalAudioTrack.ts | 14 ++++++-------- .../src/media/tracks/HMSLocalVideoTrack.ts | 15 +++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 6cadd54b9f..31d2e026a4 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -72,14 +72,12 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } clone(stream: HMSLocalStream) { - const track = new HMSLocalAudioTrack( - stream, - this.nativeTrack.clone(), - this.source!, - this.eventBus, - this.settings, - this.room, - ); + const clonedTrack = this.nativeTrack.clone(); + /** + * stream only becomes active when the track is added to it. + */ + stream.nativeStream.addTrack(clonedTrack); + const track = new HMSLocalAudioTrack(stream, clonedTrack, this.source!, this.eventBus, this.settings, this.room); track.peerId = this.peerId; if (this.pluginsManager.pluginsMap.size > 0) { diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 3a1399d9a2..7a0a3dae3c 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -93,14 +93,13 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { } clone(stream: HMSLocalStream) { - const track = new HMSLocalVideoTrack( - stream, - this.nativeTrack.clone(), - this.source!, - this.eventBus, - this.settings, - this.room, - ); + const clonedTrack = this.nativeTrack.clone(); + /** + * stream only becomes active when the track is added to it. If this is not added, after sfu migration, in non-simulcast case, the video will not be + * published to the server + */ + stream.nativeStream.addTrack(clonedTrack); + const track = new HMSLocalVideoTrack(stream, clonedTrack, this.source!, this.eventBus, this.settings, this.room); track.peerId = this.peerId; if (this.pluginsManager.pluginsMap.size > 0) {