From cd90308c97e3dcbcdfc63e7d2f1c197dffdd18ba Mon Sep 17 00:00:00 2001 From: Jing Li Date: Tue, 19 Dec 2023 15:03:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9B=91=E6=8E=A7=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=9B=B4=E6=92=AD=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/DeviceController.php | 59 +++++++++++++++++++++++ routes/api.php | 1 + 2 files changed, 60 insertions(+) diff --git a/app/Http/Controllers/DeviceController.php b/app/Http/Controllers/DeviceController.php index c8ed904..3828212 100644 --- a/app/Http/Controllers/DeviceController.php +++ b/app/Http/Controllers/DeviceController.php @@ -725,4 +725,63 @@ class DeviceController extends Controller return WormPhotoResource::collection($wormPhotos); } + + /** + * 监控设备直播地址 + */ + public function live(int $id, BiAngDeviceService $biangDeviceService) + { + $device = Device::where('type', DeviceType::Monitor)->findOrFail($id); + + switch ($device->supplier_key) { + case 'device-supplier-biang': + $client = $biangDeviceService->buildHttpClient($device); + + // 直播地址 + $address = $client->getMonitorPalyAddress($device->sn); + + return [ + 'type' => 'm3u8', + 'address' => (string) $address, + ]; + } + + // 直播地址 + $address = ''; + + if ($rtspUrl = data_get($device->extends, 'rtsp_url')) { + $value = Setting::where('slug', 'ffmpeg_websocket_ip')->value('value'); + + $wsConfig = $value ? json_decode($value, true) : []; + if (! is_array($wsConfig)) { + $wsConfig = []; + } + $wsConfig = array_merge([ + 'host' => '', + 'ip' => '127.0.0.1', + 'port'=> '80', + 'ssl' => false, + ], $wsConfig); + + if ($wsConfig['ssl'] && $wsConfig['host']) { + $address = sprintf( + 'wss://%s/rtsp?url=%s', + $wsConfig['host'], + base64_encode($rtspUrl), + ); + } else { + $address = sprintf( + 'wss://%s:%s/rtsp?url=%s', + $wsConfig['ip'], + $wsConfig['port'], + base64_encode($rtspUrl), + ); + } + } + + return [ + 'type' => 'flv', + 'address' => $address, + ]; + } } diff --git a/routes/api.php b/routes/api.php index 24839b0..5f2447a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -62,6 +62,7 @@ Route::group([ Route::apiResource('devices', DeviceController::class)->names('device'); Route::get('devices/{device}/worm-statics', [DeviceController::class, 'wormStatics']); Route::get('devices/{device}/worm-photos', [DeviceController::class, 'wormPhotos']); + Route::get('devices/{device}/live', [DeviceController::class, 'live']); Route::put('devices-update-recommend/{device}', [DeviceController::class, 'updateRecommendStatus']); Route::get('devices-num', [DeviceController::class, 'typeStatusNum'])->name('device.type_status_num'); Route::get('monitoring-data', [DeviceController::class, 'timeZoneList']);