I'm using Twilio Outgoing Browser Calls in my project. The twiml to make call is like this :
<Response>
<Dial action="hold_twiml.php" callerId="xxxxxxxxxx">
xxxxxxxxxx
</Dial>
</Response>
hold_twiml.php
if ( $_REQUEST['DialCallStatus'] == 'completed' ) { ?>
<Response>
<Hangup/>
</Response>
<?php
}
else {
?>
<Response>
<Play>http://demo.twilio.com/docs/classic.mp3</Play>
<Redirect>hold_twiml.php</Redirect>
</Response>
<?php
}
?>
I want to disconnect the call when the call ends from client/browser. For that I've added the if ( $_REQUEST['DialCallStatus'] == 'completed' )
condition and now the call is getting ended from both sides. But now the Hold feature is not working properly. When I click the hold button the following code will be executed.
if ( $action == 'hold' ) {
$url = "holding_twiml.php";
$call = $client->calls->read(
array("ParentCallSid" => $_POST['callSid'])
)[0];
} else { // unhold
$call = $client->calls($_POST['callSid'])->fetch();
$url = "redirecting_twiml.php";
}
$call->update(
array(
"url" => $url,
"method" => "POST"
)
);
holding_twiml.php
<Response>
<Enqueue waitUrl="hold_music_twiml.xml">xx</Enqueue>
</Response>
hold_music_twiml.xml
<Response>
<Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>
redirecting_twiml.php
<Response>
<Dial action="hold_twiml.php">
<Queue>xx</Queue>
</Dial>
</Response>
Now on clicking Hold, the call on browser is getting ended and the call over client(phone) is put into hold.
Can anyone help me to fix the issue? Thanks in advance.