fix(websocket): add missing close events and remove extra error event
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");
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);
});
}
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);
}
}
}
