stomp-js / stomp-websocket

Stomp client for Web browsers and node.js apps
https://stomp-js.github.io/stomp-websocket/
Apache License 2.0
141 stars 36 forks source link

Add ability to update URL during reconnect #41

Closed Edvinas01 closed 5 years ago

Edvinas01 commented 6 years ago

Context Before creating stomp client, my users fetch jwt from the back-end. Then using that jwt a url is formed which is later used in stomp client:


const stomp = require('...');

const jwt = 'some token from back-end';
const client = stomp.client(`${url}/stomp?token=${jwt}`);

client.reconnect_delay = 1000;

Issue If client loses connection to the back-end, it tries to reconnect. However the jwt which was used to initialize it can be expired. Which means the client will not be able to reconnect and will start looping in such case.

Proposed solution Add a reconnect hook which would allow to alter url before reconnecting.

kum-deepak commented 6 years ago

I do understand the issue. However the way current code is structured the solution is not going to be straightforward.

Currently I am working at rewriting this library - see: https://github.com/stomp-js/stompjs/issues/1. This will be taken as a feature request there. I will not be able to work on this as of now.

If you need a solution now, I suggest one of the following:

kum-deepak commented 5 years ago

Fixed in v5.0.0. Please upgrade https://stomp-js.github.io/stompjs/additional-documentation/upgrading.html