Twilio Client DTMF not working

Twilio Client DTMF not working

本文关键字:working not DTMF Client Twilio      更新时间:2023-09-26

我正在开发一个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>

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

在脚本块中,需要有可用的连接对象。因此,在您的函数之上,您需要类似以下内容:

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

本质上,此函数只需要"查看"连接变量。如果你的javascript文件位于不同的地方,并且你无法整合它们,你可以至少使连接对象全局(不理想),看看你是否可以让它工作。

connection = null;

(首先没有"var")