简体   繁体   English

Twilio.Device 不是构造函数

[英]Twilio.Device is not a constructor

I'm using Twilio with VueJs for the first time, and i'm getting an error: Twilio.Device is not a constructor我第一次将 Twilio 与 VueJs 一起使用,但出现错误: Twilio.Device is not a constructor

i'm following this tutorial: https://www.twilio.com/blog/make-receive-phone-calls-browser-twilio-programmable-voice-python-javascript我正在关注本教程: https://www.twilio.com/blog/make-receive-phone-calls-browser-twilio-programmable-voice-python-javascript

this is my code:这是我的代码:

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!");
            });
    }

You should use Twilio client instead of Twilio to make the request.您应该使用 Twilio 客户端而不是 Twilio 来发出请求。

yarn add twilio-client
// or
npm install twilio-client

Import Device from twilio client从 twilio 客户端导入设备

import { Device } from 'twilio-client'; // import the library at the top instead of putting in created()

export default {
   ...
   // same code as yours, only moved import to the top
   created() {
       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, {
                   ....
                }
              ...
             })
          ...
   }
} 
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用新令牌设置Twilio.Device? - How to setup Twilio.Device with new token? 如何检查Twilio.Device处理程序是否已存在 - How to check if Twilio.Device handlers already exist 我正在使用Twilio.Device Js构建自动拨号器 - I'm Building an auto dialer with Twilio.Device Js 销毁twilio.device之后连接仍然存在 - Connection still exist after Destroy twilio.device 在尝试为另一个应用程序设置新设备时未释放Twilio.Device实例 - Not releasing Twilio.Device instance on trying to setup new Device for another application TwilioRestClient和Twilio.Device有什么区别,为什么我可以使用RestClient打电话但不能发出实时声音? - What is the difference between TwilioRestClient and Twilio.Device, why I can call using RestClient but can't have live voice? Twilio 来电与<conference>没有响铃到代理 twilio.device.incoming</conference> - Twilio incoming call with <conference> not ringing to agent twilio.device.incoming Twilio:Twilio.Device.connect()未到达语音请求URL - Twilio: Twilio.Device.connect() not hitting voice request URL Twilio 对话 twilsock.InitRegistration() 不是构造函数 - Twilio Conversations twilsock.InitRegistration() is not a constructor Firebase函数上的TypeScript中twilio.AccessToken是“不是构造函数” - twilio.AccessToken is “not a constructor” in TypeScript on Firebase Functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM