kurento client php
1.0.0
Kurento WebRTC 媒體伺服器的kurento client php函式庫,它實作了 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
這是你好世界的例子。在官方教學頁面上閱讀更多內容。
<?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 MgKurentoClientWebRtcEndpoint */
$ 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已根據 MIT 許可證獲得許可 - 有關詳細信息,請參閱LICENSE
文件
該函式庫深受 Kurento 的官方 java 和 javascript 用戶端的啟發