Expose strongly typed send function.

This commit is contained in:
Paul Makles
2021-02-19 16:30:50 +00:00
parent 1139251d7b
commit 1059dbccbd
3 changed files with 11 additions and 8 deletions
+1 -1
View File
@@ -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 <insrt.uk>",
+1 -1
View File
@@ -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',
+9 -6
View File
@@ -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<void> {
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) => {