Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(mobile/external-api): stop readyToClose re-trigger loop

Calin-Teodor8580fa002031
diff --git a/react/features/mobile/external-api/functions.ts b/react/features/mobile/external-api/functions.ts
index 353e4b7978..d68c1a43e1 100644
--- a/react/features/mobile/external-api/functions.ts
+++ b/react/features/mobile/external-api/functions.ts
@@ -22,11 +22,26 @@ export function sendEvent(store: Object, name: string, data: Object) {
}
/**
- * Debounced sending of `readyToClose`.
+ * Per-store `readyToClose` senders, so one app's teardown can't drop another's.
*/
-export const _sendReadyToClose = debounce(dispatch => {
- dispatch(readyToClose());
-}, 2500, { leading: true });
+const _readyToCloseSenders = new WeakMap<Function, Function>();
+
+/**
+ * Sends `readyToClose` once per burst of calls, with no trailing call to avoid a close() re-trigger loop.
+ *
+ * @param {Function} dispatch - The redux dispatch of the store sending the event.
+ * @returns {void}
+ */
+export function _sendReadyToClose(dispatch: Function) {
+ let send = _readyToCloseSenders.get(dispatch);
+
+ if (!send) {
+ send = debounce(() => dispatch(readyToClose()), 2500, { leading: true, trailing: false });
+ _readyToCloseSenders.set(dispatch, send);
+ }
+
+ send();
+}
/**
* Returns a participant info object based on the passed participant object from redux.