cloudstorm
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -46,2 +46,3 @@ /// <reference types="node" /> | ||
latency: number; | ||
private _closing; | ||
static readonly default: typeof DiscordConnector; | ||
@@ -48,0 +49,0 @@ /** |
@@ -32,2 +32,3 @@ "use strict"; | ||
this.latency = 0; | ||
this._closing = false; | ||
this.id = id; | ||
@@ -52,2 +53,3 @@ this.client = client; | ||
connect() { | ||
this._closing = false; | ||
return this.betterWs.connect(); | ||
@@ -59,3 +61,4 @@ } | ||
async disconnect() { | ||
return this.betterWs.close(); | ||
this._closing = true; | ||
return this.betterWs.close(1000, "Disconnected by User"); | ||
} | ||
@@ -134,3 +137,3 @@ /** | ||
void this.client.emit("error", `Client was attempting to ${resume ? "resume" : "reconnect"} while the WebSocket was still in the connecting state. This should never happen.`); | ||
await this.betterWs.close(); | ||
await this.betterWs.close(resume ? 4000 : 1012, "reconnecting"); | ||
if (resume) | ||
@@ -313,4 +316,5 @@ this.clearHeartBeat(); | ||
// Don't try to reconnect when true | ||
if (code === 1000 && reason === "Disconnected by User") | ||
if (code === 1000 && this._closing) | ||
gracefulClose = true; | ||
this._closing = false; | ||
if (gracefulClose) { | ||
@@ -317,0 +321,0 @@ this.clearHeartBeat(); |
@@ -42,3 +42,3 @@ /// <reference types="node" /> | ||
connect(): Promise<void>; | ||
close(): Promise<void>; | ||
close(code: number, reason?: string): Promise<void>; | ||
sendMessage(data: import("../Types").IWSMessage): Promise<void>; | ||
@@ -45,0 +45,0 @@ private _write; |
@@ -101,3 +101,3 @@ "use strict"; | ||
} | ||
async close() { | ||
async close(code, reason) { | ||
const internal = this._internal; | ||
@@ -111,3 +111,4 @@ if (internal.closePromise) | ||
resolver = resolve; | ||
this._write(Buffer.allocUnsafe(0), 8); | ||
const from = Buffer.from([code >> 8, code & 255]); | ||
this._write(reason ? Buffer.concat([from, Buffer.from(reason)]) : from, 8); | ||
}).then(() => { | ||
@@ -114,0 +115,0 @@ internal.closePromise = null; |
{ | ||
"name": "cloudstorm", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Minimalistic Discord Gateway library", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117138
2268