示例#1
0
 public function __construct()
 {
     $configFile = __DIR__ . '/../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $ariAddress = $value['examples']['client']['ari_address'];
     $amiAddress = $value['examples']['client']['ami_address'];
     $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
     $client = new Phparia($logger);
     $client->connect($ariAddress, $amiAddress);
     $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->getWsClient()->on('Hangup', function ($event) {
             $this->log('User hung up');
         });
     });
     $this->client->run();
 }
示例#2
0
 /**
  * @param Playback $value
  */
 public function append($value)
 {
     if (!$value instanceof Playback) {
         throw new \InvalidArgumentException("Value must be of type Playback");
     }
     parent::append($value);
     // Remove playbacks when they are done playing
     $this->phparia->getWsClient()->once('PlaybackFinished', function (PlaybackFinished $playbackFinished) use($value) {
         if ($playbackFinished->getPlayback()->getId() === $value->getId()) {
             $key = array_search($value, $this->getArrayCopy());
             if ($key !== false) {
                 $this->offsetUnset($key);
             }
         }
     });
 }
示例#3
0
 /**
  * Remove CPD Result listener
  */
 public function removeCpdResult()
 {
     $this->phparia->getWsClient()->removeListener('CPD-Result', $this->cpdResultCallback);
 }