Reputation: 1549
I have read many related answers but I don't find what I need. this answer uses a library
I am using websockets without library, and a Redux middleware.
The websocket does not disconnect continually, only occasionally disconnections happen.
The WebSocket is already in CLOSING or CLOSED state.
message is not caught by the onerror function. It is console logged on this line socket.onmessage = onMessage(store);
So I am trying
socket.onmessage = () => {
if (socket.readyState !== 1) {
console.error('Please try again later.') // this is just a test to try to handle the problem, it will not be the actua implentation
return
}
onMessage(store);
}
IT does not work, messages are never sent. I really need help.
Upvotes: 1
Views: 3036
Reputation: 111
You should to catch open and close ready states in onopen, onclose handlers.
For example:
socket.onclose = () => {
console.error('Please try again later.');
}
Upvotes: 2