<?php
/*
* This file is part of the Kurento Client php package.
*
* (c) Milan Rukavina
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require_once("../../vendor/autoload.php");
use Devristo\Phpws\Framing\WebSocketFrame;
use Devristo\Phpws\Framing\WebSocketOpcode;
use Devristo\Phpws\Messaging\WebSocketMessageInterface;
use Devristo\Phpws\Protocol\WebSocketTransportInterface;
use Devristo\Phpws\Server\IWebSocketServerObserver;
use Devristo\Phpws\Server\UriHandler\WebSocketUriHandler;
use Devristo\Phpws\Server\WebSocketServer;
/**
* This CallHandler handler below will respond to all messages sent to /call (e.g. ws://localhost:8080/call)
*
* first run WS server with php index.php
*/
class CallHandler extends WebSocketUriHandler {
protected $loop = null;
protected $registry = array();
protected $pipelines = array();
/**
*
* @var \MgKurentoClient\KurentoClient
*/
protected $client = null;
/**
*
* @var \MgKurentoClient\Interfaces\MediaPipeline
*/
protected $pipeline = null;
protected $wsUrl = 'ws://127.0.0.1:8888/kurento';
/**
*
* @var \MgKurentoClient\WebRtcEndpoint
*/
protected $webRtcEndpoint = null;
function __construct($logger, $loop) {
$this->loop = $loop;
parent::__construct($logger);
$this->client = \MgKurentoClient\KurentoClient::create($this->wsUrl, $this->loop, $this->logger, function($client){
$this->logger->notice("KurentoClient created");
});
}
/**
* A client disconnected
*
* @param WebSocketTransportInterface $session
*/
public function onDisconnect(WebSocketTransportInterface $session){
unset($this->registry[$session->getId()]);
}
protected function sendResponse(WebSocketTransportInterface $session, $id, $response, $message = '', $params = array()){
$resultParams = array_merge(array(
"id" => $id,
"response" => $response,
"message" => $message
), $params);
$session->sendString(json_encode($resultParams, JSON_UNESCAPED_SLASHES));
}
/**
* New message
*
* @param WebSocketTransportInterface $session
* @param WebSocketMessageInterface $msg
*/
public function onMessage(WebSocketTransportInterface $session, WebSocketMessageInterface $msg) {
$message = json_decode($msg->getData(), true);
/* @var $user UserSession */
$user = null;
if(isset($this->registry[$session->getId()])){
$user = $this->registry[$session->getId()];
$this->logger->notice("message: " . $msg->getData() . " from User: " . $user->getName());
}
else{
$this->logger->notice("message: " . $msg->getData() . " from new User");
}
switch ($message['id']) {
case 'register':
$this->register($session, $message);
break;
case 'call':
$this->call($user, $message);
break;
case 'incomingCallResponse':
$this->incomingCallResponse($user, $message);
break;
case 'play':
$this->play($session, $message);
case 'stop':
$this->stop($session);
break;
default:
break;
}
}
/**
* Name exists
*
* @param string $name
* @return boolean
*/
protected function registryNameExists($name){
return $this->registryGetByName($name) !== false;
}
/**
* Get user
*
* @param string $name
* @return boolean|UserSession
*/
protected function registryGetByName($name){
/* @var $user UserSession */
foreach ($this->registry as $sessionId => $user) {
if($name == $user->getName()){
return $this->registry[$sessionId];
}
}
return false;
}
public function register(WebSocketTransportInterface $session, array $message){
$responseMsg = "accepted";
if (!isset($message['name']) || $message['name'] == '') {
$responseMsg = "rejected: empty user name";
} elseif ($this->registryNameExists($message['name'])) {
$responseMsg = "rejected: user '" . $message['name'] . "' already registered";
} else {
$user = new UserSession($session, $message['name']);
$this->registry[$session->getId()] = $user;
}
return $this->sendResponse($session, 'resgisterResponse', $responseMsg);
}
public function call(UserSession $caller, array $message){
$to = $message['to'];
$from = $message['from'];
if ($this->registryNameExists($to)) {
$callee = $this->registryGetByName($to);
$callee->setCallingFrom($from);
$caller->setSdpOffer($message["sdpOffer"]);
$caller->setCallingTo($to);
return $this->sendResponse($callee->getSession(), 'incomingCall', '', '', array('from' => $from));
} else {
return $this->sendResponse($caller->getSession(), 'callResponse', "rejected: user '" . $to . "' is not registered");
}
}
public function incomingCallResponse(UserSession $callee, array $message){
$callResponse = $message['callResponse'];
$caller = $this->registryGetByName($message['from']);
if ("accept" == $callResponse) {
$this->logger->notice("Accepted call from: " . $message['from'] . " from User: " . $callee->getName());
$pipeline = null;
$callee->setSdpOffer($message["sdpOffer"]);
try {
$pipeline = new CallMediaPipeline($this->client, $caller->getName(), $callee->getName(), function($pipeline) use ($message, $callee, $caller) {
$this->pipelines[$caller->getSession()->getId()] = $pipeline;
$this->pipelines[$callee->getSession()->getId()] = $pipeline;
$pipeline->generateSdpAnswerForCallee($callee->getSdpOffer(), function ($success, $data) use($pipeline, $caller, $callee){
$calleeSdpAnswer = $data['value'];
$pipeline->generateSdpAnswerForCaller($caller->getSdpOffer(), function ($success, $data) use ($pipeline, $calleeSdpAnswer, $caller, $callee){
//start recoding imidiatelly
$pipeline->record(function($success, $data){});
$callerSdpAnswer = $data['value'];
$this->sendResponse($callee->getSession(), 'startCommunication', '', '', array('sdpAnswer' => $calleeSdpAnswer));
$this->sendResponse($caller->getSession(), 'callResponse', 'accepted', '', array('sdpAnswer' => $callerSdpAnswer));
});
});
});
} catch (Exception $exc) {
$this->logger->error($exc->getMessage());
if($pipeline != null){
$pipeline->release();
}
unset($this->pipelines[$caller->getSession()->getId()]);
unset($this->pipelines[$callee->getSession()->getId()]);
$this->sendResponse($caller->getSession(), 'callResponse', "rejected");
$this->sendResponse($callee->getSession(), 'stopCommunication', "");
}
} else {
return $this->sendResponse($caller['session'], 'callResponse', "rejected");
}
}
pu
没有合适的资源?快使用搜索试试~ 我知道了~
kurento-client-php:当前PHP客户端
共106个文件
php:32个
png:26个
js:18个
需积分: 10 1 下载量 101 浏览量
2021-05-10
14:01:04
上传
评论
收藏 872KB ZIP 举报
温馨提示
Kurento客户端PHP Kurento Kurento客户端PHP库,实现了客户端 安装 安装此库的最简单方法是使用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媒体服务器安装,请检查 用法 这是你好世界的例子。 在官方阅读更多内容。
资源详情
资源评论
资源推荐
收起资源包目录
kurento-client-php:当前PHP客户端 (106个子文件)
kurento.css 2KB
kurento.css 2KB
kurento.css 2KB
kurento.css 1KB
kurento.css 1KB
urjc.gif 16KB
urjc.gif 16KB
urjc.gif 16KB
urjc.gif 16KB
urjc.gif 16KB
spinner.gif 8KB
spinner.gif 8KB
spinner.gif 8KB
spinner.gif 8KB
spinner.gif 8KB
.gitignore 114B
index.html 7KB
index.html 6KB
index.html 5KB
index.html 4KB
index.html 4KB
kurento-utils.js 18KB
kurento-utils.js 18KB
kurento-utils.js 18KB
kurento-utils.js 18KB
kurento-utils.js 18KB
index.js 7KB
index.js 6KB
index.js 4KB
dragDrop.js 4KB
dragDrop.js 4KB
index.js 3KB
console.js 2KB
console.js 2KB
console.js 2KB
console.js 2KB
console.js 2KB
index.js 2KB
app.js 1KB
composer.json 679B
package.json 234B
LICENSE 1KB
README.mdown 5KB
README.mdown 546B
README.mdown 510B
README.mdown 498B
README.mdown 494B
README.mdown 468B
index.php 19KB
index.php 13KB
index.php 7KB
Client.php 5KB
index.php 5KB
MediaObject.php 2KB
Client.php 2KB
index.php 2KB
KurentoClient.php 2KB
MediaElement.php 1KB
test-webrtc.php 887B
FaceOverlayFilter.php 782B
test-kurento-client.php 656B
MediaPipeline.php 656B
PlayerEndpoint.php 613B
WebRtcEndpoint.php 606B
SdpEndpoint.php 572B
MediaObject.php 522B
MediaElement.php 511B
RecorderEndpoint.php 454B
PlayerEndpoint.php 444B
FaceOverlayFilter.php 441B
MediaPipeline.php 410B
RecorderEndpoint.php 364B
RtpEndpoint.php 334B
WebRtcEndpoint.php 321B
SessionEndpoint.php 319B
RtpEndpoint.php 318B
Endpoint.php 316B
UriEndpoint.php 315B
Filter.php 314B
Exception.php 300B
pipeline1.png 95KB
pipeline.png 77KB
naevatec.png 51KB
naevatec.png 51KB
naevatec.png 51KB
naevatec.png 51KB
naevatec.png 51KB
pipeline.png 50KB
pipeline2.png 33KB
pipeline.png 31KB
pipeline.png 28KB
webrtc.png 12KB
webrtc.png 12KB
webrtc.png 12KB
webrtc.png 12KB
webrtc.png 12KB
kurento.png 6KB
kurento.png 6KB
kurento.png 6KB
kurento.png 6KB
共 106 条
- 1
- 2
不爱说话的我
- 粉丝: 17
- 资源: 4616
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0