diff --git a/.changeset/odd-sloths-reply.md b/.changeset/odd-sloths-reply.md new file mode 100644 index 0000000000..91cac90f6e --- /dev/null +++ b/.changeset/odd-sloths-reply.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +Handle reconnect case in onTrackAdded diff --git a/src/room/Room.ts b/src/room/Room.ts index 044085b7b3..58fd8dd64a 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -542,8 +542,8 @@ class Room extends (EventEmitter as new () => TypedEmitter) // at that time, ICE connectivity has not been established so the track is not // technically subscribed. // We'll defer these events until when the room is connected or eventually disconnected. - if (this.connectFuture) { - this.connectFuture.promise.then(() => { + if (this.connectFuture || this.reconnectFuture) { + Promise.allSettled([this.connectFuture?.promise, this.reconnectFuture?.promise]).then(() => { this.onTrackAdded(mediaTrack, stream, receiver); }); return;