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?

图片转代码服务由CSDN问答提供 功能建议

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

 &lt; script type =“text / javascript”&gt; 
 $ .each(['0','1',  '2','3','4','5','6','7','8','9','star','pound'],函数(索引,值){
  $('#button'+ value).click(function(){
 if(connection){
 if(value =='star')
 connection.sendDigits('*')
 else if(value  =='pound')
 connection.sendDigits('#')
 else 
 connection.sendDigits(value)
 return false; 
} 
}); 
}); 
&lt; / script&gt  ; 
 
 
&lt; div id =“dialpad”&gt; 
&lt; table&gt; 
&lt; tr&gt; 
&lt; td&gt;&lt; input type =“button”value =“1”id =“  button1“&gt;&lt; / td&gt; 
&lt; td&gt;&lt; input type =”button“value =”2“id =”button2“&gt;&lt; / td&gt; 
&lt; td&gt;&lt;输入类型 =“button”value =“3”id =“button3”&gt;&lt; / td&gt; 
&lt; / tr&gt; 
&lt; tr&gt; 
&lt; td&gt;&lt; input type =“button”value =  “4”id =“button4”&gt;&lt; / td&gt; 
&lt; td&gt;&lt; input type =“button”value =“5”  id =“button5”&gt;&lt; / td&gt; 
&lt; td&gt;&lt; input type =“button”value =“6”id =“button6”&gt;&lt; / td&gt; 
&lt; / tr&gt;  
&lt; tr&gt; 
&lt; td&gt;&lt; input type =“button”value =“7”id =“button7”&gt;&lt; / td&gt; 
&lt; td&gt;&lt; input type =“button  “value =”8“id =”button8“&gt;&lt; / td&gt; 
&lt; td&gt;&lt; input type =”button“value =”9“id =”button9“&gt;&lt; / td&gt; \  n&lt; / tr&gt; 
&lt; tr&gt; 
&lt; td&gt;&lt; input type =“button”value =“*”id =“buttonstar”&gt;&lt; / td&gt; 
&lt; td&gt;&lt;  ; input type =“button”value =“0”id =“button0”&gt;&lt; / td&gt; 
&lt; td&gt;&lt; input type =“button”value =“#”id =“buttonpound”&gt;  &lt; / td&gt; 
&lt; / tr&gt; 
&lt; / table&gt; 
&lt; / div&gt; 
   
 
 

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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)

    点赞 评论

相关推荐 更多相似问题