diff options
author | Simon Ser <contact@emersion.fr> | 2023-06-23 16:05:45 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-06-23 16:05:45 +0200 |
commit | 3b383308d43696b827688461da2504372a1fd7ee (patch) | |
tree | a38695f4892a614c9c633771034aaeedf9a7f861 | |
parent | 3a95fd5ba40dcb72d21c40f28ea64b02e93d289e (diff) | |
download | gamja-3b383308d43696b827688461da2504372a1fd7ee.tar.gz gamja-3b383308d43696b827688461da2504372a1fd7ee.zip |
Send PING on window focus
References: https://todo.sr.ht/~emersion/gamja/148
-rw-r--r-- | components/app.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/components/app.js b/components/app.js index 3987749..69098d9 100644 --- a/components/app.js +++ b/components/app.js @@ -228,6 +228,7 @@ export default class App extends Component { this.handleSettingsChange = this.handleSettingsChange.bind(this); this.handleSettingsDisconnect = this.handleSettingsDisconnect.bind(this); this.handleSwitchSubmit = this.handleSwitchSubmit.bind(this); + this.handleWindowFocus = this.handleWindowFocus.bind(this); this.state.settings = { ...this.state.settings, @@ -1912,13 +1913,23 @@ export default class App extends Component { } } + handleWindowFocus() { + // When the user focuses gamja, send a PING to make sure we detect any + // network errors ASAP + for (let client of this.clients.values()) { + client.send({ command: "PING", params: ["gamja"] }); + } + } + componentDidMount() { this.baseTitle = document.title; setupKeybindings(this); + window.addEventListener("focus", this.handleWindowFocus); } componentWillUnmount() { document.title = this.baseTitle; + window.removeEventListener("focus", this.handleWindowFocus); } render() { |