WebSocket alternatives for STOMP
September 7, 2012
I wrote previously about a hack to use SockJS with Stomp over WebSockets:
Stomp.WebSocketClass = SockJS;
// same as usual
var client = Stomp.client(url);
[...]
However, this was ugly and of limited use: the instantiation of the Web Socket was still done inside Stomp.client()
function.
Marek Majkowski then proposed to update the library to be able to pass any object conforming to the WebSocket type to enable all kind of cool stuff.
I have updated the library to use STOMP over any kind of WebSocket objects:
var ws = new SockJS(url);
var client = Stomp.over(ws);
// the rest of the code is the same
[...]
As written in the documentation, you can use Stomp.client(url)
to let the library create regular WebSockets or use Stomp.over(ws)
if you required another type of WebSocket.
Web Sockets for everyone!