ng2-STOMP-Over-WebSocket
ng2-STOMP-Over-WebSocket copied to clipboard
Reconnect handling
Hi @devsullo,
this module is really useful, thanks for it. Please help me, how can i handle the reconnect situation? My client lifecycle:
- connect
- subscribe
- connection lost (e.g.: backend error)
- reconnect
- -> and at this point i need to subscribe again.
--Ben
Hi, Thank you @ib1987
I think one way to do it is to pass 'subscribe' to onConnect method and every time when connection is no longer available module will try to reconnect and when connection established every 'subscribe' what we passed will happened inside onConnect method
I had the same problem. This was my old code, where after reconnection the subscriptions were lost:
stomp.startConnect().then(() => {
stomp.done('init')
stomp.subscribe( ... )
})
And this is the new working code: The subscriptions are renewed each time an onConnect event is received:
let originalOnConnect = stomp.onConnect
stomp.onConnect = (frame: any) => {
originalOnConnect(frame)
stomp.subscribe( ... )
}
stomp.startConnect().then(() => {
stomp.done('init')
})`
Feature request: It would be great if the library could manage the subscriptions automatically :blush: