mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-20 20:16:06 -04:00
Add a disconnect on websocket.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "revolt.js",
|
||||
"version": "3.0.0-beta.10",
|
||||
"version": "3.0.0-beta.11",
|
||||
"main": "dist/index.js",
|
||||
"repository": "https://gitlab.insrt.uk/revolt/revolt.js",
|
||||
"author": "Paul Makles <insrt.uk>",
|
||||
|
||||
@@ -125,6 +125,11 @@ export class Client extends EventEmitter {
|
||||
/**
|
||||
* Utility functions.
|
||||
*/
|
||||
async logout() {
|
||||
this.websocket.disconnect();
|
||||
await Axios.get('/auth/logout');
|
||||
}
|
||||
|
||||
async register(apiURL: string, data: Auth.CreateRequest): Promise<Auth.CreateResponse> {
|
||||
return (await Axios.post('/auth/create', data, { baseURL: apiURL })).data;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ export class WebSocketClient {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (typeof this.ws !== 'undefined' && this.ws.readyState === WebSocket.OPEN) {
|
||||
this.ws.close();
|
||||
}
|
||||
}
|
||||
|
||||
connect(disallowReconnect?: boolean): Promise<void> {
|
||||
this.client.emit('connecting');
|
||||
|
||||
@@ -28,9 +34,7 @@ export class WebSocketClient {
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof this.ws !== 'undefined' && this.ws.readyState === WebSocket.OPEN) {
|
||||
this.ws.close();
|
||||
}
|
||||
this.disconnect();
|
||||
|
||||
if (typeof this.client.configuration === 'undefined') {
|
||||
throw new Error("Attempted to open WebSocket without syncing configuration from server.");
|
||||
|
||||
Reference in New Issue
Block a user