File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ export class OlmAdapter extends Listenable {
141141 await this . _init ;
142142
143143 const promises = [ ] ;
144+ const participantsToWaitFor = [ ] ;
144145
145146 for ( const participant of this . _conf . getParticipants ( ) ) {
146147 const pId = participant . getId ( ) ;
@@ -157,20 +158,32 @@ export class OlmAdapter extends Listenable {
157158 }
158159
159160 // Need to wait for session to be established
161+ participantsToWaitFor . push ( pId ) ;
160162 const sessionPromise = new Promise ( resolve => {
161163 this . _sessionReadyCallbacks . set ( pId , resolve ) ;
162164 } ) ;
163165
164166 promises . push ( sessionPromise ) ;
165167 }
166168
169+ if ( promises . length === 0 ) {
170+ logger . debug ( 'All sessions already established' ) ;
171+
172+ return ;
173+ }
174+
175+ logger . debug ( `Waiting for ${ promises . length } sessions to be established` ) ;
176+
167177 // Wait for all pending sessions with a timeout
168178 await Promise . race ( [
169179 Promise . allSettled ( promises ) ,
170180 new Promise ( resolve => setTimeout ( resolve , 10000 ) ) // 10s timeout
171181 ] ) ;
172182
173- logger . debug ( `All sessions ready, total participants: ${ this . _conf . getParticipants ( ) . length } ` ) ;
183+ // Clean up any remaining callbacks (e.g., if timeout fired before sessions completed)
184+ for ( const pId of participantsToWaitFor ) {
185+ this . _sessionReadyCallbacks . delete ( pId ) ;
186+ }
174187 }
175188
176189 /**
You can’t perform that action at this time.
0 commit comments