File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @livekit/agents " : patch
3+ ---
4+
5+ Handle participant disconnect during init
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import type { WritableStreamDefaultWriter } from 'node:stream/web';
2121import { ATTRIBUTE_PUBLISH_ON_BEHALF , TOPIC_CHAT } from '../../constants.js' ;
2222import { log } from '../../log.js' ;
2323import { IdentityTransform } from '../../stream/identity_transform.js' ;
24- import { Future , Task } from '../../utils.js' ;
24+ import { Future , Task , waitForAbort } from '../../utils.js' ;
2525import { type AgentSession } from '../agent_session.js' ;
2626import {
2727 AgentSessionEventTypes ,
@@ -177,7 +177,10 @@ export class RoomIO {
177177 : this . inputOptions . participantIdentity ?? null ;
178178 }
179179 private async init ( signal : AbortSignal ) : Promise < void > {
180- await this . roomConnectedFuture . await ;
180+ await Promise . race ( [ this . roomConnectedFuture . await , waitForAbort ( signal ) ] ) ;
181+ if ( signal . aborted ) {
182+ return ;
183+ }
181184
182185 for ( const participant of this . room . remoteParticipants . values ( ) ) {
183186 this . onParticipantConnected ( participant ) ;
@@ -186,7 +189,15 @@ export class RoomIO {
186189 return ;
187190 }
188191
189- const participant = await this . participantAvailableFuture . await ;
192+ const participant = await Promise . race ( [
193+ this . participantAvailableFuture . await ,
194+ waitForAbort ( signal ) ,
195+ ] ) ;
196+
197+ if ( ! participant ) {
198+ return ;
199+ }
200+
190201 this . setParticipant ( participant . identity ) ;
191202
192203 // init agent outputs
You can’t perform that action at this time.
0 commit comments