0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(websocket): add missing close events and remove extra error event (#7606)

This commit is contained in:
crowlKats 2020-09-29 11:42:29 +02:00 committed by GitHub
parent 71a8b1fe27
commit 7713274efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,11 +72,6 @@
this.dispatchEvent(event); this.dispatchEvent(event);
core.close(this.#rid); core.close(this.#rid);
}); });
const event = new Event("error");
event.target = this;
this.onerror?.(event);
this.dispatchEvent(event);
} else { } else {
this.#readyState = OPEN; this.#readyState = OPEN;
const event = new Event("open"); const event = new Event("open");
@ -100,13 +95,20 @@
this.dispatchEvent(closeEvent); this.dispatchEvent(closeEvent);
} }
}).catch((err) => { }).catch((err) => {
const event = new ErrorEvent( this.#readyState = CLOSED;
const errorEv = new ErrorEvent(
"error", "error",
{ error: err, message: err.toString() }, { error: err, message: err.toString() },
); );
event.target = this; errorEv.target = this;
this.onerror?.(event); this.onerror?.(errorEv);
this.dispatchEvent(event); this.dispatchEvent(errorEv);
const closeEv = new CloseEvent("close");
closeEv.target = this;
this.onclose?.(closeEv);
this.dispatchEvent(closeEv);
}); });
} }
@ -285,10 +287,18 @@
this.onclose?.(event); this.onclose?.(event);
this.dispatchEvent(event); this.dispatchEvent(event);
} else if (message.type === "error") { } else if (message.type === "error") {
const event = new Event("error"); this.#readyState = CLOSED;
event.target = this;
this.onerror?.(event); const errorEv = new Event("error");
this.dispatchEvent(event); errorEv.target = this;
this.onerror?.(errorEv);
this.dispatchEvent(errorEv);
this.#readyState = CLOSED;
const closeEv = new CloseEvent("close");
closeEv.target = this;
this.onclose?.(closeEv);
this.dispatchEvent(closeEv);
} }
} }
} }