From f58259ec941509c1648a87322ccd602511fd8ab4 Mon Sep 17 00:00:00 2001 From: Pawel Urbanek Date: Tue, 28 Mar 2023 12:53:12 +0200 Subject: [PATCH] fix reconnect after WebSocket Timeout. fix typo, don't send messages thru data channel is connection is not opened --- client/src/components/connect.vue | 13 ++++++------- client/src/neko/base.ts | 2 +- client/src/neko/index.ts | 8 +++++++- client/src/store/index.ts | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/client/src/components/connect.vue b/client/src/components/connect.vue index 92d04476..31c19921 100644 --- a/client/src/components/connect.vue +++ b/client/src/components/connect.vue @@ -158,22 +158,22 @@ mounted() { // auto-password fill - let password = this.$accessor.password + this.password = this.$accessor.password if (this.autoPassword !== null) { this.removeUrlParam('pwd') - password = this.autoPassword + this.password = this.autoPassword } // auto-user fill - let displayname = this.$accessor.displayname + this.displayname = this.$accessor.displayname const usr = new URL(location.href).searchParams.get('usr') if (usr) { this.removeUrlParam('usr') - displayname = this.$accessor.displayname || usr + this.displayname = this.$accessor.displayname || usr } - if (displayname !== '' && password !== '') { - this.$accessor.login({ displayname, password }) + if (this.displayname !== '' && this.password !== '') { + this.$accessor.login({ displayname: this.displayname, password: this.password }) this.autoPassword = null } } @@ -208,7 +208,6 @@ if (this.autoPassword !== null) { password = this.autoPassword } - if (this.displayname == '') { this.$swal({ title: this.$t('connect.error') as string, diff --git a/client/src/neko/base.ts b/client/src/neko/base.ts index 43267b1d..3e4e82ba 100644 --- a/client/src/neko/base.ts +++ b/client/src/neko/base.ts @@ -173,7 +173,7 @@ export abstract class BaseClient extends EventEmitter { } // @ts-ignore - if (typeof buffer !== 'undefined') { + if (typeof buffer !== 'undefined' && this._channel?.readyState == 'open') { this._channel!.send(buffer) } } diff --git a/client/src/neko/index.ts b/client/src/neko/index.ts index 16ca0b6f..7dd094f4 100644 --- a/client/src/neko/index.ts +++ b/client/src/neko/index.ts @@ -85,7 +85,7 @@ export class NekoClient extends BaseClient implements EventEmitter { } protected [EVENT.CONNECTING]() { - this.$accessor.setConnnecting() + this.$accessor.setConnecting() } protected [EVENT.CONNECTED]() { @@ -117,6 +117,11 @@ export class NekoClient extends BaseClient implements EventEmitter { duration: 5000, speed: 1000, }) + if (reason?.message == 'connection timeout') { + if (this.$accessor.displayname && this.$accessor.password) { + this.login(this.$accessor.password, this.$accessor.displayname) + } + } } protected [EVENT.TRACK](event: RTCTrackEvent) { @@ -160,6 +165,7 @@ export class NekoClient extends BaseClient implements EventEmitter { text: message, icon: 'error', confirmButtonText: this.$vue.$t('connection.button_confirm') as string, + timer: 15000, }) } diff --git a/client/src/store/index.ts b/client/src/store/index.ts index 2bc6c91a..4bcd81b0 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -41,7 +41,7 @@ export const mutations = mutationTree(state, { Vue.set(state.locked, resource, false) }, - setConnnecting(state) { + setConnecting(state) { state.connected = false state.connecting = true },