duanhuiuw12555 2012-07-01 21:26
浏览 56
已采纳

Twilio客户端DTMF无法正常工作

I am working on a Twilio Client application and I am having a hard time sending DTMF tones. Here is the code I have so far:

<script type="text/javascript">
$.each(['0','1','2','3','4','5','6','7','8','9','star','pound'], function(index, value) { 
    $('#button' + value).click(function(){ 
        if(connection) {
            if (value=='star')
                connection.sendDigits('*')
            else if (value=='pound')
                connection.sendDigits('#')
            else
                connection.sendDigits(value)
            return false;
        } 
     });
  });
</script>


<div id="dialpad">
    <table>
    <tr>
    <td><input type="button" value="1" id="button1"></td>
    <td><input type="button" value="2" id="button2"></td>
    <td><input type="button" value="3" id="button3"></td>
    </tr>
    <tr>
    <td><input type="button" value="4" id="button4"></td>
    <td><input type="button" value="5" id="button5"></td>
    <td><input type="button" value="6" id="button6"></td>
    </tr>
    <tr>
    <td><input type="button" value="7" id="button7"></td>
    <td><input type="button" value="8" id="button8"></td>
    <td><input type="button" value="9" id="button9"></td>
    </tr>
    <tr>
    <td><input type="button" value="*" id="buttonstar"></td>
    <td><input type="button" value="0" id="button0"></td>
    <td><input type="button" value="#" id="buttonpound"></td>
    </tr>
    </table>
</div>

When I call my test number and press a button on the dialpad it does not send the values. Any help on this is greatly appreciated?

  • 写回答

1条回答 默认 最新

  • douhuan5073 2012-07-12 20:39
    关注

    In your script block you need to have the connection object available. So above your function, you'll need something like:

    var connection = null;
    Twilio.Device.setup('your token');
    params = { "number" : "5559871234", "outbound" : "true" };
    connection = Twilio.Device.connect(params);
    

    Essentially, this function just needs to "see" the connection variable. If your javascript files are in different places and you can't consolidate them, you can make the connection object global (not ideal) at least to see if you can get it working.

    connection = null;
    

    (without the "var" first)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私