From 1361333fdc3ad2122298ce8050d043f8c2b374c1 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 12 Apr 2016 18:38:10 +0100 Subject: [PATCH] Stop the MatrixClient when the MatrixChat is unmounted The MatrixClient never gets unmounted in the real app, but I've been working on some tests which would rather like to be able to create and destroy MatrixChats and not have the clients hang around forever. --- src/components/structures/MatrixChat.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 497251e5aa..285af188d9 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -183,6 +183,7 @@ module.exports = React.createClass({ }, componentWillUnmount: function() { + this._stopMatrixClient(); dis.unregister(this.dispatcherRef); document.removeEventListener("keydown", this.onKeyDown); window.removeEventListener("focus", this.onFocus); @@ -258,12 +259,7 @@ module.exports = React.createClass({ window.localStorage.setItem("mx_hs_url", hsUrl); window.localStorage.setItem("mx_is_url", isUrl); } - Notifier.stop(); - UserActivity.stop(); - Presence.stop(); - MatrixClientPeg.get().stopClient(); - MatrixClientPeg.get().removeAllListeners(); - MatrixClientPeg.unset(); + this._stopMatrixClient(); this.notifyNewScreen('login'); this.replaceState({ logged_in: false, @@ -722,6 +718,16 @@ module.exports = React.createClass({ }); }, + // stop all the background processes related to the current client + _stopMatrixClient: function() { + Notifier.stop(); + UserActivity.stop(); + Presence.stop(); + MatrixClientPeg.get().stopClient(); + MatrixClientPeg.get().removeAllListeners(); + MatrixClientPeg.unset(); + }, + onKeyDown: function(ev) { /* // Remove this for now as ctrl+alt = alt-gr so this breaks keyboards which rely on alt-gr for numbers