2012-07-01 130 views
1

我正在使用Twilio客戶端應用程序,而且我很難發送DTMF音調。這裏是我到目前爲止的代碼: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> 

當我打電話給我的測試號碼,再按撥號盤上的按鈕不發送的值。任何幫助,這是非常感謝?

+0

嗨,只是讀的JavaScript提供目前尚不清楚你在任何地方初始化'connection'變量。另外,您是否可以使用console.log確認當您單擊任何輸入時,each()函數實際上正在執行? –

回答

1

在你的腳本塊中,你需要有連接對象可用。所以在你的功能之上,你需要類似的東西:

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

本質上,這個函數只需要「看」連接變量。如果你的javascript文件位於不同的地方,並且你不能整合它們,你可以使連接對象成爲全局的(不理想的),至少看看你能否得到它的工作。

connection = null; 

(不帶 「VAR」 第一)