Question
What is a good way for a client application to know when its Twilio Capability Token has expired?
More info
In my case, the client application is a Javascript application running inside a web browser.
The reason I ask is because I want to make sure that the client application (running in the web browser) is always ready to receive incoming calls that are intended for it. It occurs to me that if the Capability Token that the client application is using has expired, then calls to that application will probably fail without its knowledge.
The best solution I can thinking of so far is for the client application to keep track of the expiration on the Capability Token and automatically query the server for a new one shortly before it expires. (Using Javascript's setTimeout()
?
More ideally would be if Twilio.Device
in the Javascript library had a callback that could be set for when the token was about to expire. That way the client could listen to that can request a new token at that time.
Another solution could possibly be for the server to be able to extend the expiration of the client's Capability Token if it knows that a call has come into that is intended for that client. However this is functionality that Twilio may or may not provide.
What is a good way to handle this?