From a798772e802621375149e68a66347284f0df68b9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 15 Dec 2020 16:53:11 +0000 Subject: [PATCH 1/3] Unregister from the dispatcher in CallHandler otherwise you end up getting multiple place_call dispatches if you place a call after logging in --- src/CallHandler.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index 41dc031b06..8bfd798f16 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -118,6 +118,7 @@ function getRemoteAudioElement(): HTMLAudioElement { export default class CallHandler { private calls = new Map(); // roomId -> call private audioPromises = new Map>(); + private dispatcherRef: string; static sharedInstance() { if (!window.mxCallHandler) { @@ -128,7 +129,7 @@ export default class CallHandler { } start() { - dis.register(this.onAction); + this.dispatcherRef = dis.register(this.onAction); // add empty handlers for media actions, otherwise the media keys // end up causing the audio elements with our ring/ringback etc // audio clips in to play. @@ -151,6 +152,7 @@ export default class CallHandler { if (cli) { cli.removeListener('Call.incoming', this.onCallIncoming); } + if (this.dispatcherRef) dis.unregister(this.dispatcherRef); } private onCallIncoming = (call) => { From a77d675664f86df5bd32ee3eda088de81b36ad70 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 15 Dec 2020 18:01:42 +0000 Subject: [PATCH 2/3] Better null check to make tests happy --- src/CallHandler.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index 8bfd798f16..eaf56b935a 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -118,7 +118,7 @@ function getRemoteAudioElement(): HTMLAudioElement { export default class CallHandler { private calls = new Map(); // roomId -> call private audioPromises = new Map>(); - private dispatcherRef: string; + private dispatcherRef: string = null; static sharedInstance() { if (!window.mxCallHandler) { @@ -152,7 +152,7 @@ export default class CallHandler { if (cli) { cli.removeListener('Call.incoming', this.onCallIncoming); } - if (this.dispatcherRef) dis.unregister(this.dispatcherRef); + if (this.dispatcherRef !== null) dis.unregister(this.dispatcherRef); } private onCallIncoming = (call) => { From 973a0b7b8a07d69fe221471de9b793750a042a42 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 16 Dec 2020 10:53:59 +0000 Subject: [PATCH 3/3] set dispatcher ref to null so we don't double-unregister --- src/CallHandler.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index eaf56b935a..fac4d6fc4e 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -152,7 +152,10 @@ export default class CallHandler { if (cli) { cli.removeListener('Call.incoming', this.onCallIncoming); } - if (this.dispatcherRef !== null) dis.unregister(this.dispatcherRef); + if (this.dispatcherRef !== null) { + dis.unregister(this.dispatcherRef); + this.dispatcherRef = null; + } } private onCallIncoming = (call) => {