Resolved: Twilio worker client disconnect reason

In this post, we will see how to resolve Twilio worker client disconnect reason

Question:

I’m trying to ensure single worker session/window at a time.
In order to achieve this I have added a parameter closeExistingSessions to the createWorker and it’s disconnecting (websocket) the other workerClient as expected.
Just wondering if there is a way to know the disconnect reason using this disconnected event listener so that I can show a relevant message to the end user.

Best Answer:

We are getting the reason (The reason the Worker websocket disconnected) as parameter to the disconnected callback.
And the reason for disconnecting due to existing sessions is 'Websocket disconnected due to new connection being registered'
Hope Twilio will keep their docs up to date

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com