glavweb/ kurento-client-php
PHP Kurento 客户端
0.2.0
2021-11-29 23:10 UTC
Requires
- php: >=7.1
- ext-json: *
- evenement/evenement: ^3.0
- psr/log: ^1.1
- ratchet/pawl: ^0.3.4
This package is auto-updated.
Last update: 2024-08-29 05:37:01 UTC
README
Kurento Client PHP 库,用于 Kurento WebRTC 媒体服务器,实现了 Kurento 协议 的客户端部分。
安装
安装此库最简单的方法是使用 composer。更新您的 composer.json
"repositories": [ { "type": "vcs", "url": "https://github.com/rukavina/kurento-client-php" } ], "require": { "rukavinamilan/kurento-client-php": "dev-master" }
然后运行
composer install
有关实际 Kurento WebRTC 媒体服务器安装的信息,请参阅 http://www.kurento.org/docs/current/installation_guide.html
使用方法
这是一个 hello world 示例。更多信息请参阅官方 教程页面。
<?php //composer autoload included require_once("vendor/autoload.php"); class DemoApp{ protected $offer = null; protected $loop; protected $logger; protected $wsUrl; protected $client; function __construct($offer, $wsUrl) { $this->offer = $offer; $this->wsUrl = $wsUrl; //required react even loop $this->loop = \React\EventLoop\Factory::create(); $this->logger = new \Zend\Log\Logger(); $writer = new \Zend\Log\Writer\Null(); $this->logger->addWriter($writer); } public function run(){ $this->client = \MgKurentoClient\KurentoClient::create($this->wsUrl, $this->loop, $this->logger, function($client){ $this->client->createMediaPipeline(function($pipeline, $success, $data){ $webRtcEndpoint = new \MgKurentoClient\WebRtcEndpoint($pipeline); $webRtcEndpoint->build(function($webRtcEndpoint, $success, $data){ $webRtcEndpoint->connect($webRtcEndpoint, function($success, $data) use ($webRtcEndpoint){ /* @var $webRtcEndpoint \MgKurentoClient\WebRtcEndpoint */ $webRtcEndpoint->processOffer($this->offer, function($success, $data){ echo $data['value']; //we don't need the loop anymore , we're exiting now $this->loop->stop(); }); }); }); }); }); $this->loop->run(); } } /* * Starting here */ //get raw post body $offer = file_get_contents('php://input'); //init the app $demoApp = new DemoApp($offer, 'ws://127.0.0.1:8888/kurento'); //start the app $demoApp->run();
通用元素
如果某些移除对象没有直接实现为 PHP 类,您仍然可以通过通用的 MediaObject
类创建和使用它们。它提供了通用方法
public function remoteCreate($remoteType, callable $callback, array $params = array()); public function remoteInvoke($operation, $operationParams, callable $callback); public function remoteRelease(callable $callback); protected function remoteSubscribe($type, $onEvent, callable $callback); public function remoteUnsubscribe($subscription, callable $callback);
使用通用类/方法的相同 hello world 示例可以按以下方式实现
$this->client = \MgKurentoClient\KurentoClient::create($this->wsUrl, $this->loop, $this->logger, function($client){ $this->client->createMediaPipeline(function($pipeline, $success, $data){ $webRtcEndpoint = new \MgKurentoClient\MediaObject($pipeline); $webRtcEndpoint->remoteCreate('WebRtcEndpoint', function($webRtcEndpoint, $success, $data){ $webRtcEndpoint->connect($webRtcEndpoint, function($success, $data) use ($webRtcEndpoint){ $webRtcEndpoint->remoteInvoke('processOffer', array('offer' => $this->offer), function($success, $data){ echo $data['value']; //we don't need the loop anymore , we're exiting now $this->loop->stop(); }); }); }); }); }); $this->loop->run();
示例安装
不要忘记首先安装 Kurento 服务器 http://www.kurento.org/docs/current/installation_guide.html
然后
git clone https://github.com/rukavina/kurento-client-php.git
composer install
然后检查每个特定示例文件夹中的 README
文件。
更多信息请参阅官方 教程页面。
需求
- Kurento Client PHP 与 PHP 5.3 或更高版本兼容。
- PHP WebSocket 库
作者
Milan Rukavina
许可
Kurento Client PHP 在 MIT 许可证下授权 - 有关详细信息,请参阅 LICENSE
文件
致谢
这个库受到了 Kurento 官方 Java 和 JavaScript 客户端的极大启发