diff --git a/src/main.ts b/src/main.ts index 591cbfa..67f01f5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,7 +54,7 @@ async function main(argv: string[]) { return; } if (msg.type == 'event') return; - client.send(await callTachyonAutohost(msg, autohost)); + client.send(await callTachyonAutohost(msg, autohost)).catch(() => undefined); }); try { diff --git a/src/tachyonClient.ts b/src/tachyonClient.ts index 0ed421e..2768c5c 100644 --- a/src/tachyonClient.ts +++ b/src/tachyonClient.ts @@ -79,6 +79,7 @@ export class TachyonClient extends TypedEmitter<{ headers: { authorization: `Bearer ${accessToken}`, }, + perMessageDeflate: false, }); this.ws = ws; @@ -114,13 +115,19 @@ export class TachyonClient extends TypedEmitter<{ this.close(); } - public send(msg: TachyonCommand): void { + public send(msg: TachyonCommand): Promise { if (this.state !== ClientState.CONNECTED) { throw new Error('Client is not connected'); } - if (this.ws) { - this.ws.send(JSON.stringify(msg)); - } + return new Promise((resolve, reject) => { + this.ws!.send(JSON.stringify(msg), { binary: false }, (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); } public close() { diff --git a/src/tachyonTypes.ts b/src/tachyonTypes.ts index c533724..a4038f4 100644 --- a/src/tachyonTypes.ts +++ b/src/tachyonTypes.ts @@ -102,8 +102,8 @@ export interface TachyonAutohost { * The interface that represents the functionality that the autohost can call on the server. */ export interface TachyonServer { - status(event: AutohostStatusEventData): void; - update(event: AutohostUpdateEventData): void; + status(event: AutohostStatusEventData): Promise; + update(event: AutohostUpdateEventData): Promise; } // Helper that works as a type guard to check if an element is included in an array.