PHP Version 5
Author: Marcelo Gornstein (marcelog@gmail.com)
Inheritance: implements PAMI\Client\IClient
コード例 #1
0
ファイル: Client.php プロジェクト: thomasvargiu/pami-module
 /**
  * Sends a message to AMI.
  *
  * @param OutgoingMessage $action Action to send
  *
  * @throws \PAMI\Client\Exception\ClientException
  *
  * @return \PAMI\Message\Response\ResponseMessage
  */
 public function sendAction(OutgoingMessage $action)
 {
     $params = new ArrayObject(['action' => $action]);
     $event = new Event(__FUNCTION__ . '.pre', $this, $params);
     $results = $this->getEventManager()->triggerEventUntil(function ($response) {
         return $response instanceof ResponseMessage;
     }, $event);
     if ($results->stopped()) {
         return $results->last();
     }
     $response = $this->connection->send($action);
     $params['response'] = $response;
     $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $params);
     return $response;
 }
コード例 #2
0
ファイル: example.php プロジェクト: alesf/PAMI
        } else {
            echo 'Unrecognized encoding - printing message in this encoding :  ';
            $event->getContentEncoding();
            echo '\\n Message:  ';
            $event->getContent();
        }
    }
}
////////////////////////////////////////////////////////////////////////////////
// Code STARTS.
////////////////////////////////////////////////////////////////////////////////
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
    $options = array('host' => $argv[1], 'port' => $argv[2], 'username' => $argv[3], 'secret' => $argv[4], 'connect_timeout' => 60, 'read_timeout' => 60);
    $a = new ClientImpl($options);
    $a->registerEventListener(new A());
    $a->open();
    // SMS
    $sms = new VGSMSMSTxAction();
    $sms->setContentType('text/plain; charset=ASCII');
    $msg = $argv[5];
    $phone = $argv[6];
    $sms->setContent($msg);
    $sms->setTo($phone);
    // SMS multipart MSG - This is used to send 1 big message splitted in several parts, up to 255 messages
    if ($argv[7] == 1) {
        $sms->setConcatRefId('58');
        $sms->setConcatTotalMsg('2');
        $sms->setConcatSeqNum('1');
        $a->send($sms);
コード例 #3
0
        if ($res != null) {
            $res->data_seek(0);
            while ($row = $res->fetch_assoc()) {
                $output[] = array('time' => $row['time'], 'with' => $row['with'], 'jid' => $row['jid'], 'body' => $row['body']);
            }
            // var_dump($output);
            return $output;
        } else {
            echo "mysqli error : " . $this->mysqli_openfire->error . "\n";
        }
    }
}
global $users;
date_default_timezone_set('Asia/Vladivostok');
$pamiClientOptions = array('log4php.properties' => __DIR__ . '/log4php.properties', 'host' => 'avanpbx', 'scheme' => 'tcp://', 'port' => 5038, 'username' => 'furiko', 'secret' => '123456', 'connect_timeout' => 10000, 'read_timeout' => 10000);
$pamiClient = new PamiClient($pamiClientOptions);
// Open the connection
$pamiClient->open();
$pamiClient->registerEventListener(function (EventMessage $event) {
    if ($event instanceof PAMI\Message\Event\BridgeEvent) {
        // $listeners[ext] = [jid][jid][jid]
        global $listeners;
        global $users;
        $channel1 = $event->getChannel1();
        $channel2 = $event->getChannel2();
        echo "Calls now {$channel1}~{$channel2}:> \n";
        if ($listeners) {
            if (isset($listeners[bare_ext($channel1)])) {
                if (is_array($listeners[bare_ext($channel1)])) {
                    foreach ($listeners[bare_ext($channel1)] as $listener) {
                        echo "listener {$listener} got for channel {$channel1}. Bridge \n";
コード例 #4
0
ファイル: example.php プロジェクト: rs-orlov/PAMI
use PAMI\Message\Action\DongleSendPDUAction;
class A implements IEventListener
{
    public function handle(EventMessage $event)
    {
        var_dump($event);
    }
}
////////////////////////////////////////////////////////////////////////////////
// Code STARTS.
////////////////////////////////////////////////////////////////////////////////
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
    $options = array('log4php.properties' => realpath(__DIR__) . DIRECTORY_SEPARATOR . 'log4php.properties', 'host' => $argv[1], 'port' => $argv[2], 'username' => $argv[3], 'secret' => $argv[4], 'connect_timeout' => $argv[5], 'read_timeout' => $argv[6], 'scheme' => 'tcp://');
    $a = new ClientImpl($options);
    $a->registerEventListener(new A());
    $a->open();
    var_dump($a->send(new DongleSendUSSDAction('dongle01', '*101#')));
    var_dump($a->send(new DongleSendPDUAction('dongle01', 'AT+CSMS=0 ')));
    var_dump($a->send(new DongleRestartAction('now', 'dongle01')));
    var_dump($a->send(new DongleResetAction('dongle01')));
    var_dump($a->send(new DongleReloadAction('now')));
    var_dump($a->send(new DongleStopAction('now', 'dongle01')));
    var_dump($a->send(new DongleStartAction('dongle01')));
    var_dump($a->send(new DongleSendSMSAction('dongle01', '+666666666', 'a message')));
    var_dump($a->send(new ListCommandsAction()));
    var_dump($a->send(new QueueStatusAction()));
    var_dump($a->send(new QueueStatusAction()));
    var_dump($a->send(new QueueStatusAction()));
    var_dump($a->send(new CoreShowChannelsAction()));
コード例 #5
0
ファイル: ListenCommand.php プロジェクト: opensoft/asterbunny
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pamiClientOptions = array('log4php.properties' => $input->getOption('log4php-configuration'), 'host' => $input->getOption('ami-host'), 'scheme' => 'tcp://', 'port' => $input->getOption('ami-port'), 'username' => $input->getOption('ami-username'), 'secret' => $input->getOption('ami-password'), 'connect_timeout' => $input->getOption('ami-connect-timeout'), 'read_timeout' => $input->getOption('ami-read-timeout'));
     $pamiClient = new ClientImpl($pamiClientOptions);
     $output->write("<comment>Opening asterisk connection... </comment>");
     $pamiClient->open();
     $output->writeln('<info>done</info>');
     $output->write("<comment>Opening rabbitmq connection... </comment>");
     $amqpConn = new AMQPConnection($input->getOption('rabbit-host'), $input->getOption('rabbit-port'), $input->getOption('rabbit-username'), $input->getOption('rabbit-password'), $input->getOption('rabbit-vhost'));
     $ch = $amqpConn->channel();
     $exchange = $input->getOption('rabbit-exchange-name');
     $ch->exchange_declare($exchange, 'fanout', false, true, false);
     $output->writeln('<info>done</info>');
     $i = 0;
     $counter = 0;
     $pamiClient->registerEventListener(function (EventMessage $event) use($output, $ch, $exchange, &$counter, &$i) {
         // Send to RabbitMQ
         $msg = new AMQPMessage(json_encode($event->getKeys()), array('content_type' => 'application/json', 'timestamp' => time(), 'delivery_mode' => 2));
         $ch->basic_publish($msg, $exchange);
         gc_collect_cycles();
         $output->writeln(sprintf(" >> <comment>[%s] [%s bytes]</comment> <info>%s</info>", date('Y-m-d G:i:s') . substr((string) microtime(), 1, 8), memory_get_usage(), $event->getName()));
         $counter = 0;
         $i = 0;
     });
     $closer = function ($autoExit = true) use($pamiClient, $amqpConn, $ch, $output) {
         $output->writeln('');
         $output->write('<comment>Closing ami connection... </comment>');
         $pamiClient->close();
         // send logoff and close the connection.
         $output->writeln("<info>done</info>");
         $output->write('<comment>Closing rabbitmq connection... </comment>');
         $ch->close();
         $amqpConn->close();
         $output->writeln("<info>done</info>");
         if ($autoExit) {
             exit(0);
         }
     };
     declare (ticks=1) {
         pcntl_signal(\SIGINT, $closer);
         pcntl_signal(\SIGTERM, $closer);
         while (true) {
             try {
                 usleep(1000);
                 // 1ms delay
                 $i++;
                 if ($i == 10000) {
                     // show some feedback every 10000 iterations or so, roughly every 10 seconds if nothing is processed
                     $counter++;
                     $output->writeln(sprintf(" >> <comment>Waiting for events... [%d seconds]</comment> <info>Ping...</info>", $counter * 10));
                     $i = 0;
                     // for every 10 seconds that go by, send a ping/pong event to the asterisk server
                     // if send times out, it'll throw an exception, which will end this script... supervisor should restart
                     /** @var ResponseMessage $pong  */
                     $pong = $pamiClient->send(new \PAMI\Message\Action\PingAction());
                     if ('Success' == $pong->getKey('response')) {
                         // Send the pong event onto RabbitMQ.  This has a faux keep-alive effect on the RabbitMQ connection
                         $msg = new AMQPMessage(json_encode($pong->getKeys()), array('content_type' => 'application/json', 'timestamp' => time(), 'delivery_mode' => 2));
                         $ch->basic_publish($msg, $exchange);
                         $output->writeln(sprintf(" >> <comment>[%s] [%s bytes]</comment> <info>%s</info>", date('Y-m-d G:i:s') . substr((string) microtime(), 1, 8), memory_get_usage(), 'Pong'));
                     }
                 }
                 $pamiClient->process();
             } catch (\Exception $e) {
                 // try to close any connections
                 $closer(false);
                 // rethrow the exception
                 throw $e;
             }
         }
     }
     $closer(false);
     return 0;
 }
コード例 #6
0
ファイル: PamiHelper.php プロジェクト: im286er/Ding
 /**
  * Closes the connection to ami.
  *
  * return void
  */
 public function close()
 {
     $this->_ami->close();
 }
コード例 #7
0
ファイル: Client.php プロジェクト: dafik/dfi
 public function __construct($options)
 {
     $logger = new Dfi_Asterisk_Logger(Zend_Registry::get('debugLogger'));
     parent::__construct($options, $logger);
 }