Added an auto reconnect system
parent
35dff37a40
commit
3663adfe4f
|
@ -8,6 +8,8 @@
|
||||||
- Fixed the vertical sliders for touch devices
|
- Fixed the vertical sliders for touch devices
|
||||||
- Added an effect on slider select/move
|
- Added an effect on slider select/move
|
||||||
- Fixed query visibility setting
|
- Fixed query visibility setting
|
||||||
|
- Removed useless client infos for query clients
|
||||||
|
- Added an auto reconnect system
|
||||||
|
|
||||||
* **15.02.19**
|
* **15.02.19**
|
||||||
- Fixed MS Edge loading/document issues
|
- Fixed MS Edge loading/document issues
|
||||||
|
|
|
@ -59,6 +59,8 @@ class TSClient {
|
||||||
|
|
||||||
private _clientId: number = 0;
|
private _clientId: number = 0;
|
||||||
private _ownEntry: LocalClientEntry;
|
private _ownEntry: LocalClientEntry;
|
||||||
|
private _reconnect_timer: NodeJS.Timer;
|
||||||
|
private _reconnect_attempt: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.selectInfo = new InfoBar(this, $("#select_info"));
|
this.selectInfo = new InfoBar(this, $("#select_info"));
|
||||||
|
@ -78,6 +80,7 @@ class TSClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
startConnection(addr: string, profile: profiles.ConnectionProfile, name?: string, password?: {password: string, hashed: boolean}) {
|
startConnection(addr: string, profile: profiles.ConnectionProfile, name?: string, password?: {password: string, hashed: boolean}) {
|
||||||
|
this._reconnect_attempt = false;
|
||||||
if(this.serverConnection)
|
if(this.serverConnection)
|
||||||
this.handleDisconnect(DisconnectReason.REQUESTED);
|
this.handleDisconnect(DisconnectReason.REQUESTED);
|
||||||
|
|
||||||
|
@ -166,10 +169,16 @@ class TSClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDisconnect(type: DisconnectReason, data: any = {}) {
|
handleDisconnect(type: DisconnectReason, data: any = {}) {
|
||||||
|
let auto_reconnect = false;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DisconnectReason.REQUESTED:
|
case DisconnectReason.REQUESTED:
|
||||||
break;
|
break;
|
||||||
case DisconnectReason.CONNECT_FAILURE:
|
case DisconnectReason.CONNECT_FAILURE:
|
||||||
|
if(this._reconnect_attempt) {
|
||||||
|
auto_reconnect = true;
|
||||||
|
chat.serverChat().appendError(tr("Connect failed"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
console.error(tr("Could not connect to remote host! Exception: %o"), data);
|
console.error(tr("Could not connect to remote host! Exception: %o"), data);
|
||||||
|
|
||||||
if(native_client) {
|
if(native_client) {
|
||||||
|
@ -203,6 +212,8 @@ class TSClient {
|
||||||
tr("The connection was closed by remote host")
|
tr("The connection was closed by remote host")
|
||||||
).open();
|
).open();
|
||||||
sound.play(Sound.CONNECTION_DISCONNECTED);
|
sound.play(Sound.CONNECTION_DISCONNECTED);
|
||||||
|
|
||||||
|
auto_reconnect = true;
|
||||||
break;
|
break;
|
||||||
case DisconnectReason.CONNECTION_PING_TIMEOUT:
|
case DisconnectReason.CONNECTION_PING_TIMEOUT:
|
||||||
console.error(tr("Connection ping timeout"));
|
console.error(tr("Connection ping timeout"));
|
||||||
|
@ -211,6 +222,7 @@ class TSClient {
|
||||||
tr("Connection lost"),
|
tr("Connection lost"),
|
||||||
tr("Lost connection to remote host (Ping timeout)<br>Even possible?")
|
tr("Lost connection to remote host (Ping timeout)<br>Even possible?")
|
||||||
).open();
|
).open();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DisconnectReason.SERVER_CLOSED:
|
case DisconnectReason.SERVER_CLOSED:
|
||||||
chat.serverChat().appendError(tr("Server closed ({0})"), data.reasonmsg);
|
chat.serverChat().appendError(tr("Server closed ({0})"), data.reasonmsg);
|
||||||
|
@ -220,6 +232,8 @@ class TSClient {
|
||||||
"Reason: " + data.reasonmsg
|
"Reason: " + data.reasonmsg
|
||||||
).open();
|
).open();
|
||||||
sound.play(Sound.CONNECTION_DISCONNECTED);
|
sound.play(Sound.CONNECTION_DISCONNECTED);
|
||||||
|
|
||||||
|
auto_reconnect = true;
|
||||||
break;
|
break;
|
||||||
case DisconnectReason.SERVER_REQUIRES_PASSWORD:
|
case DisconnectReason.SERVER_REQUIRES_PASSWORD:
|
||||||
chat.serverChat().appendError(tr("Server requires password"));
|
chat.serverChat().appendError(tr("Server requires password"));
|
||||||
|
@ -236,6 +250,7 @@ class TSClient {
|
||||||
ClientEntry.chatTag(data["invokerid"], data["invokername"], data["invokeruid"]),
|
ClientEntry.chatTag(data["invokerid"], data["invokername"], data["invokeruid"]),
|
||||||
data["reasonmsg"] ? " (" + data["reasonmsg"] + ")" : "");
|
data["reasonmsg"] ? " (" + data["reasonmsg"] + ")" : "");
|
||||||
sound.play(Sound.SERVER_KICKED);
|
sound.play(Sound.SERVER_KICKED);
|
||||||
|
auto_reconnect = true;
|
||||||
break;
|
break;
|
||||||
case DisconnectReason.CLIENT_BANNED:
|
case DisconnectReason.CLIENT_BANNED:
|
||||||
chat.serverChat().appendError(tr("You got banned from the server by {0}{1}"),
|
chat.serverChat().appendError(tr("You got banned from the server by {0}{1}"),
|
||||||
|
@ -256,5 +271,34 @@ class TSClient {
|
||||||
this.controlBar.update_connection_state();
|
this.controlBar.update_connection_state();
|
||||||
this.selectInfo.setCurrentSelected(null);
|
this.selectInfo.setCurrentSelected(null);
|
||||||
this.selectInfo.update_banner();
|
this.selectInfo.update_banner();
|
||||||
|
|
||||||
|
if(auto_reconnect) {
|
||||||
|
if(!this.serverConnection) {
|
||||||
|
console.log(tr("Allowed to auto reconnect but cant reconnect because we dont have any information left..."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chat.serverChat().appendMessage(tr("Reconnecting in 2.5 seconds"));
|
||||||
|
|
||||||
|
console.log(tr("Allowed to auto reconnect. Reconnecting in 2500ms"));
|
||||||
|
const server_address = this.serverConnection._remote_address;
|
||||||
|
const profile = this.serverConnection._handshakeHandler.profile;
|
||||||
|
const name = this.serverConnection._handshakeHandler.name;
|
||||||
|
const password = this.serverConnection._handshakeHandler.server_password;
|
||||||
|
|
||||||
|
this._reconnect_timer = setTimeout(() => {
|
||||||
|
this._reconnect_timer = undefined;
|
||||||
|
chat.serverChat().appendMessage(tr("Reconnecting..."));
|
||||||
|
console.log(tr("Reconnecting..."));
|
||||||
|
this.startConnection(server_address.host + ":" + server_address.port, profile, name, password ? { password: password, hashed: true} : undefined);
|
||||||
|
this._reconnect_attempt = true;
|
||||||
|
}, 2500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel_reconnect() {
|
||||||
|
if(this._reconnect_timer) {
|
||||||
|
clearTimeout(this._reconnect_timer);
|
||||||
|
this._reconnect_timer = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -243,6 +243,7 @@ class ControlBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onConnect() {
|
private onConnect() {
|
||||||
|
this.handle.cancel_reconnect();
|
||||||
Modals.spawnConnectModal({
|
Modals.spawnConnectModal({
|
||||||
url: "ts.TeaSpeak.de",
|
url: "ts.TeaSpeak.de",
|
||||||
enforce: false
|
enforce: false
|
||||||
|
@ -264,6 +265,7 @@ class ControlBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
private onDisconnect() {
|
private onDisconnect() {
|
||||||
|
this.handle.cancel_reconnect();
|
||||||
this.handle.handleDisconnect(DisconnectReason.REQUESTED); //TODO message?
|
this.handle.handleDisconnect(DisconnectReason.REQUESTED); //TODO message?
|
||||||
this.update_connection_state();
|
this.update_connection_state();
|
||||||
sound.play(Sound.CONNECTION_DISCONNECTED);
|
sound.play(Sound.CONNECTION_DISCONNECTED);
|
||||||
|
|
Loading…
Reference in New Issue