如何在 Meteor JS 中初始化 Twilio 客户端?



我在Meteor JS中设置Twilio客户端时遇到了难以置信的困难,非常感谢任何帮助。

我已经提取了下面的相关代码和错误日志。据我所知,它应该很简单。代码只是抓取我之前生成的authtoken,然后尝试使用该authtoken设置设备。但它不起作用。

'click #initializeDevice'(event) {
var thisAuthToken = Session.get('myAuthToken');
console.log(thisAuthToken); // I have confirmed with Twilio support that these authtokens are correctly generated
const Device = require('twilio-client').Device;
Device.setup(thisAuthToken, { debug: true });
var myStatus = Device.status()
console.log(myStatus); //this is logging "offline"
Device.on('ready',function (device) {
log('Twilio.Device Ready!'); //this is not logging anything
});
},

当该代码运行时,它会生成以下日志:

eyJhbGciDpvdXRnb2luZz9hcHBTaWQ9QVA2NDE2MzJmMzA1ZjJiY2I[Note:I have deleted part of the middle of the logged authtoken for the purpose of this public post]5YmMxOGQyOWVlNGU2ZGM0NjdmMzRiNDVhNCIsImV4cCI6MTU3Nz0ygbJKTx15GgNCWDkm-iUPjn_O1NZU6yovp4vjE
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Setting up VSP
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 WSTransport.open() called...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Attempting to connect...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Closing and cleaning up WebSocket...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 No WebSocket to clean up.
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Could not connect to endpoint: ws does not work in the browser. Browser clients must use the native WebSocket object
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 Closing and cleaning up WebSocket...
modules.js?hash=69069bec9aeba9503ae3467590cf182be57d9e62:3605 No WebSocket to clean up.
calltemplate.js:31 offline

我从本地服务器完成这一切,通过 NGROK 隧道。我还设置了Twilio后端,链接了应用程序,购买了一个号码等。

据我所知,从日志来看,这个问题似乎与Meteor使用WebSockets的方式有关。

无法连接到端点:ws 在浏览器中不起作用。浏览器客户端必须使用本机 WebSocket 对象

这不是与流星相关的问题,而不是浏览器问题。

确保您的浏览器支持 WebRTC

顺便说一句,您的浏览器可能支持它,但您需要启用它。

最新更新