mirror of
https://github.com/adamdruppe/arsd.git
synced 2025-04-26 21:30:12 +03:00
more reliable connect loop
This commit is contained in:
parent
5618c1e47a
commit
23cf22d0e3
1 changed files with 25 additions and 5 deletions
30
discord.d
30
discord.d
|
@ -748,10 +748,7 @@ class DiscordGatewayConnection {
|
||||||
websocket.onmessage = &handleWebsocketMessage;
|
websocket.onmessage = &handleWebsocketMessage;
|
||||||
websocket.onclose = &handleWebsocketClose;
|
websocket.onclose = &handleWebsocketClose;
|
||||||
|
|
||||||
// FIXME: if the connect fails we should set a timer and try
|
websocketConnectInLoop();
|
||||||
// again, but if it fails then, quit. at least if it is not a websocket reply
|
|
||||||
// cuz it could be discord went down or something.
|
|
||||||
this.websocket_.connect();
|
|
||||||
|
|
||||||
var resumeData = var.emptyObject;
|
var resumeData = var.emptyObject;
|
||||||
resumeData.token = this.token;
|
resumeData.token = this.token;
|
||||||
|
@ -927,7 +924,7 @@ class DiscordGatewayConnection {
|
||||||
websocket.onmessage = &handleWebsocketMessage;
|
websocket.onmessage = &handleWebsocketMessage;
|
||||||
websocket.onclose = &handleWebsocketClose;
|
websocket.onclose = &handleWebsocketClose;
|
||||||
|
|
||||||
websocket.connect();
|
websocketConnectInLoop();
|
||||||
|
|
||||||
var d = var.emptyObject;
|
var d = var.emptyObject;
|
||||||
d.token = token;
|
d.token = token;
|
||||||
|
@ -940,6 +937,29 @@ class DiscordGatewayConnection {
|
||||||
|
|
||||||
sendWebsocketCommand(OpCode.Identify, d);
|
sendWebsocketCommand(OpCode.Identify, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void websocketConnectInLoop() {
|
||||||
|
// FIXME: if the connect fails we should set a timer and try
|
||||||
|
// again, but if it fails then, quit. at least if it is not a websocket reply
|
||||||
|
// cuz it could be discord went down or something.
|
||||||
|
|
||||||
|
import core.time;
|
||||||
|
auto d = 1.seconds;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.websocket_.connect();
|
||||||
|
} catch(Exception e) {
|
||||||
|
import core.thread;
|
||||||
|
Thread.sleep(d);
|
||||||
|
d *= 2;
|
||||||
|
count++;
|
||||||
|
if(count == 10)
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiscordRpcConnection {
|
class DiscordRpcConnection {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue