From 3c14d93237f5e2ce2426919c9d2f2046f5f85ce9 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 29 Jun 2022 10:09:41 -0400 Subject: [PATCH] Reduce video rooms log spam (#8913) * Reduce video rooms log spam If you forget to call preventDefault in widget action handlers, matrix-widget-api logs a bunch of errors complaining that the action is unsupported/unhandled, even if it isn't. * Fix tests --- src/stores/VideoChannelStore.ts | 14 +++++++++++--- src/stores/widgets/StopGapWidget.ts | 2 ++ test/stores/VideoChannelStore-test.ts | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/stores/VideoChannelStore.ts b/src/stores/VideoChannelStore.ts index 160ce18355..05b2b4dfb7 100644 --- a/src/stores/VideoChannelStore.ts +++ b/src/stores/VideoChannelStore.ts @@ -202,6 +202,7 @@ export default class VideoChannelStore extends AsyncStoreWithClient { messaging, `action:${ElementWidgetActions.JoinCall}`, (ev: CustomEvent) => { + ev.preventDefault(); this.ack(ev); return true; }, @@ -290,42 +291,49 @@ export default class VideoChannelStore extends AsyncStoreWithClient { await removeOurDevice(room); }; - private ack = (ev: CustomEvent) => { + private ack = (ev: CustomEvent, messaging = this.activeChannel) => { // Even if we don't have a reply to a given widget action, we still need // to give the widget API something to acknowledge receipt - this.activeChannel.transport.reply(ev.detail, {}); + messaging.transport.reply(ev.detail, {}); }; private onHangup = async (ev: CustomEvent) => { - this.ack(ev); + ev.preventDefault(); + const messaging = this.activeChannel; // In case this hangup is caused by Jitsi Meet crashing at startup, // wait for the connection event in order to avoid racing if (!this.connected) await waitForEvent(this, VideoChannelEvent.Connect); await this.setDisconnected(); + this.ack(ev, messaging); }; private onParticipants = (ev: CustomEvent) => { + ev.preventDefault(); this.participants = ev.detail.data.participants as IJitsiParticipant[]; this.emit(VideoChannelEvent.Participants, this.roomId, ev.detail.data.participants); this.ack(ev); }; private onMuteAudio = (ev: CustomEvent) => { + ev.preventDefault(); this.audioMuted = true; this.ack(ev); }; private onUnmuteAudio = (ev: CustomEvent) => { + ev.preventDefault(); this.audioMuted = false; this.ack(ev); }; private onMuteVideo = (ev: CustomEvent) => { + ev.preventDefault(); this.videoMuted = true; this.ack(ev); }; private onUnmuteVideo = (ev: CustomEvent) => { + ev.preventDefault(); this.videoMuted = false; this.ack(ev); }; diff --git a/src/stores/widgets/StopGapWidget.ts b/src/stores/widgets/StopGapWidget.ts index 794fa17a25..7a1c5e0ba5 100644 --- a/src/stores/widgets/StopGapWidget.ts +++ b/src/stores/widgets/StopGapWidget.ts @@ -374,6 +374,7 @@ export class StopGapWidget extends EventEmitter { if (WidgetType.JITSI.matches(this.mockWidget.type)) { this.messaging.on(`action:${ElementWidgetActions.HangupCall}`, (ev: CustomEvent) => { + ev.preventDefault(); if (ev.detail.data?.errorMessage) { Modal.createDialog(ErrorDialog, { title: _t("Connection lost"), @@ -382,6 +383,7 @@ export class StopGapWidget extends EventEmitter { }), }); } + this.messaging.transport.reply(ev.detail, {}); }, ); } diff --git a/test/stores/VideoChannelStore-test.ts b/test/stores/VideoChannelStore-test.ts index 4525930bcd..16542f41e8 100644 --- a/test/stores/VideoChannelStore-test.ts +++ b/test/stores/VideoChannelStore-test.ts @@ -106,7 +106,7 @@ describe("VideoChannelStore", () => { const waitForConnect = new Promise(resolve => store.once(VideoChannelEvent.Connect, resolve), ); - join({ detail: {} } as unknown as CustomEvent); + join(new CustomEvent("widgetapirequest", { detail: {} }) as CustomEvent); await waitForConnect; }; @@ -119,7 +119,7 @@ describe("VideoChannelStore", () => { const waitForHangup = new Promise(resolve => store.once(VideoChannelEvent.Disconnect, resolve), ); - hangup({ detail: {} } as unknown as CustomEvent); + hangup(new CustomEvent("widgetapirequest", { detail: {} }) as CustomEvent); await waitForHangup; };