This commit is contained in:
CoolElectronics 2023-08-13 23:57:17 -04:00
commit 58c3ba546d
6 changed files with 184 additions and 48 deletions

View file

@ -5,7 +5,6 @@ import {
GetRequestHeadersCallback,
MetaCallback,
ReadyStateCallback,
WebSocketFields,
WebSocketImpl,
} from "bare-client-custom";
import { Connection } from "./Connection";
@ -70,7 +69,7 @@ export class AdriftBareClient extends Client {
const ws = new webSocketImpl("ws:null", protocols);
// this will error. that's okay
let send = this.connection.wsconnect(
let { send, close } = this.connection.wsconnect(
remote,
() => {
onReadyState(WebSocketFields.OPEN);
@ -79,8 +78,6 @@ export class AdriftBareClient extends Client {
() => {
onReadyState(WebSocketFields.CLOSED);
ws.dispatchEvent(new Event("close"));
// what do i do for WebSocketFields.closing?
},
(data) => {
ws.dispatchEvent(
@ -91,11 +88,16 @@ export class AdriftBareClient extends Client {
}
);
(ws as any).__defineGetter__("send", () => (data: any) => {
send(data);
});
(ws as any).__defineSetter__("send", () => { });
// uv wraps it and we don't want that
// i can probably fix later but this is fine for now -CE
(ws as any).__defineSetter__("send", () => {});
(ws as any).__defineGetter__("close", (code?: number, reason?: string) => {
close(code, reason);
});
return ws;
}