Implement optional opportunistic pings

This commit is contained in:
Drew DeVault 2021-05-27 12:17:41 -04:00 committed by Simon Ser
parent 3021eae9af
commit d612c91016
2 changed files with 14 additions and 0 deletions

View file

@ -48,6 +48,10 @@ location /socket {
}
```
If you are unable to configure the proxy timeout accordingly, you can set the
`server.ping` option in `config.json` to an interval, in seconds, between which
gamja will send opportunistic pings.
### Development server
Start your IRC WebSocket server, e.g. on port 8080. Then run:

View file

@ -213,6 +213,8 @@ export default class App extends Component {
* - Default server URL constructed from the current URL location
*/
handleConfig(config) {
this.config = config;
var host = window.location.host || "localhost:8080";
var proto = "wss:";
if (window.location.protocol != "https:") {
@ -531,6 +533,13 @@ export default class App extends Component {
if (params.autojoin.length > 0) {
this.switchToChannel = params.autojoin[0];
}
if (this.config.server && this.config.server.ping > 0) {
// TODO: unregister setInterval on disconnect
setInterval(() => {
client.send({ command: "PING", params: ["gamja"] });
}, this.config.server.ping * 1000);
}
}
disconnect(netID) {
@ -845,6 +854,7 @@ export default class App extends Component {
case "CAP":
case "AUTHENTICATE":
case "PING":
case "PONG":
case "BATCH":
// Ignore these
break;