【问题标题】:Twilio Client DTMF not workingTwilio 客户端 DTMF 不工作
【发布时间】:2012-07-01 21:26:16
【问题描述】:

我正在开发 Twilio 客户端应用程序,并且很难发送 DTMF 音调。这是我到目前为止的代码:

<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>

当我拨打我的测试号码并按下拨号盘上的按钮时,它不会发送值。非常感谢您对此提供任何帮助?

【问题讨论】:

  • 您好,只要阅读 javascript,您就可以在任何地方初始化 connection 变量并不清楚。另外,当您单击任何输入时,您能否通过 console.log 确认 each() 函数实际上正在执行?

标签: php javascript twilio


【解决方案1】:

在您的脚本块中,您需要有可用的连接对象。所以在你的函数之上,你需要类似的东西:

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

本质上,这个函数只需要“看到”连接变量。如果您的 javascript 文件位于不同的位置并且您无法合并它们,您可以将连接对象设为全局(不理想),至少看看您是否可以让它工作。

connection = null;

(首先没有“var”)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2015-03-04
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多