1

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.

jakehallas
  • 2,456
  • 1
  • 18
  • 26
  • You should not do dialling core without experience. Check vicidial.org or other OS projects for dialling core variant. You can use ARI or AMI interface to spot events/end of dialling or you can use FastAGI interface to control call. – arheops Nov 30 '15 at 23:11
  • I am having different issues, I am using PAMI and when the dialed extension picks up the call it dials other local extension numbers automatically and does not dial to the customer number :( – shzyincu Sep 28 '17 at 11:09

1 Answers1

0

You should not couple your web application to your telephony backend. Async is the way to go.

In the best scenario you would write you web application so it can use websockets, long polling, SSE, or a 3rd party service that can be used to deliver events to your web application and coming in from "the backend" in an async way.

The requests from you web application to your "backend" can be done in the traditional way (by using HTTP requests) or using websockets.

"The backend" could be a process (or an ecosystem of processes communicated by a message bus) that runs in the background, listening for interesting events coming in from you PBXs and your web clients, and then deliver them to your web application or PBXs by any means necessary.

Example:

  1. A user presses the "call" button.
  2. Your web application issues an HTTP request to a web controller.
  3. A web controller receives the request and injects a json payload into your message bus with the dialing information.
  4. A worker listening for the right type of payloads "picks this up" and chooses a random asterisk node to issue the dial.
  5. The Originate action is sent to the chosen node.
  6. One or more processes listening for events coming in from the different Asterisk nodes pick up the dial events and send them to your web application via the websocket. You should be able to "bind" one or more channels or action ids to the right web client.

You could also use SSE from your web application to listen for events.

I know, I highly reduced all the gory details and complexities, just to give you an idea of how decoupling the different parts of your application will do some good in your current architecture :)

Makes sense?

Cheers!

marcelog
  • 7,062
  • 1
  • 33
  • 46
  • I am having different issues, I am using PAMI and when the dialed extension picks up the call it dials other local extension numbers automatically and does not dial to the customer number :( – shzyincu Sep 28 '17 at 11:09