I have a question about JS Kuzzle SDK and the "reconnected" event. In my team we are looking to build a service that connects to a Kuzzle instance and needs to run "indefinitely". This means we need to handle disconnection and reconnection. We used the events to handle that but we are having trouble to make it stable. We had problems with a code which looks like this :
this.kuzzle = new Kuzzle(new WebSocket(hostname, { port: port }), { offlineMode: "auto" });
const onConnected = async () => {
console.log('CONNECTED');
}
// This triggers correctly
this.kuzzle.addListener('connected', onConnected);
// This doesn't trigger
this.kuzzle.addListener('reconnected', onConnected);
// This triggers correctly
this.kuzzle.addListener('disconnected', () => {
console.log('disconnected');
});
this.kuzzle.connect().catch(e => console.log('connection error'));
Is there something we're missing out in configuration? And also, is there a reconnection timeout that stops the reconnection attempts after a certain number of attempts or amount of time?
Software versions : Kuzzle: 2.17.4 kuzzle-sdk: 7.10.0
Thanks in advance!
EDIT
The problem was not coming from Kuzzle and event not triggering but from using asynchronous actions inside the callbacks. As we needed to handle the authentication in these events, the solution was right there in front of us : the authenticator property.
this.kuzzle.authenticator = async () => {
if (!this.kuzzle.authenticated) {
await this.kuzzle.auth.login('local', credentials);
}
}
And it did the trick.