I'm trying to figure out a way for my SockJS clients to reconnect to the server if it should go down.
I currently have this:
new_conn = function() {
socket = new SockJS(protocol + serverDomain + '/echo', null, {
'protocols_whitelist': ['websocket', 'xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']
});
};
socket.onopen = function () {
clearInterval(recInterval);
};
socket.onclose = function () {
recInterval = window.setInterval(function () {
new_conn();
}, 2000);
};
The problem is that the setInterval
keeps firing even after a successful reconnect. It seems that the socket.onopen
never gets executed.
Any ideas what I could be doing wrong?