ไลบรารี kurento client php สำหรับเซิร์ฟเวอร์สื่อ Kurento WebRTC ซึ่งใช้งานฝั่งไคลเอ็นต์ของ Kurento Protocol
วิธีที่ง่ายที่สุดในการติดตั้งไลบรารีนี้คือการใช้ 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 );
ตัวอย่างสวัสดีชาวโลกเดียวกันนี้สามารถนำไปใช้ได้โดยใช้คลาส/วิธีการทั่วไปเช่น
$ 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
ไลบรารีนี้ได้รับแรงบันดาลใจอย่างมากจากไคลเอ็นต์ Java และ Javascript อย่างเป็นทางการของ Kurento