chan-sccp / PAMI

Fork of PHP Asterisk Manager Interface ( AMI ) supports synchronous command ( action )/ responses and asynchronous events using the pattern observer-listener. Supports commands with responses with multiple events. Very suitable for development of operator consoles and / or asterisk / channels / peers monitoring through SOA, etc
http://marcelog.github.com/PAMI
Apache License 2.0
27 stars 21 forks source link

VarSetEvent VariableName always null #13

Closed marayshi closed 4 years ago

marayshi commented 4 years ago

if ($event instanceof VarSetEvent){ var_dump($event->getVariableName()); }

Its always return Null

dkgroot commented 4 years ago

@marayshi Can you give me a bit of help. Which file are you referring to and what are you trying to do. Do you have some sample code for me to run, maybe ?

marayshi commented 4 years ago

Yes @dkgroot I'm trying to catch asterisk events specially ConfBridge events When try to make "ConfbridgeStartRecord" action i should get Varset events with record file path and the variable name should be "MIXMONITOR_FILENAME" So when i get this events i save the file path in the databases I have to check all variable names but i'm getting null check my code

try {
            $options = array(
                'host' =>  config('services.ami.AMI_HOST'),
                'scheme' => 'tcp://',
                'port' => 5038,
                'username' => config('services.ami.AMI_USER'),
                'secret' => config('services.ami.AMI_PASS'),
                'connect_timeout' => 10000,
                'read_timeout' => 10000
            );
            $pamiClient = new PamiClient($options);
            $pamiClient->open();

            $pamiClient->registerEventListener(

                function (EventMessage $event) use ($pamiClient) {
                    if ($event instanceof VarSetEvent){
                        var_dump($event->getVariableName()); // Null for all events
                        if ($event->getVariableName() === 'MIXMONITOR_FILENAME'){
                            $record_file_path = $event->getValue();
                            // ToDo Save the file path to database
                        }
                    }
                }
            );

            $running = true;
            while ($running) {
                $pamiClient->process();
                usleep(1000);
            }
            $pamiClient->close();
        }catch (\Exception $exception){
            var_dump($exception->getMessage());
        }
dkgroot commented 4 years ago

Ok will have a look to see what needs to be done, thanks for providing a testable sample.

dkgroot commented 4 years ago

I have updated the IncomingMessage.php handler to include the 'variable' key in the set. This fixes the problem AFAIK. Can you run a test using the current master branch. We can release a new version afterwards, if you need that for production.

marayshi commented 4 years ago

Thank you @dkgroot Thats work for me

I have other question about ConfbridgeStartRecordAction Action Its require conference name as parameter I wonder if i can customize it and use it like Monitor Asterisk application by passing variable like MONITOR_EXEC and use my own script to make combine two legs records and output stereo file `

!/usr/bin/sh

SOX=/usr/bin/sox PATH=/var/spool/asterisk/monitor/ $SOX $PATH$1.wav $PATH$2.wav --channels 2 --combine merge $PATH$3.wav remix 1,2v0.2 1v0.2,2 `

marayshi commented 4 years ago

Hi @dkgroot I made some custom class for monitor action it worked very well Really thank's for the amazing work

class MonitorAction extends ActionMessage{

    public function __construct($channel)
    {
        parent::__construct("Monitor");
        $this->setKey("Channel",$channel);
    }

    public function setFile($file){
        $this->setKey("File",$file);
    }

    public function setFormat($format){
        $this->setKey("Format",$format);
    }

    public function setMix($mix){
        $this->setKey('Mix', 1);
    }
}
marayshi commented 4 years ago

@dkgroot Sorry Just realized you already made this action class 👍 :)

dkgroot commented 4 years ago

Normally you would wait for the Conference to end before merging the streams. If you like you can do this from php by monitoring the event or you could just add a System() command to the dialplan to schedule a nice +5 /usr/bin/sox command in cron. Or have a daemon that does the combining, when you leave it a message etc... 1000 ways to do this (wrong ones would do it inside an asterisk thread, correct once schedule it outside).

dkgroot commented 4 years ago

Created a new release (v2.0.7) to include the patch.