英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论