@@ -5,7 +5,11 @@ import { Mutex } from '@livekit/mutex';
55import { EncryptionState , type EncryptionType } from '@livekit/rtc-ffi-bindings' ;
66import type { FfiEvent } from '@livekit/rtc-ffi-bindings' ;
77import { DisconnectReason , type OwnedParticipant } from '@livekit/rtc-ffi-bindings' ;
8- import type { DataStream_Trailer , DisconnectCallback } from '@livekit/rtc-ffi-bindings' ;
8+ import type {
9+ DataStream_Trailer ,
10+ DisconnectCallback ,
11+ TrackPublicationInfo ,
12+ } from '@livekit/rtc-ffi-bindings' ;
913import {
1014 type ConnectCallback ,
1115 ConnectRequest ,
@@ -514,6 +518,19 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
514518 const publication = this . localParticipant . trackPublications . get ( ev . value . publicationSid ! ) ;
515519 this . localParticipant . trackPublications . delete ( ev . value . publicationSid ! ) ;
516520 this . emit ( RoomEvent . LocalTrackUnpublished , publication ! , this . localParticipant ! ) ;
521+ } else if ( ( ev . case as string ) == 'localTrackRepublished' ) {
522+ const value = ( ev as any ) . value ;
523+ const previousSid : string = value . previousSid ! ;
524+ const newInfo : TrackPublicationInfo = value . info ! ;
525+ const publication = this . localParticipant . trackPublications . get ( previousSid ) ;
526+ if ( publication ) {
527+ publication . updateInfo ( newInfo ) ;
528+ this . localParticipant . trackPublications . delete ( previousSid ) ;
529+ this . localParticipant . trackPublications . set ( publication . sid ! , publication ) ;
530+ this . emit ( RoomEvent . LocalTrackRepublished , publication , previousSid , this . localParticipant ) ;
531+ } else {
532+ log . warn ( `RoomEvent.LocalTrackRepublished: previous publication not found: ${ previousSid } ` ) ;
533+ }
517534 } else if ( ev . case == 'localTrackSubscribed' ) {
518535 const publication = this . localParticipant . trackPublications . get ( ev . value . trackSid ! ) ;
519536 if ( publication ) {
@@ -936,6 +953,18 @@ export type RoomCallbacks = {
936953 publication : LocalTrackPublication ,
937954 participant : LocalParticipant ,
938955 ) => void ;
956+ /**
957+ * Fired when the SDK auto-republished a local track during a full
958+ * reconnect. The publication object's identity is preserved (the same
959+ * instance is updated in place with the new server-assigned SIDs);
960+ * `previousSid` is provided for callers that key external state on the
961+ * old SID and need to reconcile.
962+ */
963+ localTrackRepublished : (
964+ publication : LocalTrackPublication ,
965+ previousSid : string ,
966+ participant : LocalParticipant ,
967+ ) => void ;
939968 localTrackSubscribed : ( track : LocalTrack ) => void ;
940969 trackPublished : ( publication : RemoteTrackPublication , participant : RemoteParticipant ) => void ;
941970 trackUnpublished : ( publication : RemoteTrackPublication , participant : RemoteParticipant ) => void ;
@@ -993,6 +1022,7 @@ export enum RoomEvent {
9931022 ParticipantDisconnected = 'participantDisconnected' ,
9941023 LocalTrackPublished = 'localTrackPublished' ,
9951024 LocalTrackUnpublished = 'localTrackUnpublished' ,
1025+ LocalTrackRepublished = 'localTrackRepublished' ,
9961026 LocalTrackSubscribed = 'localTrackSubscribed' ,
9971027 TrackPublished = 'trackPublished' ,
9981028 TrackUnpublished = 'trackUnpublished' ,
0 commit comments