mirror of
https://github.com/MercuryWorkshop/bare-mux.git
synced 2025-05-14 14:50:03 -04:00
im dumb
This commit is contained in:
parent
fae6b90225
commit
4b1c06d484
1 changed files with 15 additions and 6 deletions
|
@ -37,11 +37,14 @@ export class BareWebSocket extends EventTarget {
|
||||||
};
|
};
|
||||||
const event = new Event("open")
|
const event = new Event("open")
|
||||||
this.dispatchEvent(event);
|
this.dispatchEvent(event);
|
||||||
|
if (this.onopen) {
|
||||||
this.onopen(event);
|
this.onopen(event);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onmessage = async (payload) => {
|
const onmessage = async (payload) => {
|
||||||
if ("byteLength" in payload) {
|
if (typeof payload === "string") {
|
||||||
|
} else if ("byteLength" in payload) {
|
||||||
if (this.binaryType === "blob") {
|
if (this.binaryType === "blob") {
|
||||||
payload = new Blob([payload]);
|
payload = new Blob([payload]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,21 +59,27 @@ export class BareWebSocket extends EventTarget {
|
||||||
|
|
||||||
const event = new MessageEvent("message", {data: payload });
|
const event = new MessageEvent("message", {data: payload });
|
||||||
this.dispatchEvent(event);
|
this.dispatchEvent(event);
|
||||||
|
if (this.onmessage) {
|
||||||
this.onmessage(event);
|
this.onmessage(event);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onclose = (code: number, reason: string) => {
|
const onclose = (code: number, reason: string) => {
|
||||||
this.readyState = WebSocketFields.CLOSED;
|
this.readyState = WebSocketFields.CLOSED;
|
||||||
const event = new CloseEvent("close", { code, reason })
|
const event = new CloseEvent("close", { code, reason })
|
||||||
this.dispatchEvent(event);
|
this.dispatchEvent(event);
|
||||||
this.onclose(event)
|
if (this.onclose) {
|
||||||
|
this.onclose(event);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onerror = () => {
|
const onerror = () => {
|
||||||
this.readyState = WebSocketFields.CLOSED;
|
this.readyState = WebSocketFields.CLOSED;
|
||||||
const event = new Event("error");
|
const event = new Event("error");
|
||||||
this.dispatchEvent(event)
|
this.dispatchEvent(event);
|
||||||
this.onerror(event)
|
if (this.onerror) {
|
||||||
|
this.onerror(event);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.channel = new MessageChannel();
|
this.channel = new MessageChannel();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue