I am creating a chat widget using svelte. I want to display the websocket is connected or not using the websocket.readyState property, the readyState values as follows
the status i want to display in app header is
Well according this documentation you can use the events to know. MDN
0 CONNECTING Socket has been created. The connection is not yet open.
1 OPEN The connection is open and ready to communicate.
2 CLOSING The connection is in the process of closing.
3 CLOSED The connection is closed or couldn't be opened.
socket = new WebSocket(url) status is CONNECTINGonopen = (event) => { } status is OPENonclose or onerror status is CLOSEDsocket.close() status is CLOSINGIt might be some other situation for CLOSING but not something I know of.