WIP on websocket impl

This commit is contained in:
Spencer Pogorzelski 2023-08-13 19:06:52 -07:00
parent 07b0ba3a07
commit f64cc78f9f
6 changed files with 91 additions and 28 deletions

View file

@ -1,6 +1,7 @@
import {
C2SRequestType,
C2SRequestTypes,
C2SWSOpenPayload,
HTTPRequestPayload,
HTTPResponsePayload,
S2CRequestType,
@ -112,11 +113,12 @@ export class Connection {
send: (data: any) => void;
close: (code?: number, reason?: string) => void;
} {
const payload = JSON.stringify({ url });
const payload: C2SWSOpenPayload = { url: url.toString() };
const payloadJSON = JSON.stringify(payload);
let seq = this.nextSeq();
this.send(
seq,
new TextEncoder().encode(payload),
new TextEncoder().encode(payloadJSON),
C2SRequestTypes.WSOpen
).catch((e) => {
console.error(e);