add support for binary JPEG (server)

This commit is contained in:
Elijah R
2024-06-25 19:56:28 -04:00
parent 8369de53ba
commit fe830afdeb
10 changed files with 121 additions and 13 deletions

View File

@@ -33,6 +33,7 @@ export default class WSClient extends EventEmitter implements NetworkClient {
getIP(): string {
return this.ip;
}
send(msg: string): Promise<void> {
return new Promise((res, rej) => {
if (!this.isOpen()) res();
@@ -47,6 +48,20 @@ export default class WSClient extends EventEmitter implements NetworkClient {
});
}
sendBinary(msg: Uint8Array): Promise<void> {
return new Promise((res, rej) => {
if (!this.isOpen()) res();
this.socket.send(msg, (err) => {
if (err) {
rej(err);
return;
}
res();
});
});
}
close(): void {
if (this.isOpen()) {
// While this seems counterintutive, do note that the WebSocket protocol