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:
parent
71a8b1fe27
commit
7713274efd
1 changed files with 23 additions and 13 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue