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);
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);
}
}
}