客户端知道 Twilio 功能令牌何时过期的好方法 [英] Good way for the client to know when a Twilio Capability Token has expired

查看:16
本文介绍了客户端知道 Twilio 功能令牌何时过期的好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端应用程序知道其 Twilio 功能令牌何时过期的好方法是什么?

What is a good way for a client application to know when its Twilio Capability Token has expired?

就我而言,客户端应用程序是在 Web 浏览器中运行的 Javascript 应用程序.

In my case, the client application is a Javascript application running inside a web browser.

我之所以这么问是因为我想确保客户端应用程序(在 Web 浏览器中运行)始终准备好接收针对它的来电.我突然想到,如果客户端应用程序使用的能力令牌已过期,则对该应用程序的调用可能会在其不知情的情况下失败.

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.

到目前为止,我能想到的最佳解决方案是让客户端应用程序跟踪 Capability Token 的过期时间,并在过期前不久自动向服务器查询新的.(使用 Javascript 的 setTimeout()?

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()?

更理想的是,如果 Javascript 库中的 Twilio.Device 有一个回调,可以在令牌即将到期时设置回调.这样客户端就可以监听到那个时候可以请求一个新的令牌.

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.

另一个解决方案可能是服务器能够延长客户端能力令牌的到期时间,如果它知道已经有一个针对该客户端的调用.但是,这是 Twilio 可能提供也可能不提供的功能.

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.

有什么好的处理方法?

推荐答案

您提到的使用 setTimeout() 的技术是一种完全有效的管理方法.由于您的应用程序设置了到期时间,因此您可以设置一个与请求新令牌一致的未来函数调用.

The technique you mentioned using setTimeout() is a completely valid way to manage this. Since your application sets the expiry time, you can set a future function call that coincides to request a new token.

或者,如果您更喜欢回调,您可以实现 Twilio.Device 的 离线处理程序.当令牌过期或 Internet 连接断开时调用此方法.无论哪种方式,您都需要一个新令牌来重新建立您的离线客户端与 Twilio 的连接.

Alternately, if you prefer a callback you can implement Twilio.Device's offline handler. This is called when the token expires, or the Internet connection drops. Either way you'll need a new token to re-establish your offline Client's connection to Twilio.

您可以在文档技能培训.

这篇关于客户端知道 Twilio 功能令牌何时过期的好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆