@@ -129,29 +129,26 @@ export default class RemoteTrackPublication extends TrackPublication {
129
129
setTrack ( track ?: RemoteTrack ) {
130
130
const prevStatus = this . subscriptionStatus ;
131
131
const prevTrack = this . track ;
132
+ if ( prevTrack === track ) {
133
+ return ;
134
+ }
132
135
if ( prevTrack ) {
133
136
// unregister listener
134
137
prevTrack . off ( TrackEvent . VideoDimensionsChanged , this . handleVideoDimensionsChange ) ;
135
138
prevTrack . off ( TrackEvent . VisibilityChanged , this . handleVisibilityChange ) ;
136
139
prevTrack . off ( TrackEvent . Ended , this . handleEnded ) ;
137
140
prevTrack . detach ( ) ;
141
+ this . emit ( TrackEvent . Unsubscribed , prevTrack ) ;
138
142
}
139
143
super . setTrack ( track ) ;
140
144
if ( track ) {
141
145
track . sid = this . trackSid ;
142
146
track . on ( TrackEvent . VideoDimensionsChanged , this . handleVideoDimensionsChange ) ;
143
147
track . on ( TrackEvent . VisibilityChanged , this . handleVisibilityChange ) ;
144
148
track . on ( TrackEvent . Ended , this . handleEnded ) ;
149
+ this . emit ( TrackEvent . Subscribed , track ) ;
145
150
}
146
151
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
- }
155
152
}
156
153
157
154
/** @internal */
0 commit comments