feat: 收口视频访问与摄像头密钥输出

This commit is contained in:
weijuesen
2026-08-14 00:07:52 +08:00
parent 440cf803e4
commit 1a29def480
14 changed files with 494 additions and 78 deletions
+13 -10
View File
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { View, Text, Video } from '@tarojs/components';
import { useRouter } from '@tarojs/taro';
import styles from './index.module.scss';
import { getCameras } from '@/api/video';
import { getCameras, playCamera } from '@/api/video';
import { resolveUrl } from '@/api/config';
import type { Camera } from '@/types';
@@ -30,10 +30,6 @@ const VideoPlayerPage: React.FC = () => {
const found = cameras.find((c) => c.id === cameraId);
if (found) {
setCamera(found);
const url = found.hlsUrl || found.streamUrl || found.flvUrl;
if (url) {
setVideoUrl(resolveUrl(url));
}
}
} catch (err) {
console.error('[VideoPlayer] 获取摄像头信息失败:', err);
@@ -44,14 +40,21 @@ const VideoPlayerPage: React.FC = () => {
}, [cameraId, directUrl]);
const handlePlay = async () => {
if (!cameraId && !camera) return;
const id = cameraId || camera?.id;
if (!id) return;
setLoading(true);
setError('');
const streamUrl = resolveUrl(`/api/v1/video/cameras/${cameraId || camera!.id}/live/stream`);
console.log('[VideoPlayer] 获取播放地址成功:', streamUrl);
setVideoUrl(streamUrl);
setLoading(false);
try {
const info = await playCamera(id, { format: 'flv' });
const streamUrl = resolveUrl(info.url);
console.log('[VideoPlayer] 获取播放地址成功:', streamUrl);
setVideoUrl(streamUrl);
} catch (err) {
setError(err instanceof Error ? err.message : '获取播放地址失败');
} finally {
setLoading(false);
}
};
const formats: { key: 'hls' | 'flv' | 'webrtc'; label: string }[] = [