Send PING on window focus

References: https://todo.sr.ht/~emersion/gamja/148
This commit is contained in:
Simon Ser 2023-06-23 16:05:45 +02:00
parent 3a95fd5ba4
commit 3b383308d4

View file

@ -228,6 +228,7 @@ export default class App extends Component {
this.handleSettingsChange = this.handleSettingsChange.bind(this); this.handleSettingsChange = this.handleSettingsChange.bind(this);
this.handleSettingsDisconnect = this.handleSettingsDisconnect.bind(this); this.handleSettingsDisconnect = this.handleSettingsDisconnect.bind(this);
this.handleSwitchSubmit = this.handleSwitchSubmit.bind(this); this.handleSwitchSubmit = this.handleSwitchSubmit.bind(this);
this.handleWindowFocus = this.handleWindowFocus.bind(this);
this.state.settings = { this.state.settings = {
...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() { componentDidMount() {
this.baseTitle = document.title; this.baseTitle = document.title;
setupKeybindings(this); setupKeybindings(this);
window.addEventListener("focus", this.handleWindowFocus);
} }
componentWillUnmount() { componentWillUnmount() {
document.title = this.baseTitle; document.title = this.baseTitle;
window.removeEventListener("focus", this.handleWindowFocus);
} }
render() { render() {