...
|
...
|
@@ -4,12 +4,16 @@ namespace console\controllers; |
|
|
use Yii;
|
|
|
use yii\console\Controller;
|
|
|
use common\models\Room;
|
|
|
use common\config\Params;
|
|
|
use common\lib\QcloudApi\Client as QcloudApiClient;
|
|
|
use common\models\Video;
|
|
|
|
|
|
/**
|
|
|
* Site controller
|
|
|
*/
|
|
|
class RoomController extends Controller
|
|
|
{
|
|
|
const QCLOUD_LVING_STAT = 1;
|
|
|
|
|
|
/**
|
|
|
* 重置房间状态
|
...
|
...
|
@@ -57,4 +61,62 @@ class RoomController extends Controller |
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 检查直播中的房间,如果腾讯云返回不是直播中的置为直播结束,30min检查一次
|
|
|
* https://www.qcloud.com/doc/api/258/4717
|
|
|
* 0 无输入流 ,1 直播中, 2 异常, 3 关闭
|
|
|
* @author yaoxiaofeng
|
|
|
* @use php yii room/check
|
|
|
*/
|
|
|
public function actionCheck()
|
|
|
{
|
|
|
//获取本地服务器直播中的房间
|
|
|
$result = Room::find()
|
|
|
->where(['living' => Params::LIVING])
|
|
|
->orderBy(['starting_time' => SORT_ASC])
|
|
|
->all();
|
|
|
|
|
|
if ($result) {
|
|
|
foreach ($result as $room) {
|
|
|
if ($room->roomQchannel) {
|
|
|
$channel_id = (string)$room->roomQchannel->channel_id;
|
|
|
$ret = QcloudApiClient::self()->DescribeLVBChannel($channel_id);
|
|
|
if (!$ret) {
|
|
|
$this->_log(QcloudApiClient::self()->error());
|
|
|
return;
|
|
|
}
|
|
|
//腾讯云返回不是直播中的置为直播结束
|
|
|
if ($ret['channelInfo'][0]['channel_status'] != self::QCLOUD_LVING_STAT) {
|
|
|
/*$room->setAttributes([
|
|
|
'living' => Params::LIVE_END,
|
|
|
'unstart_sort' => 0,
|
|
|
'living_sort' => 0
|
|
|
]);
|
|
|
if ($room->save(false)) {
|
|
|
$this->_log("room[{$room->room_id}] closed success");
|
|
|
} else {
|
|
|
$this->_log("room[{$room->room_id}] closed faild");
|
|
|
}*/
|
|
|
//是否要调用统一的结束接口,如果掉用的话存在资讯抛异常问题,那么房间就一直结束不了
|
|
|
try {
|
|
|
$video_res = (new Video())->setVideoStop($room->room_id);
|
|
|
if($video_res){
|
|
|
$this->_log("room[{$room->room_id}] closed success");
|
|
|
}else{
|
|
|
$this->_log("room[{$room->room_id}] closed faild");
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
$this->_log("room[{$room->room_id}] exception:".$e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function _log($string){
|
|
|
$string = sprintf("[%s]%s \n",date('Y-m-d H:i:s'),$string);
|
|
|
$this->stdout($string);
|
|
|
}
|
|
|
} |
...
|
...
|
|