I am currently writing a script utilising PAMI to communicate with an Asterisk server.
My code for originating a call is below:
public function store(Requests\CallRequest $request, ClientImpl $a)
{
$originateMsg = new OriginateAction('Local/' . $request->agent . '@auto-answer');
$originateMsg->setContext('G-Outgoing');
$originateMsg->setPriority('1');
$originateMsg->setExtension($request->dial);
$a->send($originateMsg);
while(true) {
if( $a->process() ) return redirect(route('call-hangup'));
usleep(1000);
}
$a->close();
}
The problem is, I have to set off an infinite while loop until a hangup request is made. $a->process()
calls the below method:
class VoipEventStart implements IEventListener
{
public function handle(EventMessage $event)
{
$a = $event->getKeys();
if( ($a['event'] == "Hangup" || $a['event'] == "HangupRequest") && strpos($a['channel'], 'SIP/') !== FALSE)
{
return true;
}
return false;
}
}
What I am after..
Is there anyway I can set this process running without the page looking like it's trying to load due to the while loop?
Can javascript be of any help? I did have the thought of using AJAX
to make the request, but it would still hit the while loop & stop until a call is hungup.