@@ -44,6 +44,9 @@ export class Remote {
4444 return remoteTrack ;
4545 } ;
4646
47+ public getTrackByMidOrNull = ( mid : string ) : RemoteTrack | null =>
48+ Object . values ( this . remoteTracks ) . find ( ( remote ) => remote . mLineId === mid ) ?? null ;
49+
4750 public addTracks = ( endpointId : EndpointId , tracks : Record < TrackId , MediaEvent_Track > ) => {
4851 const endpoint : EndpointWithTrackContext | undefined = this . remoteEndpoints [ endpointId ] ;
4952
@@ -72,10 +75,18 @@ export class Remote {
7275
7376 private removeRemoteTrack = ( trackId : TrackId ) => {
7477 const remoteTrack = this . remoteTracks [ trackId ] ;
75- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
78+ if ( ! remoteTrack ) {
79+ console . warn ( `Track ${ trackId } not found, skipping remove` ) ;
80+ return ;
81+ }
7682
7783 const remoteEndpoint = this . remoteEndpoints [ remoteTrack . trackContext . endpoint . id ] ;
78- if ( ! remoteEndpoint ) throw new Error ( `Endpoint ${ remoteTrack . trackContext . endpoint . id } not found` ) ;
84+ if ( ! remoteEndpoint ) {
85+ console . warn ( `Endpoint ${ remoteTrack . trackContext . endpoint . id } not found, skipping remove` ) ;
86+ delete this . remoteTracks [ trackId ] ;
87+ this . emit ( 'trackRemoved' , remoteTrack . trackContext ) ;
88+ return ;
89+ }
7990
8091 remoteEndpoint . tracks . delete ( trackId ) ;
8192 delete this . remoteTracks [ trackId ] ;
@@ -110,7 +121,10 @@ export class Remote {
110121
111122 public updateRemoteEndpoint = ( endpointId : string , metadataJson ?: MetadataJson ) => {
112123 const endpoint : EndpointWithTrackContext | undefined = this . remoteEndpoints [ endpointId ] ;
113- if ( ! endpoint ) throw new Error ( `Endpoint ${ endpointId } not found` ) ;
124+ if ( ! endpoint ) {
125+ console . warn ( `Endpoint ${ endpointId } not found, skipping update` ) ;
126+ return ;
127+ }
114128
115129 endpoint . metadata = metadataJson ? JSON . parse ( metadataJson ) : undefined ;
116130
@@ -119,7 +133,10 @@ export class Remote {
119133
120134 public removeRemoteEndpoint = ( endpointId : EndpointId ) => {
121135 const endpoint : EndpointWithTrackContext | undefined = this . remoteEndpoints [ endpointId ] ;
122- if ( ! endpoint ) throw new Error ( `Endpoint ${ endpointId } not found` ) ;
136+ if ( ! endpoint ) {
137+ console . warn ( `Endpoint ${ endpointId } not found, skipping remove` ) ;
138+ return ;
139+ }
123140
124141 const trackIds = [ ...endpoint . tracks . values ( ) ] . map ( ( { trackId } ) => trackId ) ;
125142
@@ -131,10 +148,16 @@ export class Remote {
131148 } ;
132149
133150 public updateRemoteTrack = ( endpointId : string , trackId : string , metadataJson ?: MetadataJson ) => {
134- if ( ! this . remoteEndpoints [ endpointId ] ) throw new Error ( `Endpoint ${ endpointId } not found` ) ;
151+ if ( ! this . remoteEndpoints [ endpointId ] ) {
152+ console . warn ( `Endpoint ${ endpointId } not found, skipping track update` ) ;
153+ return ;
154+ }
135155
136156 const remoteTrack = this . remoteTracks [ trackId ] ;
137- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
157+ if ( ! remoteTrack ) {
158+ console . warn ( `Track ${ trackId } not found, skipping update` ) ;
159+ return ;
160+ }
138161
139162 remoteTrack . trackContext . metadata = metadataJson ? JSON . parse ( metadataJson ) : undefined ;
140163
@@ -143,7 +166,10 @@ export class Remote {
143166
144167 public disableRemoteTrackEncoding = ( trackId : TrackId , encoding : Variant ) => {
145168 const remoteTrack = this . remoteTracks [ trackId ] ;
146- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
169+ if ( ! remoteTrack ) {
170+ console . warn ( `Track ${ trackId } not found, skipping disableEncoding` ) ;
171+ return ;
172+ }
147173
148174 remoteTrack . disableTrackEncoding ( encoding ) ;
149175
@@ -152,7 +178,10 @@ export class Remote {
152178
153179 public enableRemoteTrackEncoding = ( trackId : TrackId , encoding : Variant ) => {
154180 const remoteTrack = this . remoteTracks [ trackId ] ;
155- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
181+ if ( ! remoteTrack ) {
182+ console . warn ( `Track ${ trackId } not found, skipping enableEncoding` ) ;
183+ return ;
184+ }
156185
157186 remoteTrack . enableTrackEncoding ( encoding ) ;
158187
@@ -161,7 +190,10 @@ export class Remote {
161190
162191 public setRemoteTrackEncoding = ( trackId : TrackId , encoding : Variant , reason ?: EncodingReason ) => {
163192 const remoteTrack = this . remoteTracks [ trackId ] ;
164- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
193+ if ( ! remoteTrack ) {
194+ console . warn ( `Track ${ trackId } not found, skipping setEncoding` ) ;
195+ return ;
196+ }
165197
166198 remoteTrack . trackContext . encoding = encoding ;
167199 remoteTrack . trackContext . encodingReason = reason ;
@@ -171,7 +203,10 @@ export class Remote {
171203
172204 public setRemoteTrackVadStatus = ( trackId : TrackId , vadStatus : MediaEvent_VadNotification_Status ) => {
173205 const remoteTrack = this . remoteTracks [ trackId ] ;
174- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
206+ if ( ! remoteTrack ) {
207+ console . warn ( `Track ${ trackId } not found, skipping vad status update` ) ;
208+ return ;
209+ }
175210
176211 let nextStatus : VadStatus | null = null ;
177212
@@ -208,7 +243,10 @@ export class Remote {
208243
209244 public setTargetRemoteTrackEncoding = ( trackId : TrackId , variant : Variant ) => {
210245 const remoteTrack = this . remoteTracks [ trackId ] ;
211- if ( ! remoteTrack ) throw new Error ( `Track ${ trackId } not found` ) ;
246+ if ( ! remoteTrack ) {
247+ console . warn ( `Track ${ trackId } not found, skipping setTargetEncoding` ) ;
248+ return ;
249+ }
212250
213251 try {
214252 remoteTrack . setTargetTrackEncoding ( variant ) ;
0 commit comments