3

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>

テスト番号に電話してダイヤルパッドのボタンを押すと、値が送信されません。これに関する助けは大歓迎です?

4

1 に答える 1

2

スクリプトブロックでは、接続オブジェクトを使用可能にする必要があります。したがって、関数の上に、次のようなものが必要になります。

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

基本的に、この関数は接続変数を「見る」必要があります。javascriptファイルが別の場所にあり、それらを統合できない場合は、接続オブジェクトをグローバル(理想的ではない)にして、少なくともそれを機能させることができるかどうかを確認できます。

connection = null;

(最初に「var」なし)

于 2012-07-12T20:39:23.263 に答える