初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\library\live;
|
||||
use AlibabaCloud\SDK\Live\V20161101\Models\DescribeLiveStreamStateRequest;
|
||||
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
|
||||
use AlibabaCloud\SDK\Live\V20161101\Models\DescribeLiveDomainOnlineUserNumRequest;
|
||||
/**
|
||||
* 直播间操作
|
||||
*/
|
||||
class Room
|
||||
{
|
||||
/**
|
||||
* 检查直播推流状态
|
||||
* @param $appName
|
||||
* @param $streamName
|
||||
* @return false|string online:推流中,表示正常推流中。 offline:不在线(推流失败或者推流结束,具体状态根据推流回调返回,此API不细分)。 forbidden:已禁推。
|
||||
*/
|
||||
public static function checkLiveStatus($appName,$streamName){
|
||||
|
||||
$liveConfig = \app\common\model\config\System::getConfig('ali_live');
|
||||
|
||||
$client = \app\common\library\live\AliLiveClient::createClient();
|
||||
|
||||
|
||||
|
||||
$describeLiveStreamStateRequest = new DescribeLiveStreamStateRequest([
|
||||
"domainName" => $liveConfig['push_domain'],
|
||||
"appName" => $appName,
|
||||
"streamName" => $streamName
|
||||
]);
|
||||
$runtime = new RuntimeOptions([]);
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
$data = $client->describeLiveStreamStateWithOptions($describeLiveStreamStateRequest, $runtime);
|
||||
|
||||
if(!in_array($data->body->streamState,['online','offline','forbidden'])){
|
||||
return 'onlinefaild';
|
||||
}
|
||||
return $data->body->streamState;
|
||||
}catch (Exception $error) {
|
||||
return $error->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询域名下所有流的在线人数信息
|
||||
* @return string
|
||||
*/
|
||||
public static function getLiveDomainOnlineUserNum(){
|
||||
$liveConfig = \app\common\model\config\System::getConfig('ali_live');
|
||||
$client = \app\common\library\live\AliLiveClient::createClient();
|
||||
|
||||
$describeLiveDomainOnlineUserNumRequest = new DescribeLiveDomainOnlineUserNumRequest([
|
||||
"domainName" => $liveConfig['play_domain']
|
||||
]);
|
||||
$runtime = new RuntimeOptions([]);
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
$data = $client->describeLiveDomainOnlineUserNumWithOptions($describeLiveDomainOnlineUserNumRequest, $runtime);
|
||||
return $data->body->onlineUserInfo;
|
||||
}
|
||||
catch (Exception $error) {
|
||||
return $error->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user