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(); }
public function tearDown() { $channels = $this->client->channels()->getChannels(); foreach ($channels as $channel) { $channel->hangup(); } parent::tearDown(); }
/** * Stop all the playbacks */ public function stop() { foreach (array_reverse($this->playbacks) as $playback) { try { $this->phparia->playbacks()->stopPlayback($playback); } catch (\Exception $ignore) { } } }
/** * 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 } } }
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); }
/** * @param string $msg */ protected function log($msg) { $logger = $this->client->getLogger(); $logger->notice($msg); }
/** * Remove CPD Result listener */ public function removeCpdResult() { $this->phparia->getWsClient()->removeListener('CPD-Result', $this->cpdResultCallback); }