123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- /**
- * Created by KLXQ
- * user: youyi
- * Date:2024/6/12 11:36.
- */
- namespace App\Services;
- use App\Http\Helpers\Tencent\MediaTencent;
- use App\Http\Helpers\Tencent\SignTencent;
- use App\Http\Helpers\Tencent\TrtcTencent;
- use App\Models\LectureRecord;
- use App\Models\LiveRecord;
- use App\Models\MeetingCentre;
- use App\Models\Room as RoomModel;
- use App\Models\RoomWebRecord;
- class LiveWebRecordService
- {
- public array $storageParams = [
- 'CloudVod' => [
- 'TencentVod' => [
- 'StorageRegion' => 'ap-chongqing',
- 'Procedure' => 'STD-H264-MP4-1080P',
- 'ClassId' => 1174322,
- 'SubAppId' => 1327013090,
- 'UserDefineRecordId' => '',
- ],
- ],
- ];
- public function startWebRecord($request)
- {
- $roomId = $request['room_id'];
- $roomName = $request['room_name'];
- $otherParams = $request['other_params'];
- $userId = $request['account_id'];
- // 录制机器人的UserId,用于进房发起录制任务
- $recordUserId = 'recorder_'.$roomId.'_'.$userId;
- $this->storageParams['CloudVod']['TencentVod']['UserDefineRecordId'] = $recordUserId;
- $sign = new SignTencent();
- $userSign = $sign->genUserSign($recordUserId);
- $recordInsertData = [
- 'lecture_id' => $roomId,
- 'room_name' => $roomName,
- 'user_id' => $userId,
- 'record_user_id' => $recordUserId,
- 'user_sign' => $userSign,
- ];
- $maxDurationLimit = config('tencent.web.max_duration_limit.region');
- $tParams = [
- 'RecordUrl' => $this->webRecordUrl($recordInsertData, $otherParams),
- 'MaxDurationLimit' => $maxDurationLimit,
- 'StorageParams' => $this->storageParams,
- ];
- // print_r($tParams);exit;
- $tRoom = new TrtcTencent('StartWebRecord', $tParams);
- $retData = $tRoom->resultArr;
- $taskId = $retData['data']['TaskId'] ?? '';
- if (!$taskId) {
- return false;
- }
- $recordInsertData['task_id'] = $taskId;
- $roomRecord = new LectureRecord();
- $roomRecord->fill($recordInsertData)->save();
- return $taskId;
- }
- public function describeWebRecord($taskId)
- {
- $params['TaskId'] = $taskId;
- $tRoom = new TrtcTencent('DescribeWebRecord', $params);
- $retData = $tRoom->resultArr;
- return $retData['data'];
- }
- public function stopWebRecord($taskId)
- {
- $params['TaskId'] = $taskId;
- $tRoom = new TrtcTencent('StopWebRecord', $params);
- $retData = $tRoom->resultArr;
- return $retData['data'];
- }
- public function deleteMedia($fileId)
- {
- if (!$fileId) {
- return false;
- }
- $params['FileId'] = $fileId;
- $tMedia = new MediaTencent('DeleteMedia', $params);
- $retData = $tMedia->resultArr;
- return $retData['data'];
- }
- // 构建Web录制页面的URL
- public function webRecordUrl($data, $otherParams): string
- {
- $url = getenv('WEB_URL').'Room?';
- $params = [
- 'user_id' => $data['record_user_id'],
- 'username' => $data['record_user_id'],
- 'room_id' => (string) $data['lecture_id'],
- 'room_name' => $data['room_name'],
- 'user_sign' => $data['user_sign'],
- 'sdk_app_id' => (int)config('tencent.trtc.app_id'),
- 'room_exist' => true,
- 'is_record' => true,
- ];
- $extraInfo = [
-
- ];
- // 其他参数,主要控制页面录制时,页面需要渲染成什么样子
- if (\is_array($otherParams)) {
- foreach ($otherParams as $k => $v) {
- $params[$k] = $v;
- }
- }
- // print_r($params);exit;
- $url .= 'roomInfo='.urlencode(json_encode($params, JSON_UNESCAPED_UNICODE));
- $url .= '&extraInfo='.urlencode(json_encode($extraInfo, JSON_UNESCAPED_UNICODE));
- $url.='&is_record=true&room_id='.$data['lecture_id'];
- return $url;
- }
- }
|