我创建一个按钮来拨打电话,但是当我点击呼叫按钮并调用twilio连接对象时,它无法正常工作,它会调用断开连接对象。
这是我的代码
$accountSid = 'xxxx';
$authToken = 'xxx';
// put your TwiML Application Sid here
$appSid = 'xxxxx';
$capability = new ClientToken($accountSid, $authToken);
$capability->allowClientOutgoing($appSid);
$capability->allowClientIncoming('jenny');
$token = $capability->generateToken();
Twilio.Device.setup("<?php echo $token; ?>");
Twilio.Device.ready(function (device) {
$("#log").text("Ready");
});
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
Twilio.Device.connect(function (conn) {
$("#log").text("Successfully established call");
console.log(conn.status());
});
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
Twilio.Device.error(function (conn) {
$("#log").text("Call ended");
});
Twilio.Device.cancel(function(conn) {
console.log(conn.parameters.From); // who canceled the call
conn.status // => "closed"
});
Twilio.Device.incoming(function (conn) {
$("#log").text("Incoming connection from " + conn.parameters.From);
// accept the incoming connection and start two-way audio
conn.status
var ask = confirm("Incoming Call Please ANSWER");
if(ask){
console.log(conn.status());
conn.accept();
console.log(conn.status());
}else{
console.log(conn.status());
var a = conn.status();
console.log(a);
// Twilio.Device.disconnectAll();
}
});
function call() {
// get the phone number to connect the call to+19082900867
params = {"phone": $("#PhoneNumber").val(), "callerId": "+17203303808"};
connection = Twilio.Device.connect(params);
console.log(connection.status);
// Twilio.Device.connect();
}
function hangup() {
Twilio.Device.disconnectAll();
}
我不会出现什么问题,但是在演出开始时你已经准备就绪,但当我点击通话按钮时,它会显示你已经断开连接