takenet / blip-sdk-js

The Javascript SDK for BLiP
https://blip.ai
MIT License
32 stars 12 forks source link

Auto recover routine #18

Open devleste opened 4 years ago

devleste commented 4 years ago

I've been using this sdk for roughly 4 months now.

Since day one I suffer from situations where the connected instance simply stop receiving or sending messages, without emitting any error ou timeout events.

The customer sends a message from its device and nothing reaches my server. At the same time, I send a message to a customer and despite the sdk seemingly accepting the command, the message does not reach the customer.

At the moment, this problem is being detected only by observation, after several minutes of failing communications. The workaround is a total script restart, manually.

I can't provide solid evidence because, as I said, no error events are emitted whatsover. A blank log file would do no good here.

The main point here is: there has to be a way to realiably know the integrity of the current connected instance. Maybe some internal periodical routine or a more robust event system that allow us to develop our own routines.

Thanks in advance.

ceifa commented 4 years ago

When the transport is disconnected, it will try to reconnect 10 times, after that if it fails to reconnect it will throw an error. Have you tried to put a try-catch block to get if any error was thrown?

If no error are been throwed you can enable a trace when building the transport:

.withTransportFactory(() => new WebSocketTransport(undefined, true)) // the second argument means the trace should be enabled

The trace can bring for you more meaningful logs.

However, if you want to build your own routine to check if the connection is alive you can use the listening property inside the blip client instance.