Skip to content

Commit 84a96b2

Browse files
fix video track lost for migration on safari (#419)
* don't detach track when same mediatrack received * changeset * attempt Co-authored-by: David Zhao <[email protected]>
1 parent e00bee8 commit 84a96b2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

.changeset/six-insects-enjoy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'livekit-client': patch
3+
---
4+
5+
fix video track lost for safari migration

src/room/track/RemoteTrackPublication.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,26 @@ export default class RemoteTrackPublication extends TrackPublication {
129129
setTrack(track?: RemoteTrack) {
130130
const prevStatus = this.subscriptionStatus;
131131
const prevTrack = this.track;
132+
if (prevTrack === track) {
133+
return;
134+
}
132135
if (prevTrack) {
133136
// unregister listener
134137
prevTrack.off(TrackEvent.VideoDimensionsChanged, this.handleVideoDimensionsChange);
135138
prevTrack.off(TrackEvent.VisibilityChanged, this.handleVisibilityChange);
136139
prevTrack.off(TrackEvent.Ended, this.handleEnded);
137140
prevTrack.detach();
141+
this.emit(TrackEvent.Unsubscribed, prevTrack);
138142
}
139143
super.setTrack(track);
140144
if (track) {
141145
track.sid = this.trackSid;
142146
track.on(TrackEvent.VideoDimensionsChanged, this.handleVideoDimensionsChange);
143147
track.on(TrackEvent.VisibilityChanged, this.handleVisibilityChange);
144148
track.on(TrackEvent.Ended, this.handleEnded);
149+
this.emit(TrackEvent.Subscribed, track);
145150
}
146151
this.emitSubscriptionUpdateIfChanged(prevStatus);
147-
if (!!track !== !!prevTrack) {
148-
// when undefined status changes, there's a subscription changed event
149-
if (track) {
150-
this.emit(TrackEvent.Subscribed, track);
151-
} else if (prevTrack) {
152-
this.emit(TrackEvent.Unsubscribed, prevTrack);
153-
}
154-
}
155152
}
156153

157154
/** @internal */

0 commit comments

Comments
 (0)