MyPAGIApplication::run PHP Method

run() public method

(non-PHPdoc)
public run ( )
    public function run()
    {
        $this->log('Run');
        $client = $this->getAgi();
        $loggerFacade = $client->getAsteriskLogger();
        $loggerFacade->notice('hello notice');
        $loggerFacade->warn('hello warn');
        $loggerFacade->debug('hello debug');
        $loggerFacade->error('hello error');
        $loggerFacade->dtmf('hello dtmf');
        //$this->log($client->faxReceive('/tmp/a.tiff')->__toString());
        //$this->log($client->faxSend('/tmp/a.tiff')->__toString());
        $variables = $client->getChannelVariables();
        $this->log('Config dir: ' . $variables->getDirectoryConfig());
        $this->log('Config file: ' . $variables->getConfigFile());
        $this->log('Module dir: ' . $variables->getDirectoryModules());
        $this->log('Spool dir: ' . $variables->getDirectorySpool());
        $this->log('Monitor dir: ' . $variables->getDirectoryMonitor());
        $this->log('Var dir: ' . $variables->getDirectoryVar());
        $this->log('Data dir: ' . $variables->getDirectoryData());
        $this->log('Log dir: ' . $variables->getDirectoryLog());
        $this->log('Agi dir: ' . $variables->getDirectoryAgi());
        $this->log('Key dir: ' . $variables->getDirectoryKey());
        $this->log('Run dir: ' . $variables->getDirectoryRun());
        $this->log('Request: ' . $variables->getRequest());
        $this->log('Channel: ' . $variables->getChannel());
        $this->log('Language: ' . $variables->getLanguage());
        $this->log('Type: ' . $variables->getType());
        $this->log('UniqueId: ' . $variables->getUniqueId());
        $this->log('Version: ' . $variables->getVersion());
        $this->log('CallerId: ' . $variables->getCallerId());
        $this->log('CallerId name: ' . $variables->getCallerIdName());
        $this->log('CallerId pres: ' . $variables->getCallingPres());
        $this->log('CallingAni2: ' . $variables->getCallingAni2());
        $this->log('CallingTon: ' . $variables->getCallingTon());
        $this->log('CallingTNS: ' . $variables->getCallingTns());
        $this->log('DNID: ' . $variables->getDNID());
        $this->log('RDNIS: ' . $variables->getRDNIS());
        $this->log('Context: ' . $variables->getContext());
        $this->log('Extension: ' . $variables->getDNIS());
        $this->log('Priority: ' . $variables->getPriority());
        $this->log('Enhanced: ' . $variables->getEnhanced());
        $this->log('AccountCode: ' . $variables->getAccountCode());
        $this->log('ThreadId: ' . $variables->getThreadId());
        $this->log('Arguments: ' . intval($variables->getTotalArguments()));
        for ($i = 0; $i < $variables->getTotalArguments(); $i++) {
            $this->log(' -- Argument ' . intval($i) . ': ' . $variables->getArgument($i));
        }
        $result = $client->sayDigits('12345', '12#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say digits.');
        }
        $result = $client->sayNumber('12345', '12#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say number.');
        }
        $result = $client->getData('welcome', 10000, 4);
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for get data with: ' . $result->getDigits());
        }
        $result = $client->getOption('welcome', '0123456789*#', 10000);
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for get option.');
        }
        $result = $client->streamFile('welcome', '#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for stream file.');
        }
        $this->log('Channel status: ' . ChannelStatus::toString($client->channelStatus()));
        $this->log('Channel status: ' . ChannelStatus::toString($client->channelStatus($variables->getChannel())));
        $this->log('Variable: ' . $client->getVariable('EXTEN'));
        $this->log('FullVariable: ' . $client->getFullVariable('EXTEN'));
        $cdr = $client->getCDR();
        $this->log('CDRVariable: ' . $cdr->getSource());
        $cdr->setAccountCode('foo');
        $this->log('CDRVariable: ' . $cdr->getAccountCode());
        $callerId = $client->getCallerId();
        $this->log('CallerID: ' . $callerId);
        $callerId->setName('pepe');
        $this->log('CallerID: ' . $callerId);
        $client->setCallerId('foo', '123123');
        $this->log('CallerID: ' . $callerId);
        $this->log($client->exec('Dial', array('SIP/sip', 30, 'r')));
        $this->log($client->dial('SIP/01', array(30, 'r')));
        $result = $client->sayPhonetic('marcelog', '123#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say phonetic.');
        }
        $result = $client->sayAlpha('marcelog', '123#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say alpha.');
        }
        $result = $client->sayTime(time(), '123#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say time.');
        }
        $result = $client->sayDateTime(time(), 'mdYHMS', '123#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say datetime.');
        }
        $result = $client->sayDate(time(), '123#');
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for say date.');
        }
        $client->setPriority(1000);
        $client->setExtension(1000);
        $client->setContext('foo');
        $client->setMusic(true);
        sleep(10);
        $client->setMusic(false);
        $result = $client->waitDigit(10000);
        if (!$result->isTimeout()) {
            $this->log('Read: ' . $result->getDigits());
        } else {
            $this->log('Timeouted for waitdigit.');
        }
        $result = $client->record('/tmp/asd', 'wav', '#');
        if ($result->isInterrupted()) {
            if ($result->isHangup()) {
                $this->log('hangup when recording.');
            } else {
                $this->log('interrupted with: ' . $result->getDigits());
            }
            $this->log('Recorded: ' . $result->getEndPos());
        }
        //$this->log($client->databaseGet('SIP', 'Registry'));
        //$client->setAutoHangup(10);
        //sleep(20);
    }

Usage Example

示例#1
0
文件: example.php 项目: bit0rez/PAMI
 public function handle(EventMessage $event)
 {
     if ($event instanceof \PAMI\Message\Event\AsyncAGIEvent) {
         if ($event->getSubEvent() == 'Start') {
             switch ($pid = pcntl_fork()) {
                 case 0:
                     $logger = \Logger::getLogger(__CLASS__);
                     $this->_client = new ClientImpl($this->_pamiOptions);
                     $this->_client->open();
                     $agi = new \PAMI\AsyncAgi\AsyncClientImpl(array('pamiClient' => $this->_client, 'asyncAgiEvent' => $event));
                     $app = new MyPAGIApplication(array('pagiClient' => $agi));
                     $app->init();
                     $app->run();
                     //$agi->indicateProgress();
                     //$agi->answer();
                     //$agi->streamFile('welcome');
                     //$agi->playCustomTones(array("425/50","0/50"));
                     //sleep(5);
                     //$agi->indicateCongestion(10);
                     //$agi->hangup();
                     $this->_client->close();
                     echo "Application finished\n";
                     exit(0);
                     break;
                 case -1:
                     echo "Could not fork application\n";
                     break;
                 default:
                     echo "Forked Application\n";
                     break;
             }
         }
     }
 }
All Usage Examples Of MyPAGIApplication::run