多个星号AMI连接与PAMI和React-PHP。

huangapple go评论77阅读模式
英文:

multiple asterisk ami connections with pami and react-php

问题

我正在使用PAMI与react-php和ratchet连接到Asterisk AMI,我有3个FreePBX服务器,希望在一个仪表板上连接到它们所有,并接收来自所有FreePBX服务器的所有事件。

这是我在php/laravel中编写的代码,用于连接到Asterisk AMI。
问题是,我可以使用PAMI和react-php连接到多个FreePBX服务器吗?

Artisan::command('asterisk:go', function () {
    $loop = React\EventLoop\Factory::create();
    $websockethandler = new \App\WebsocketHandler();
    $app = new Ratchet\App(
        'localhost',
        6001,
        '0.0.0.0',
        $loop
    );
    $app->route(
        '/websocket',
        $websockethandler,
        ['*']
    );
    $user = AsteriskServer::where('user_id', auth()->user()->id)->get();
    foreach ($user as $key => $us) {
        try {
            $ami = new \React\Stream\DuplexResourceStream(
                stream_socket_client("tcp://$us->pbx:5038"),
                $loop
            );
        } catch (\Exception $e) {
            die($e->getMessage());
        }
        $asteriskmanager[$key] = new App\AsteriskManager($ami);
        $asteriskmanager[$key]->login(
            $us->ami_username,
            $us->ami_password
        );
        $callcenter = new Callcenter($websockethandler, $asteriskmanager[$key]);
        $websockethandler->on('websocket.hello', [$callcenter, 'websocketHello']);
        $websockethandler->on('websocket.avail', [$callcenter, 'websocketSetAgentAvail']);
        $websockethandler->on('websocket.pause', [$callcenter, 'websocketSetAgentPause']);

        $asteriskmanager[$key]->on('agent.loggedin', [$callcenter, 'agentLoggedIn']);
        $asteriskmanager[$key]->on('agent.events', [$callcenter, 'agentEvents']);
        $asteriskmanager[$key]->on('agent.paused', [$callcenter, 'agentPaused']);
        $asteriskmanager[$key]->on('agent.avail', [$callcenter, 'agentAvail']);
    }

    $app->run();
})->purpose('Display an inspiring quote');

如果您有任何其他问题,请随时提出。

英文:

I'm using PAMI with react-php and ratchet to connect with asterisk ami, I have 3 freepbx servers and want to connect with all of them in one dashboard and receive all the events from all the freepbx servers.

Here is the code that I wrote in php/laravel to connect with Asterisk ami.
The question is, Can I use PAMI and react-php to connect to multiple freepbx servers?

Artisan::command('asterisk:go', function () {
$loop = React\\EventLoop\\Factory::create();
$websockethandler = new \\App\\WebsocketHandler();
$app = new Ratchet\\App(
'localhost',
6001,
'0.0.0.0',
$loop
);
$app->route(
'/websocket',
$websockethandler,
['\*'\]
);
$user               = AsteriskServer::where('user_id', auth()->user()->id)->get();
foreach($user as $key => $us){
try {

            $ami = new \React\Stream\DuplexResourceStream(
                stream_socket_client("tcp://$us->pbx:5038"),
                $loop
            );
    } catch (\Exception $e) {
        die($e->getMessage());
    }
    $asteriskmanager[$key] = new App\AsteriskManager($ami);
    $asteriskmanager[$key]->login(
        $us->ami_username,
        $us->ami_password
    );
    $callcenter = new Callcenter($websockethandler, $asteriskmanager[$key]);
    $websockethandler->on('websocket.hello', [$callcenter, 'websocketHello']);
    $websockethandler->on('websocket.avail', [$callcenter, 'websocketSetAgentAvail']);
    $websockethandler->on('websocket.pause', [$callcenter, 'websocketSetAgentPause']);
    
    $asteriskmanager[$key]->on('agent.loggedin', [$callcenter, 'agentLoggedIn']);
    $asteriskmanager[$key]->on('agent.events', [$callcenter, 'agentEvents']);
    $asteriskmanager[$key]->on('agent.paused', [$callcenter, 'agentPaused']);
    $asteriskmanager[$key]->on('agent.avail', [$callcenter, 'agentAvail']);

}

    $app->run();

})-\>purpose('Display an inspiring quote');

答案1

得分: 0

可以的,实际上您可以查看 https://github.com/clue/reactphp-ami,这是基于ReactPHP构建的对Asterisk Manager Interface (AMI)的流式、事件驱动访问方式。

英文:

Yes you can, in fact you can take a look at https://github.com/clue/reactphp-ami which is a streaming, event-driven access to the Asterisk Manager Interface (AMI), built on top of ReactPHP.

huangapple
  • 本文由 发表于 2023年7月6日 21:47:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629543.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定