参考:Directives · arut/nginx-rtmp-module Wiki · GitHub
文档中描述了可以添加事件
on_connect
on_play
on_publish
on_done
on_play_done
on_publish_done
on_record_done
on_update
notify_update_timeout
notify_update_strict
notify_relay_redirect
notify_method
在/etc/nginx/nginx.conf配置文件中添加事件接收处理
rtmp {
server {
....
notify_method post;
publish_notify on;
on_publish http://127.0.0.1:8326/api/vedio;
......
}
}
thinkphp6使用swoole作为服务,因此可以直接连接,要注意的是不要使用http://localhost:8326/… 这样的路径进行访问,这样会导致OBS客户端连接失败
thinkphp添加路径
// 视频控制路由
Route::any('vedio', 'VedioNotice/serve');
建立控制器
namespace app\controller;
class VedioNotice extends BaseController
{
/**
* @return Response
* @throws InvalidArgumentException
* @throws BadRequestException
* @author xaboy
* @day 2020-04-26
*/
public function serve()
{
$param = $this->request->post();
Log::debug('post param:' . var_export($param, true));
// throw new \Exception('禁止连接!!');
return app('json')->success([
'code' => '200'
]);
}
}
使用OBS连接,带下如下参数
检查PHP日志,查看接收到的数据
param:array (
'param1' => '1111',
'param2' => '2222',
'call' => 'publish',
'name' => '12345677',
'type' => 'live',
'app' => 'song',
'flashver' => 'FMLE/3.0 (compatible; FMSc/1.0)',
'swfurl' => 'rtmp://173.154.216.128:1935/song',
'tcurl' => 'rtmp://173.154.216.128:1935/song',
'addr' => '173.154.216.1',
'clientid' => '9',
)
从返回数据中可以分析:param1和param2可以传到PHP控制器中,需要如何限制权限,如何查数据库自己处理吧
如果用户名和密码不正确,抛个异常就可以限制推送了 throw new \Exception