Twilio JS客户端立即挂断

时间:2018-09-08 00:21:43

标签: twilio

我试图通过单击浏览器中的按钮来发起呼叫,以拨打英国的真实手机(我的手机,用于测试)。

我立即收到挂断声音,并收到一条控制台消息,提示“从网关接收到HANGUP”。

Called init
Twilio:812 Received token and setting up device
Device.setup @ twilio.min.js:55
(anonymous) @ Twilio:813
Promise.then (async)
init @ Twilio:811
created @ Twilio:796
callHook @ vendor.js?id=32f887f09d9fd70ffc0a:94704
Vue._init @ vendor.js?id=32f887f09d9fd70ffc0a:96413
VueComponent @ vendor.js?id=32f887f09d9fd70ffc0a:96581
createComponentInstanceForVnode @ vendor.js?id=32f887f09d9fd70ffc0a:96093
init @ vendor.js?id=32f887f09d9fd70ffc0a:95914
createComponent @ vendor.js?id=32f887f09d9fd70ffc0a:97391
createElm @ vendor.js?id=32f887f09d9fd70ffc0a:97338
patch @ vendor.js?id=32f887f09d9fd70ffc0a:97913
Vue._update @ vendor.js?id=32f887f09d9fd70ffc0a:94453
updateComponent @ vendor.js?id=32f887f09d9fd70ffc0a:94571
get @ vendor.js?id=32f887f09d9fd70ffc0a:94925
run @ vendor.js?id=32f887f09d9fd70ffc0a:95002
flushSchedulerQueue @ vendor.js?id=32f887f09d9fd70ffc0a:94764
(anonymous) @ vendor.js?id=32f887f09d9fd70ffc0a:93620
flushCallbacks @ vendor.js?id=32f887f09d9fd70ffc0a:93541
twilio.min.js:55 Setting up VSP
twilio.min.js:55 WSTransport.open() called...
twilio.min.js:55 Attempting to connect...
twilio.min.js:55 Closing and cleaning up WebSocket...
twilio.min.js:55 No WebSocket to clean up.
twilio.min.js:55 WebSocket opened successfully.
twilio.min.js:55 [PStream] Setting token and publishing listen
twilio.min.js:55 Stream is ready
Twilio:822 Connected and ready
Twilio:801 Trying to make a call
twilio.min.js:55 [Twilio.PeerConnection] signalingState is "have-local-offer"
twilio.min.js:55 Received HANGUP from gateway
twilio.min.js:55 Disconnecting...
twilio.min.js:55 [Twilio.PeerConnection] iceConnectionState is "closed"
twilio.min.js:55 [Twilio.PeerConnection] signalingState is "closed"

我正在使用Twilio JS客户端https://media.twiliocdn.com/sdk/js/client/v1.6/twilio.min.js的CDN版本。

我正在ngrok HTTP的URL上对其进行本地测试。

我正在使用AccessTokens,并且访问令牌没有收到任何错误,因此我认为该令牌完全有效。

用于生成我的令牌的代码为:

$token = new \Twilio\Jwt\AccessToken(
        $account_sid = "xxx",
        $api_key = "xxx",
        $api_secret = "xxx",
        $ttl = 3600,
        $identity = "example@example.com"
    );

    $voice = new \Twilio\Jwt\Grants\VoiceGrant();
    $voice->setOutgoingApplicationSid(
        $outgoing_sid = "xxx"
    );

    $token->addGrant($voice);

    return $token->toJWT();

我的客户代码如下:

makeCall() {
            console.log("Trying to make a call");
            Twilio.Device.connect({
                From: '+442921673534',
                To: '+447580007865',
            });
        },
        init() {
            console.log("Called init");
            Nova.request().get('/nova-vendor/alexbowers/nova-twilio-field/token').then(function(response) {
                console.log("Received token and setting up device");
                Twilio.Device.setup(response.data, {debug: true});
            });

            Twilio.Device.disconnect((e) => {
                // console.log(e);
                this.handleClose();
            });

            Twilio.Device.ready(function() {
                console.log("Connected and ready");
            });

            Twilio.Device.error(function(e) {
                // console.log(e);
                console.log("Handling error");
            });
        },

在点击时调用makeCall,在页面加载时调用init的地方。

1 个答案:

答案 0 :(得分:0)

我刚刚解决了同样的问题。 请检查您的 javascript twilio 客户端和后端中设置的参数是否匹配以获取参数。

获取twilio语音通话请求的后端代码

  let voiceResponse = new VoiceResponse();
  voiceResponse.dial({
    callerId: process.env.TWILIO_NUMBER,
  }, request.body.number);

前端代码

  Twilio.Device.connect({ number: "+86xxxxxxxxxxx" });

您必须确认前端和后端的关键“数字”相同。

祝你好运