Skip to content

Commit ad14090

Browse files
authored
0.8.1 (#8)
* Try reconnecting when getting a DNS error on WS connect * 0.8.1
1 parent d348b61 commit ad14090

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "detritus-client-socket",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "A TypeScript NodeJS library to interact with Discord's Gateway",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"files": [
88
"lib/**/*"
99
],
1010
"dependencies": {
11+
"@types/node": "^14.17.1",
1112
"detritus-utils": "^0.4.0",
1213
"ws": "^7.4.6"
1314
},
1415
"devDependencies": {
15-
"@types/node": "^14.17.1",
1616
"typedoc": "^0.20.36",
1717
"typescript": "^4.2.4"
1818
},

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const Package = Object.freeze({
22
URL: 'https://github.com/detritusjs/client-socket',
3-
VERSION: '0.8.0',
3+
VERSION: '0.8.1',
44
});
55

66

src/gateway.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,26 @@ export class Socket extends EventSpewer {
433433
}; break;
434434
}
435435

436-
this.socket = new BaseSocket(this.url.href);
437-
this.socket.on(SocketEventsBase.CLOSE, this.onClose.bind(this, this.socket));
438-
this.socket.on(SocketEventsBase.ERROR, this.onError.bind(this, this.socket));
439-
this.socket.on(SocketEventsBase.MESSAGE, this.onMessage.bind(this, this.socket));
440-
this.socket.on(SocketEventsBase.OPEN, this.onOpen.bind(this, this.socket));
436+
try {
437+
this.socket = new BaseSocket(this.url.href);
438+
this.socket.on(SocketEventsBase.CLOSE, this.onClose.bind(this, this.socket));
439+
this.socket.on(SocketEventsBase.ERROR, this.onError.bind(this, this.socket));
440+
this.socket.on(SocketEventsBase.MESSAGE, this.onMessage.bind(this, this.socket));
441+
this.socket.on(SocketEventsBase.OPEN, this.onOpen.bind(this, this.socket));
442+
} catch(error) {
443+
this.socket = null;
444+
if (this.autoReconnect && !this.killed) {
445+
if (this.reconnectMax < this.reconnects) {
446+
this.kill(new Error(`Tried reconnecting more than ${this.reconnectMax} times.`));
447+
} else {
448+
this.emit(SocketEvents.RECONNECTING);
449+
setTimeout(() => {
450+
this.connect(url);
451+
this.reconnects++;
452+
}, this.reconnectDelay);
453+
}
454+
}
455+
}
441456

442457
this.setState(SocketStates.CONNECTING);
443458
this.emit(SocketEvents.SOCKET, this.socket);

0 commit comments

Comments
 (0)