@@ -16,7 +16,7 @@ import {
1616 type RoomMember ,
1717} from "matrix-js-sdk/src/matrix" ;
1818import { KnownMembership , type Membership } from "matrix-js-sdk/src/types" ;
19- import { logger } from "matrix-js-sdk/src/logger" ;
19+ import { logger as rootLogger } from "matrix-js-sdk/src/logger" ;
2020import { secureRandomString } from "matrix-js-sdk/src/randomstring" ;
2121import { CallType } from "matrix-js-sdk/src/webrtc/call" ;
2222import { type IWidgetApiRequest , type ClientWidgetApi , type IWidgetData } from "matrix-widget-api" ;
@@ -46,6 +46,7 @@ import DMRoomMap from "../utils/DMRoomMap.ts";
4646import { type WidgetMessaging , WidgetMessagingEvent } from "../stores/widgets/WidgetMessaging.ts" ;
4747
4848const TIMEOUT_MS = 16000 ;
49+ const logger = rootLogger . getChild ( "models/Call" ) ;
4950
5051// Waits until an event is emitted satisfying the given predicate
5152const waitForEvent = async (
@@ -219,38 +220,50 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
219220 public async start ( _params ?: WidgetGenerationParameters ) : Promise < ClientWidgetApi > {
220221 const messagingStore = WidgetMessagingStore . instance ;
221222 const startTime = performance . now ( ) ;
222- let messaging : WidgetMessaging | undefined ;
223+ let messaging : WidgetMessaging | undefined = messagingStore . getMessagingForUid ( this . widgetUid ) ;
223224 // The widget might still be initializing, so wait for it in an async
224225 // event loop. We need the messaging to be both present and started, so
225226 // we register listeners for both cases. Note that due to React strict
226227 // mode, the messaging could even be aborted and replaced by an entirely
227228 // new messaging while we are waiting here!
228- while ( ! messaging ?. widgetApi ) {
229- messaging = messagingStore . getMessagingForUid ( this . widgetUid ) ;
229+ while ( ! messaging ) {
230+ logger . info ( `No messaging for ${ this . widgetUid } ` ) ;
230231 await new Promise < void > ( ( resolve , reject ) => {
231- const onStart = ( ) : void => resolve ( ) ;
232- messaging ?. on ( WidgetMessagingEvent . Start , onStart ) ;
233-
232+ // We don't have `messaging` either so wait for the
234233 const onStoreMessaging = ( uid : string , m : WidgetMessaging ) : void => {
235234 if ( uid === this . widgetUid ) {
235+ messagingStore . off ( WidgetMessagingStoreEvent . StoreMessaging , onStoreMessaging ) ;
236236 messaging = m ;
237237 resolve ( ) ;
238238 }
239239 } ;
240240 messagingStore . on ( WidgetMessagingStoreEvent . StoreMessaging , onStoreMessaging ) ;
241241
242242 setTimeout (
243- ( ) =>
244- reject (
245- new Error (
246- `Messaging for call in ${ this . roomId } ${ messaging ? "did not start" : "not present" } ; timed out` ,
247- ) ,
248- ) ,
243+ ( ) => {
244+ messagingStore . off ( WidgetMessagingStoreEvent . StoreMessaging , onStoreMessaging ) ;
245+ reject ( new Error ( `Messaging for call in ${ this . roomId } not present; timed out` ) ) ;
246+ } ,
247+ startTime + TIMEOUT_MS - performance . now ( ) ,
248+ ) ;
249+ } ) ;
250+ }
251+
252+ while ( ! messaging . widgetApi ) {
253+ const foundMessaging = messaging ;
254+ logger . info ( `No widgetApi for ${ this . widgetUid } ` ) ;
255+ await new Promise < void > ( ( resolve , reject ) => {
256+ // We have messasing but are waiting for the widgetApi
257+ foundMessaging . once ( WidgetMessagingEvent . Start , ( ) : void => resolve ( ) ) ;
258+
259+ setTimeout (
260+ ( ) => reject ( new Error ( `Messaging for call in ${ this . roomId } did not start; timed out` ) ) ,
249261 startTime + TIMEOUT_MS - performance . now ( ) ,
250262 ) ;
251263 } ) ;
252264 }
253- return this . widgetApi = messaging . widgetApi ;
265+ logger . debug ( `Widget ${ this . widgetUid } now ready` ) ;
266+ return ( this . widgetApi = messaging . widgetApi ) ;
254267 }
255268
256269 protected setConnected ( ) : void {
@@ -306,7 +319,7 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
306319
307320 private readonly onStopMessaging = ( uid : string ) : void => {
308321 if ( uid === this . widgetUid && this . connected ) {
309- logger . log ( "The widget died; treating this as a user hangup" ) ;
322+ logger . debug ( "The widget died; treating this as a user hangup" ) ;
310323 this . setDisconnected ( ) ;
311324 this . close ( ) ;
312325 }
@@ -526,7 +539,7 @@ export class JitsiCall extends Call {
526539 // Re-add this device every so often so our video member event doesn't become stale
527540 this . resendDevicesTimer = window . setInterval (
528541 async ( ) : Promise < void > => {
529- logger . log ( `Resending video member event for ${ this . roomId } ` ) ;
542+ logger . debug ( `Resending video member event for ${ this . roomId } ` ) ;
530543 await this . addOurDevice ( ) ;
531544 } ,
532545 ( this . STUCK_DEVICE_TIMEOUT_MS * 3 ) / 4 ,
0 commit comments