From 2a348a0106095d466f17f0fa16ea44d05778a7c4 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Mon, 24 Aug 2026 13:37:05 +0200 Subject: [PATCH] fix(call): load the call iframe after the widget transport is listening --- .../plugins/call/CallEmbed.handshake.test.ts | 20 +++++++++++++++++++ src/app/plugins/call/CallEmbed.ts | 10 +++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/app/plugins/call/CallEmbed.handshake.test.ts diff --git a/src/app/plugins/call/CallEmbed.handshake.test.ts b/src/app/plugins/call/CallEmbed.handshake.test.ts new file mode 100644 index 000000000..f966821ad --- /dev/null +++ b/src/app/plugins/call/CallEmbed.handshake.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it, vi } from 'vitest'; + +vi.mock('../../utils/debugLogger', () => ({ + createDebugLogger: () => ({ + info: vi.fn<(...args: unknown[]) => void>(), + warn: vi.fn<(...args: unknown[]) => void>(), + error: vi.fn<(...args: unknown[]) => void>(), + debug: vi.fn<(...args: unknown[]) => void>(), + }), +})); + +import { CallEmbed } from './CallEmbed'; + +describe('CallEmbed.getIframe', () => { + it('leaves src unset so the caller can load after the transport is listening', () => { + const iframe = CallEmbed.getIframe(); + + expect(iframe.getAttribute('src')).toBeNull(); + }); +}); diff --git a/src/app/plugins/call/CallEmbed.ts b/src/app/plugins/call/CallEmbed.ts index 8ad03365c..4cade0062 100644 --- a/src/app/plugins/call/CallEmbed.ts +++ b/src/app/plugins/call/CallEmbed.ts @@ -194,7 +194,7 @@ export class CallEmbed { return widget; } - static getIframe(url: string): HTMLIFrameElement { + static getIframe(): HTMLIFrameElement { const iframe = document.createElement('iframe'); iframe.title = 'Call Embed'; @@ -202,7 +202,6 @@ export class CallEmbed { 'allow-forms allow-scripts allow-same-origin allow-popups allow-modals allow-downloads'; iframe.allow = 'microphone; camera; display-capture; autoplay; clipboard-write; local-network-access;'; - iframe.src = url; iframe.style.width = '100%'; iframe.style.height = '100%'; @@ -220,14 +219,15 @@ export class CallEmbed { ) { debugLog.info('call', 'Initializing call embed', { roomId: room.roomId }); - const iframe = CallEmbed.getIframe( - widget.getCompleteUrl({ currentUserId: mx.getSafeUserId() }) - ); + const iframe = CallEmbed.getIframe(); container.append(iframe); const callWidgetDriver: WidgetDriver = new CallWidgetDriver(mx, room.roomId); const call: ClientWidgetApi = new ClientWidgetApi(widget, iframe, callWidgetDriver); + // Load after the transport is listening, or a fast iframe's contentLoaded is missed. + iframe.src = widget.getCompleteUrl({ currentUserId: mx.getSafeUserId() }); + this.mx = mx; this.call = call; this.room = room;