From 1059dbccbd34b709fb6a22df651f280271f303f6 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 19 Feb 2021 16:30:50 +0000 Subject: [PATCH] Expose strongly typed send function. --- package.json | 2 +- src/index.ts | 2 +- src/websocket/client.ts | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 6f3e8c74..5ac0a79a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "revolt.js", - "version": "3.0.3-alpha.8", + "version": "3.0.3-alpha.9", "main": "dist/index.js", "repository": "https://gitlab.insrt.uk/revolt/revolt.js", "author": "Paul Makles ", diff --git a/src/index.ts b/src/index.ts index 32a3af2d..5cf119cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ export { default as User } from './objects/User'; export { default as Message } from './objects/Message'; export { default as Channel, SavedMessagesChannel, DirectMessageChannel, GroupChannel } from './objects/Channel'; -export const LIBRARY_VERSION = '3.0.3-alpha.8'; +export const LIBRARY_VERSION = '3.0.3-alpha.9'; export const defaultConfig = { apiURL: 'https://api.revolt.chat', diff --git a/src/websocket/client.ts b/src/websocket/client.ts index 15dbbe7f..2e6af792 100644 --- a/src/websocket/client.ts +++ b/src/websocket/client.ts @@ -31,6 +31,14 @@ export class WebSocketClient { } } + send(notification: ServerboundNotification) { + if (!this.ws) return; + + let data = JSON.stringify(notification); + if (this.client.debug) console.debug('[<] PACKET', data); + this.ws.send(data); + } + connect(disallowReconnect?: boolean): Promise { this.client.emit('connecting'); @@ -54,14 +62,9 @@ export class WebSocketClient { } let ws = new WebSocket(this.client.configuration.ws); - const send = (notification: ServerboundNotification) => { - let data = JSON.stringify(notification); - if (this.client.debug) console.debug('[<] PACKET', data); - ws.send(data) - }; ws.onopen = () => { - send({ type: 'Authenticate', ...this.client.session as Auth.Session }); + this.send({ type: 'Authenticate', ...this.client.session as Auth.Session }); }; let handle = async (msg: WebSocket.MessageEvent) => {