File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed
Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " livekit-client " : patch
3+ ---
4+
5+ fix: remove track from transceiver if add request failed
Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
330330 reject (
331331 new ConnectionError (
332332 'publication of local track timed out, no response from server' ,
333- ConnectionErrorReason . InternalError ,
333+ ConnectionErrorReason . Timeout ,
334334 ) ,
335335 ) ;
336336 } , 10_000 ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export enum ConnectionErrorReason {
1616 InternalError ,
1717 Cancelled ,
1818 LeaveRequest ,
19+ Timeout ,
1920}
2021
2122export class ConnectionError extends LivekitError {
Original file line number Diff line number Diff line change @@ -1142,11 +1142,32 @@ export default class LocalParticipant extends Participant {
11421142 } ;
11431143
11441144 let ti : TrackInfo ;
1145+ const addTrackPromise = new Promise < TrackInfo > ( async ( resolve , reject ) => {
1146+ try {
1147+ ti = await this . engine . addTrack ( req ) ;
1148+ resolve ( ti ) ;
1149+ } catch ( err ) {
1150+ if ( track . sender && this . engine . pcManager ?. publisher ) {
1151+ this . engine . pcManager . publisher . removeTrack ( track . sender ) ;
1152+ await this . engine . negotiate ( ) . catch ( ( negotiateErr ) => {
1153+ this . log . error (
1154+ 'failed to negotiate after removing track due to failed add track request' ,
1155+ {
1156+ ...this . logContext ,
1157+ ...getLogContextFromTrack ( track ) ,
1158+ error : negotiateErr ,
1159+ } ,
1160+ ) ;
1161+ } ) ;
1162+ }
1163+ reject ( err ) ;
1164+ }
1165+ } ) ;
11451166 if ( this . enabledPublishVideoCodecs . length > 0 ) {
1146- const rets = await Promise . all ( [ this . engine . addTrack ( req ) , negotiate ( ) ] ) ;
1167+ const rets = await Promise . all ( [ addTrackPromise , negotiate ( ) ] ) ;
11471168 ti = rets [ 0 ] ;
11481169 } else {
1149- ti = await this . engine . addTrack ( req ) ;
1170+ ti = await addTrackPromise ;
11501171 // server might not support the codec the client has requested, in that case, fallback
11511172 // to a supported codec
11521173 let primaryCodecMime : string | undefined ;
You can’t perform that action at this time.
0 commit comments