From 3b383308d43696b827688461da2504372a1fd7ee Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 23 Jun 2023 16:05:45 +0200 Subject: [PATCH] Send PING on window focus References: https://todo.sr.ht/~emersion/gamja/148 --- components/app.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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() {