Open techniq opened 9 years ago
FYI, I worked around the issue by using popular einaros/ws library and listening to setting up a handler for the onerror
callback.
var WebSocket = require('ws');
WebSocket.prototype.onerror = function(e) {
throw e
};
var ws = new WebSocket(config.uri);
client = Stomp.over(ws);
My actual implementation wraps all of this in a Promise
(and I reject the promise within the onerror
), but this should help someone else who runs into this issue.
When using Node and the websocket API (
Stomp.overWS('ws://...')
, if the server is unavailable (service is down, wrong URL, etc),client.connect(...)
fails silently (neither success or failure callback is called). I looked into the bundled WebSocket client and it appears it has aconnectFailed
event for these situations:I've ran into this issue on a project where I will reboot the server and expect the clients to reconnect, but they hang on the next
client.connect(...)
call while the server is starting back up. I think it would be best if the event was watched and an error thrown (or the failure callback is called):Somewhat related, It would also be nice if a custom WebSocket library could be used in place of the
theturtle32/WebSocket-Node
one (like stomp's browser API allows). For example, using the popular einaros/ws library:This library matches the W3C spec more closely and will throw an exception while creating an instance of
WebSocket
, just like the browser does. Note: theturtle32/WebSocket-Node has aW3CWebSocket
API, but it does not throw an exception while creating an instance ofW3CWebSocket