Exemplo n.º 1
0
 public function __construct()
 {
     $configFile = __DIR__ . '/../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $ariAddress = $value['examples']['client']['ari_address'];
     $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
     $client = new \phparia\Client\Phparia($logger);
     $client->connect($ariAddress);
     $this->client = $client;
     // Listen for the stasis start
     $client->onStasisStart(function (StasisStart $event) {
         // Put the new channel in a bridge
         $channel = $event->getChannel();
         $bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'bridgename');
         $this->client->bridges()->addChannel($bridge->getId(), $channel->getId());
         // Listen for DTMF and hangup when '#' is pressed
         $channel->onChannelDtmfReceived(function (ChannelDtmfReceived $event) use($channel) {
             $this->log("Got digit: {$event->getDigit()}");
             if ($event->getDigit() === '#') {
                 $channel->hangup();
             }
         });
     });
     $this->client->run();
 }
Exemplo n.º 2
0
 public function tearDown()
 {
     $channels = $this->client->channels()->getChannels();
     foreach ($channels as $channel) {
         $channel->hangup();
     }
     parent::tearDown();
 }
Exemplo n.º 3
0
 /**
  * Stop all the playbacks
  */
 public function stop()
 {
     foreach (array_reverse($this->playbacks) as $playback) {
         try {
             $this->phparia->playbacks()->stopPlayback($playback);
         } catch (\Exception $ignore) {
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Stop all the playbacks
  */
 public function stop()
 {
     foreach (array_reverse($this->playbacks) as $playback) {
         try {
             $this->phparia->playbacks()->stopPlayback($playback->getId());
         } catch (\Exception $ignore) {
             // Don't throw exception if the playback does not exist
         }
     }
 }
Exemplo n.º 5
0
 public function setUp()
 {
     $configFile = __DIR__ . '/../../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $this->ariAddress = $value['tests']['ari_address'];
     $this->amiAddress = $value['tests']['ami_address'];
     $this->dialString = $value['tests']['dial_string'];
     $this->logger = new \Zend\Log\Logger();
     $logWriter = new \Zend\Log\Writer\Stream("php://output");
     $this->logger->addWriter($logWriter);
     //$filter = new \Zend\Log\Filter\SuppressFilter(true);
     $filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
     $logWriter->addFilter($filter);
     $this->client = new Phparia($this->logger);
     $this->client->connect($this->ariAddress, $this->amiAddress);
 }
Exemplo n.º 6
0
 /**
  * @param string $msg
  */
 protected function log($msg)
 {
     $logger = $this->client->getLogger();
     $logger->notice($msg);
 }
Exemplo n.º 7
0
 /**
  * Remove CPD Result listener
  */
 public function removeCpdResult()
 {
     $this->phparia->getWsClient()->removeListener('CPD-Result', $this->cpdResultCallback);
 }