mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(websocket): add missing close events and remove extra error event (#7606)
This commit is contained in:
parent
71a8b1fe27
commit
7713274efd
1 changed files with 23 additions and 13 deletions
|
@ -72,11 +72,6 @@
|
|||
this.dispatchEvent(event);
|
||||
core.close(this.#rid);
|
||||
});
|
||||
|
||||
const event = new Event("error");
|
||||
event.target = this;
|
||||
this.onerror?.(event);
|
||||
this.dispatchEvent(event);
|
||||
} else {
|
||||
this.#readyState = OPEN;
|
||||
const event = new Event("open");
|
||||
|
@ -100,13 +95,20 @@
|
|||
this.dispatchEvent(closeEvent);
|
||||
}
|
||||
}).catch((err) => {
|
||||
const event = new ErrorEvent(
|
||||
this.#readyState = CLOSED;
|
||||
|
||||
const errorEv = new ErrorEvent(
|
||||
"error",
|
||||
{ error: err, message: err.toString() },
|
||||
);
|
||||
event.target = this;
|
||||
this.onerror?.(event);
|
||||
this.dispatchEvent(event);
|
||||
errorEv.target = this;
|
||||
this.onerror?.(errorEv);
|
||||
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.dispatchEvent(event);
|
||||
} else if (message.type === "error") {
|
||||
const event = new Event("error");
|
||||
event.target = this;
|
||||
this.onerror?.(event);
|
||||
this.dispatchEvent(event);
|
||||
this.#readyState = CLOSED;
|
||||
|
||||
const errorEv = new Event("error");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue