Javascript 设备不是构造函数
我第一次将Twilio与VueJs一起使用,我得到一个错误:Javascript 设备不是构造函数,javascript,twilio,Javascript,Twilio,我第一次将Twilio与VueJs一起使用,我得到一个错误:Twilio.Device不是构造函数 我将遵循本教程: 这是我的代码: created(){ const Twilio = require("twilio"); let device; console.log("Requesting Access Token..."); // Using a relative link to acc
Twilio.Device不是构造函数
我将遵循本教程:
这是我的代码:
created(){
const Twilio = require("twilio");
let device;
console.log("Requesting Access Token...");
// Using a relative link to access the Voice Token function
getAPI.get("/api/contacts/token/")
.then(function (response) {
console.log("Got a token.");
console.log("Token: " + response.data.token);
// Setup Twilio.Device
device = new Twilio.Device(response.data.token, {
// Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and
// providing better audio quality in restrained network conditions. Opus will be default in 2.0.
codecPreferences: ["opus", "pcmu"],
// Use fake DTMF tones client-side. Real tones are still sent to the other end of the call,
// but the client-side DTMF tones are fake. This prevents the local mic capturing the DTMF tone
// a second time and sending the tone twice. This will be default in 2.0.
fakeLocalDTMF: true,
// Use `enableRingingState` to enable the device to emit the `ringing`
// state. The TwiML backend also needs to have the attribute
// `answerOnBridge` also set to true in the `Dial` verb. This option
// changes the behavior of the SDK to consider a call `ringing` starting
// from the connection to the TwiML backend to when the recipient of
// the `Dial` verb answers.
enableRingingState: true,
debug: true,
});
device.on("ready", function (device) {
console.log("Twilio.Device Ready!");
});
device.on("error", function (error) {
console.log("Twilio.Device Error: " + error.message);
});
device.on("connect", function (conn) {
console.log('Successfully established call ! ');
// $('#modal-call-in-progress').modal('show')
});
device.on("disconnect", function (conn) {
console.log("Call ended.");
// $('.modal').modal('hide')
});
})
.catch(function (err) {
console.log(err);
console.log("Could not get a token from server!");
});
}
您应该使用Twilio客户端而不是Twilio来发出请求
纱线添加斜纹布客户端
//或
npm安装twilio客户端
从twilio客户端导入设备
从“twilio客户端”导入{Device};//在顶部导入库,而不是放入created()
导出默认值{
...
//与您的代码相同,仅将导入移到顶部
创建(){
let装置;
log(“请求访问令牌…”);
//使用相对链接访问语音令牌功能
getAPI.get(“/api/contacts/token/”)
.然后(功能(响应){
log(“得到一个令牌”);
log(“令牌:+response.data.Token”);
//设置Twilio.Device
设备=新的twrio.device(response.data.token{
....
}
...
})
...
}
}
下面的答案对您有帮助吗?如果有,请接受。如果没有,请为我们提供更多信息。