67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?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();
|
|
}
|
|
}
|
|
} |