Reconnect when loosing connection

This commit is contained in:
Simon Ser 2021-01-11 18:12:28 +01:00
parent 57ca2c44ad
commit 4b165054a4
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 19 additions and 6 deletions

View file

@ -12,7 +12,7 @@ export default {
if (window.localStorage) {
localStorage.removeItem("autoconnect");
}
app.client.close();
app.close(SERVER_BUFFER);
},
"query": (app, args) => {
var nick = args[0];

View file

@ -15,6 +15,7 @@ import { setup as setupKeybindings } from "/keybindings.js";
const CHATHISTORY_PAGE_SIZE = 100;
const CHATHISTORY_MAX_SIZE = 4000;
const RECONNECT_DELAY_SEC = 10;
var messagesCount = 0;
@ -358,10 +359,16 @@ export default class App extends Component {
});
this.client.addEventListener("close", () => {
this.setState({
status: Status.DISCONNECTED,
buffers: new Map(),
activeBuffer: null,
this.setState((state) => {
if (state.status == Status.DISCONNECTED) {
// User decided to logout
return null;
}
console.log("Reconnecting to server in " + RECONNECT_DELAY_SEC + " seconds");
setTimeout(() => {
this.connect(params);
}, RECONNECT_DELAY_SEC * 1000);
return { status: Status.DISCONNECTED };
});
});
@ -606,6 +613,11 @@ export default class App extends Component {
close(target) {
if (target == SERVER_BUFFER) {
this.setState({
status: Status.DISCONNECTED,
buffers: new Map(),
activeBuffer: null,
});
this.client.close();
return;
}
@ -811,7 +823,7 @@ export default class App extends Component {
}
render() {
if (this.state.status != Status.REGISTERED) {
if (this.state.status != Status.REGISTERED && !this.state.activeBuffer) {
return html`
<section id="connect">
<${Connect} error=${this.state.error} params=${this.state.connectParams} disabled=${this.state.status != Status.DISCONNECTED} onSubmit=${this.handleConnectSubmit}/>

View file

@ -27,6 +27,7 @@ export default function BufferHeader(props) {
var description = null;
if (props.buffer.serverInfo) {
// TODO: print current connection status
var serverInfo = props.buffer.serverInfo;
description = `Connected to ${serverInfo.name}`;
} else if (props.buffer.topic) {