Example #1
0
 public function __construct()
 {
     $configFile = __DIR__ . '/../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $ariAddress = $value['examples']['client']['ari_address'];
     $dialString = $value['examples']['dial_example']['dial_string'];
     $logger = new \Zend\Log\Logger();
     $logWriter = new \Zend\Log\Writer\Stream("php://output");
     $logger->addWriter($logWriter);
     //$filter = new \Zend\Log\Filter\SuppressFilter(true);
     $filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
     $logWriter->addFilter($filter);
     // Connect to the ARI server
     $this->client = new Phparia($logger);
     $this->client->connect($ariAddress);
     $this->client->getAriClient()->onConnect(function () use($dialString) {
         try {
             $this->client->channels()->createChannel($dialString, null, null, null, null, $this->client->getStasisApplicationName(), 'dialed', '8185551212', 30, null, null, array('MYVARIABLE' => 'value'));
         } catch (\phparia\Exception\ServerException $e) {
             $this->log($e->getMessage());
         }
     });
     // Listen for the stasis start
     $this->client->onStasisStart(function (StasisStart $event) use($dialString) {
         if (count($event->getArgs()) > 0 && $event->getArgs()[0] === 'dialed') {
             $this->log('Detected outgoing call with variable MYVARIABLE=' . $event->getChannel()->getVariable('MYVARIABLE')->getValue());
             // Put the new channel in a bridge
             $channel = $event->getChannel();
             $this->bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'dial_example_bridge');
             $this->bridge->addChannel($channel->getId());
         }
     });
     $this->client->run();
 }
 public function __construct()
 {
     $configFile = __DIR__ . '/../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $ariAddress = $value['examples']['client']['ari_address'];
     $dialString = $value['examples']['dial_example']['dial_string'];
     $logger = new Log\Logger();
     $logWriter = new Log\Writer\Stream("php://output");
     $logger->addWriter($logWriter);
     //$filter = new Log\Filter\SuppressFilter(true);
     $filter = new Log\Filter\Priority(Log\Logger::NOTICE);
     $logWriter->addFilter($filter);
     // Connect to the ARI server
     $this->client = new Phparia($logger);
     $this->client->connect($ariAddress);
     // Hangup this channel if the caller hangs up
     $this->client->onStasisEnd(function (StasisEnd $event) {
         $this->log("Channel {$event->getChannel()->getId()} no longer in stasis app, hanging up on dialed channel");
         $this->dialedChannel->hangup();
     });
     // Listen for the stasis start
     $this->client->onStasisStart(function (StasisStart $event) use($dialString) {
         if (count($event->getArgs()) > 0 && $event->getArgs()[0] === 'dialed') {
             $this->log('Detected outgoing call');
             $this->bridge->addChannel($event->getChannel()->getId());
             return;
             // Not an incoming call
         }
         // Put the new channel in a bridge
         $channel = $event->getChannel();
         $this->bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'dial_example_bridge');
         $this->bridge->addChannel($channel->getId());
         try {
             $this->dialedChannel = $this->client->channels()->createChannel($dialString, null, null, null, $this->client->getStasisApplicationName(), 'dialed', '8005551212');
         } catch (ServerException $e) {
             $this->log($e->getMessage());
         }
     });
     $this->client->run();
 }
Example #3
0
 /**
  * @todo Enable this again once it actually works from asterisk
  * @depends canSubscribe
  * @param \phparia\Resources\Bridge $bridge
  * @expectedException \phparia\Exception\ConflictException
  */
 public function canUnsubscribeThrowConflictException(Bridge $bridge)
 {
     $this->client->applications()->unsubscribe($this->client->getStasisApplicationName(), "bridge:{$bridge->getId()}");
     $this->client->applications()->unsubscribe($this->client->getStasisApplicationName(), "bridge:{$bridge->getId()}");
 }