@uniai-fe/uds-templates 0.6.25 → 0.6.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/package.json +1 -1
- package/src/cctv/apis/client.ts +56 -2
- package/src/cctv/apis/server.ts +1 -120
- package/src/cctv/components/Provider.tsx +66 -8
- package/src/cctv/components/cam-list/Item.tsx +6 -0
- package/src/cctv/components/pagination/list/Item.tsx +20 -0
- package/src/cctv/components/video/Template.tsx +3 -0
- package/src/cctv/components/viewer/desktop/Video.tsx +1 -0
- package/src/cctv/hooks/streamScheduler.ts +276 -0
- package/src/cctv/hooks/useRtcStream.ts +218 -18
- package/src/cctv/types/api.ts +0 -94
- package/src/cctv/types/context.ts +21 -0
- package/src/cctv/types/hook.ts +24 -0
- package/src/cctv/types/props.ts +12 -1
- package/src/cctv/types/video-state.ts +18 -3
- package/src/cctv/utils/video-state.ts +3 -0
package/README.md
CHANGED
package/package.json
CHANGED
package/src/cctv/apis/client.ts
CHANGED
|
@@ -7,16 +7,42 @@ import type {
|
|
|
7
7
|
API_Res_CctvRtcToken,
|
|
8
8
|
} from "../types";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* CCTV; RTC token fallback max age
|
|
12
|
+
* @desc
|
|
13
|
+
* JWT exp를 읽을 수 없는 token은 React Query dataUpdatedAt 기준으로 이 시간까지만 신규 WHEP 연결에 재사용한다.
|
|
14
|
+
*/
|
|
10
15
|
export const CCTV_RTC_TOKEN_FALLBACK_MAX_AGE_MS = 5 * 60 * 1000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* CCTV; RTC token query cache retention
|
|
19
|
+
* @desc
|
|
20
|
+
* focus/reconnect 자동 refetch는 막되, 오래된 token이 무기한 신규 연결에 쓰이지 않게 fallback max age와 동일하게 제한한다.
|
|
21
|
+
*/
|
|
11
22
|
export const CCTV_RTC_TOKEN_GC_TIME_MS = CCTV_RTC_TOKEN_FALLBACK_MAX_AGE_MS;
|
|
12
23
|
|
|
24
|
+
/**
|
|
25
|
+
* CCTV; client company-list fetcher
|
|
26
|
+
* @param {object} params 요청 파라미터
|
|
27
|
+
* @param {string} [params.url] service에서 주입한 company-list API 경로
|
|
28
|
+
* @returns {Promise<API_Res_CctvCompany>} CCTV company-list 응답
|
|
29
|
+
*/
|
|
13
30
|
export const getClientCctvCompanyList = async ({
|
|
14
31
|
url,
|
|
15
32
|
}: {
|
|
16
33
|
url?: string;
|
|
17
34
|
}): Promise<API_Res_CctvCompany> =>
|
|
35
|
+
// Provider에서 listUrl을 주입하지 않으면 UDS 기본 Next route를 사용한다.
|
|
18
36
|
await (await fetch(url ?? "/api/cctv/company-list")).json();
|
|
19
37
|
|
|
38
|
+
/**
|
|
39
|
+
* CCTV; company-list query hook
|
|
40
|
+
* @hook
|
|
41
|
+
* @param {object} params query 파라미터
|
|
42
|
+
* @param {string} [params.url] service에서 주입한 company-list API 경로
|
|
43
|
+
* @param {readonly unknown[]} [params.queryKeyDeps] service별 목록 cache 분리용 key dependency
|
|
44
|
+
* @returns {UseQueryResult<API_Res_CctvCompany>} company-list query 결과
|
|
45
|
+
*/
|
|
20
46
|
export const useQueryCctvCompanyList = ({
|
|
21
47
|
url,
|
|
22
48
|
queryKeyDeps = [],
|
|
@@ -25,17 +51,28 @@ export const useQueryCctvCompanyList = ({
|
|
|
25
51
|
queryKeyDeps?: readonly unknown[];
|
|
26
52
|
}): UseQueryResult<API_Res_CctvCompany> =>
|
|
27
53
|
useQuery({
|
|
54
|
+
// username/site 등 service-local 조건이 바뀌면 queryKeyDeps로 cache를 분리한다.
|
|
28
55
|
queryKey: ["cctv_company_list", url, ...queryKeyDeps],
|
|
29
56
|
queryFn: () => getClientCctvCompanyList({ url }),
|
|
30
57
|
});
|
|
31
58
|
|
|
59
|
+
/**
|
|
60
|
+
* CCTV; RTC token POST fetcher
|
|
61
|
+
* @param {API_Req_CctvRtcToken & { url?: string }} params token 요청 파라미터
|
|
62
|
+
* @param {string} params.company_id 업체 id코드
|
|
63
|
+
* @param {string} params.cam_id 카메라 id코드
|
|
64
|
+
* @param {string} params.username CCTV token 권한 확인용 계정명
|
|
65
|
+
* @param {string} [params.url] service에서 주입한 token API 경로
|
|
66
|
+
* @returns {Promise<API_Res_CctvRtcToken>} RTC token 응답
|
|
67
|
+
*/
|
|
32
68
|
export const postCctvRtcToken = async ({
|
|
33
69
|
company_id,
|
|
34
70
|
cam_id,
|
|
35
71
|
username,
|
|
36
72
|
url,
|
|
37
73
|
}: API_Req_CctvRtcToken & { url?: string }): Promise<API_Res_CctvRtcToken> =>
|
|
38
|
-
await
|
|
74
|
+
await // token route는 service-local proxy가 있으면 그 경로를 우선 사용한다.
|
|
75
|
+
(
|
|
39
76
|
await fetch(url ?? "/api/cctv/token", {
|
|
40
77
|
method: "POST",
|
|
41
78
|
headers: {
|
|
@@ -45,20 +82,37 @@ export const postCctvRtcToken = async ({
|
|
|
45
82
|
})
|
|
46
83
|
).json();
|
|
47
84
|
|
|
85
|
+
/**
|
|
86
|
+
* CCTV; RTC token query hook
|
|
87
|
+
* @hook
|
|
88
|
+
* @param {API_Req_CctvRtcToken & { enabled?: boolean; url?: string }} params token query 파라미터
|
|
89
|
+
* @param {string} params.company_id 업체 id코드
|
|
90
|
+
* @param {string} params.cam_id 카메라 id코드
|
|
91
|
+
* @param {boolean} [params.enabled] scheduler grant 이후 token query를 열기 위한 외부 gate
|
|
92
|
+
* @param {string} params.username CCTV token 권한 확인용 계정명
|
|
93
|
+
* @param {string} [params.url] service에서 주입한 token API 경로
|
|
94
|
+
* @returns {UseQueryResult<API_Res_CctvRtcToken>} RTC token query 결과
|
|
95
|
+
*/
|
|
48
96
|
export const useQueryCctvRtcToken = ({
|
|
49
97
|
company_id,
|
|
50
98
|
cam_id,
|
|
99
|
+
enabled = true,
|
|
51
100
|
username,
|
|
52
101
|
url,
|
|
53
102
|
}: API_Req_CctvRtcToken & {
|
|
103
|
+
enabled?: boolean;
|
|
54
104
|
url?: string;
|
|
55
105
|
}): UseQueryResult<API_Res_CctvRtcToken> =>
|
|
56
106
|
useQuery({
|
|
107
|
+
// token은 username/company/cam/API route 조합별로 분리한다.
|
|
57
108
|
queryKey: ["cctv_rtc_token", username, company_id, cam_id, url],
|
|
58
109
|
queryFn: () => postCctvRtcToken({ company_id, cam_id, username, url }),
|
|
59
|
-
|
|
110
|
+
// scheduler grant 전에는 token burst가 생기지 않도록 enabled를 false로 유지한다.
|
|
111
|
+
enabled: enabled && Boolean(username && company_id && cam_id),
|
|
112
|
+
// exp decode가 불가한 token은 fallback age를 넘기면 신규 WHEP 연결에 쓰지 않는다.
|
|
60
113
|
staleTime: CCTV_RTC_TOKEN_FALLBACK_MAX_AGE_MS,
|
|
61
114
|
gcTime: CCTV_RTC_TOKEN_GC_TIME_MS,
|
|
115
|
+
// focus/reconnect/mount가 곧바로 다수 WHEP 재협상으로 이어지지 않도록 자동 refetch를 막는다.
|
|
62
116
|
refetchOnMount: false,
|
|
63
117
|
refetchOnReconnect: false,
|
|
64
118
|
refetchOnWindowFocus: false,
|
package/src/cctv/apis/server.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fetchWithBody,
|
|
3
|
-
generateQueryUrl,
|
|
4
|
-
nextAPILog,
|
|
5
|
-
} from "@uniai-fe/util-api";
|
|
1
|
+
import { generateQueryUrl, nextAPILog } from "@uniai-fe/util-api";
|
|
6
2
|
import type {
|
|
7
3
|
API_Req_GetCompanyListParams,
|
|
8
|
-
API_Req_GetCctvTokenParams,
|
|
9
|
-
API_Req_CctvRtcTokenOrigin,
|
|
10
4
|
API_Res_CctvCompanyGroup,
|
|
11
|
-
API_Res_CctvRtcToken,
|
|
12
5
|
API_Res_CctvCompany,
|
|
13
6
|
} from "../types";
|
|
14
7
|
|
|
@@ -50,8 +43,6 @@ export const GROUP_PRESET: API_Res_CctvCompanyGroup[] = [
|
|
|
50
43
|
},
|
|
51
44
|
];
|
|
52
45
|
|
|
53
|
-
const CCTV_RTC_TOKEN_DEFAULT_TTL_SECONDS = 5 * 60;
|
|
54
|
-
|
|
55
46
|
export function getMatchedGroupList(
|
|
56
47
|
data: API_Res_CctvCompanyGroup[] = [],
|
|
57
48
|
{ code, method }: { code: string; method: string },
|
|
@@ -191,113 +182,3 @@ export async function getServerCompanyList({
|
|
|
191
182
|
};
|
|
192
183
|
}
|
|
193
184
|
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* CCTV; token API route.ts 로직
|
|
197
|
-
* @api
|
|
198
|
-
* @route /token
|
|
199
|
-
* @param {API_Req_GetCctvTokenParams} params
|
|
200
|
-
* @property {string} domain API 요청 도메인(서버)
|
|
201
|
-
* @property {string} routeUrl Next.js app/api 이하 경로 url
|
|
202
|
-
* @property {string} [queryUrl] 백엔드 요청 url
|
|
203
|
-
* @property {NextRequest} req Next.js API body 데이터
|
|
204
|
-
*/
|
|
205
|
-
export async function getServerCctvToken({
|
|
206
|
-
domain,
|
|
207
|
-
routeUrl,
|
|
208
|
-
queryUrl,
|
|
209
|
-
req,
|
|
210
|
-
headers,
|
|
211
|
-
tokenPreset,
|
|
212
|
-
}: API_Req_GetCctvTokenParams): Promise<{
|
|
213
|
-
res: API_Res_CctvRtcToken;
|
|
214
|
-
domain: string;
|
|
215
|
-
queryUrl: string;
|
|
216
|
-
options?: ResponseInit;
|
|
217
|
-
}> {
|
|
218
|
-
const query_url = queryUrl || "/token";
|
|
219
|
-
const reqBody = await req.json();
|
|
220
|
-
|
|
221
|
-
const API_OPTION = {
|
|
222
|
-
domain,
|
|
223
|
-
queryUrl: query_url,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const alternateResponse: API_Res_CctvRtcToken = {
|
|
227
|
-
token: "",
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const password =
|
|
231
|
-
reqBody?.password || tokenPreset?.password || reqBody?.username || "";
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
!reqBody ||
|
|
235
|
-
!reqBody.username ||
|
|
236
|
-
!reqBody.company_id ||
|
|
237
|
-
!reqBody.cam_id ||
|
|
238
|
-
!password
|
|
239
|
-
) {
|
|
240
|
-
nextAPILog("POST", routeUrl, query_url, {
|
|
241
|
-
hasUsername: Boolean(reqBody?.username),
|
|
242
|
-
hasCompanyId: Boolean(reqBody?.company_id),
|
|
243
|
-
hasCamId: Boolean(reqBody?.cam_id),
|
|
244
|
-
hasPassword: Boolean(password),
|
|
245
|
-
});
|
|
246
|
-
return {
|
|
247
|
-
res: alternateResponse,
|
|
248
|
-
...API_OPTION,
|
|
249
|
-
options: {
|
|
250
|
-
status: 400,
|
|
251
|
-
statusText: "토큰 요청 파라미터가 올바르지 않습니다.",
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const site = !isNaN(Number(reqBody.company_id))
|
|
257
|
-
? `farm${reqBody.company_id}`
|
|
258
|
-
: String(reqBody.company_id);
|
|
259
|
-
const username = reqBody.username;
|
|
260
|
-
const path = !isNaN(Number(reqBody.cam_id))
|
|
261
|
-
? `cam${reqBody.cam_id}`
|
|
262
|
-
: String(reqBody.cam_id);
|
|
263
|
-
|
|
264
|
-
// 토큰 요청 payload 구성
|
|
265
|
-
const bodyData: API_Req_CctvRtcTokenOrigin = {
|
|
266
|
-
site,
|
|
267
|
-
username,
|
|
268
|
-
password,
|
|
269
|
-
action: "read",
|
|
270
|
-
path,
|
|
271
|
-
ttl_seconds: tokenPreset?.ttl_seconds ?? CCTV_RTC_TOKEN_DEFAULT_TTL_SECONDS,
|
|
272
|
-
kid: tokenPreset?.kid ?? "streaming-auth-1",
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
nextAPILog("POST", routeUrl, query_url, {
|
|
276
|
-
hasRequiredParams: true,
|
|
277
|
-
ttlSeconds: bodyData.ttl_seconds,
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
try {
|
|
281
|
-
const res = await fetchWithBody<string, API_Res_CctvRtcToken>({
|
|
282
|
-
method: "POST",
|
|
283
|
-
routeUrl,
|
|
284
|
-
...API_OPTION,
|
|
285
|
-
headers: {
|
|
286
|
-
accept: "application/json",
|
|
287
|
-
"Content-Type": "application/json",
|
|
288
|
-
...(headers || {}),
|
|
289
|
-
},
|
|
290
|
-
body: JSON.stringify(bodyData),
|
|
291
|
-
alternateResponse,
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
return { res, ...API_OPTION };
|
|
295
|
-
} catch (error) {
|
|
296
|
-
nextAPILog("POST", routeUrl, query_url, { error });
|
|
297
|
-
return {
|
|
298
|
-
res: alternateResponse,
|
|
299
|
-
...API_OPTION,
|
|
300
|
-
options: { status: 500 },
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
}
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
createCctvRtcStreamRegistry,
|
|
15
15
|
type CctvRtcStreamRegistry,
|
|
16
16
|
} from "../hooks/streamRegistry";
|
|
17
|
+
import {
|
|
18
|
+
createCctvRtcStreamScheduler,
|
|
19
|
+
type CctvRtcStreamScheduler,
|
|
20
|
+
} from "../hooks/streamScheduler";
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* CCTV; API 경로 컨텍스트
|
|
@@ -28,6 +32,9 @@ const ApiUrlContext = createContext<CctvApiUrlContext>({
|
|
|
28
32
|
const RtcStreamRegistryContext = createContext<CctvRtcStreamRegistry | null>(
|
|
29
33
|
null,
|
|
30
34
|
);
|
|
35
|
+
const RtcStreamSchedulerContext = createContext<CctvRtcStreamScheduler | null>(
|
|
36
|
+
null,
|
|
37
|
+
);
|
|
31
38
|
|
|
32
39
|
/**
|
|
33
40
|
* CCTV; API 경로 컨텍스트
|
|
@@ -40,6 +47,13 @@ export function useCctvApiUrl(): CctvApiUrlContext {
|
|
|
40
47
|
return useContext(ApiUrlContext);
|
|
41
48
|
}
|
|
42
49
|
|
|
50
|
+
/**
|
|
51
|
+
* CCTV; RTC stream registry context hook
|
|
52
|
+
* @hook
|
|
53
|
+
* @returns {CctvRtcStreamRegistry} Provider instance 단위 stream registry
|
|
54
|
+
* @desc
|
|
55
|
+
* registry는 WHEP PeerConnection/MediaStream을 Provider lifecycle 안에서 유지하고 list/viewer video reattach를 담당한다.
|
|
56
|
+
*/
|
|
43
57
|
export function useCctvRtcStreamRegistry(): CctvRtcStreamRegistry {
|
|
44
58
|
const registry = useContext(RtcStreamRegistryContext);
|
|
45
59
|
if (!registry) {
|
|
@@ -50,6 +64,23 @@ export function useCctvRtcStreamRegistry(): CctvRtcStreamRegistry {
|
|
|
50
64
|
return registry;
|
|
51
65
|
}
|
|
52
66
|
|
|
67
|
+
/**
|
|
68
|
+
* CCTV; RTC stream scheduler context hook
|
|
69
|
+
* @hook
|
|
70
|
+
* @returns {CctvRtcStreamScheduler} Provider instance 단위 stream scheduler
|
|
71
|
+
* @desc
|
|
72
|
+
* scheduler는 item UI 렌더와 token/WHEP 시작 시점을 분리해 초기 요청 burst를 batch 단위로 줄인다.
|
|
73
|
+
*/
|
|
74
|
+
export function useCctvRtcStreamScheduler(): CctvRtcStreamScheduler {
|
|
75
|
+
const scheduler = useContext(RtcStreamSchedulerContext);
|
|
76
|
+
if (!scheduler) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"CCTV.Provider 내부에서 useCctvRtcStreamScheduler를 사용해야 합니다.",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return scheduler;
|
|
82
|
+
}
|
|
83
|
+
|
|
53
84
|
/**
|
|
54
85
|
* CCTV; Provider props
|
|
55
86
|
* @component
|
|
@@ -60,6 +91,7 @@ export function useCctvRtcStreamRegistry(): CctvRtcStreamRegistry {
|
|
|
60
91
|
* @property {string} [username] CCTV 조회시 권한 확인을 위한 계정명
|
|
61
92
|
* @property {string} [whepUsername] WHEP endpoint username 덮어쓰기 값
|
|
62
93
|
* @property {ContextExtension} [defaultValues] 서비스 확장 context 기본값
|
|
94
|
+
* @property {CctvRtcStreamOptions} [streamOptions] stream lazy loading 옵션
|
|
63
95
|
* @property {React.ReactNode} children
|
|
64
96
|
*/
|
|
65
97
|
export default function CCTVProvider<ContextExtension extends object = object>({
|
|
@@ -70,15 +102,39 @@ export default function CCTVProvider<ContextExtension extends object = object>({
|
|
|
70
102
|
listUrl,
|
|
71
103
|
tokenUrl,
|
|
72
104
|
defaultValues,
|
|
105
|
+
streamOptions,
|
|
73
106
|
children,
|
|
74
107
|
}: CctvProviderProps<ContextExtension>) {
|
|
108
|
+
// streamOptions object identity가 매 렌더 바뀌어도 primitive option 값 기준으로만 scheduler를 교체한다.
|
|
109
|
+
const streamBatchSize = streamOptions?.batchSize;
|
|
110
|
+
const streamBatchIntervalMs = streamOptions?.batchIntervalMs;
|
|
111
|
+
const hasStreamOptions =
|
|
112
|
+
streamBatchSize !== undefined || streamBatchIntervalMs !== undefined;
|
|
113
|
+
|
|
114
|
+
// registry는 Provider lifetime 동안 유지해 list/viewer 전환 시 기존 MediaStream을 재사용한다.
|
|
75
115
|
const streamRegistry = useMemo(() => createCctvRtcStreamRegistry(), []);
|
|
76
116
|
|
|
117
|
+
// scheduler는 Provider option이 바뀌는 경우에만 새 batch 정책으로 다시 만든다.
|
|
118
|
+
const streamScheduler = useMemo(
|
|
119
|
+
() =>
|
|
120
|
+
createCctvRtcStreamScheduler(
|
|
121
|
+
hasStreamOptions
|
|
122
|
+
? {
|
|
123
|
+
batchIntervalMs: streamBatchIntervalMs,
|
|
124
|
+
batchSize: streamBatchSize,
|
|
125
|
+
}
|
|
126
|
+
: undefined,
|
|
127
|
+
),
|
|
128
|
+
[hasStreamOptions, streamBatchIntervalMs, streamBatchSize],
|
|
129
|
+
);
|
|
130
|
+
|
|
77
131
|
useEffect(() => {
|
|
78
132
|
return () => {
|
|
133
|
+
// Provider unmount가 CCTV stream lifecycle의 최종 정리 지점이다.
|
|
79
134
|
streamRegistry.closeAll();
|
|
135
|
+
streamScheduler.clear();
|
|
80
136
|
};
|
|
81
|
-
}, [streamRegistry]);
|
|
137
|
+
}, [streamRegistry, streamScheduler]);
|
|
82
138
|
|
|
83
139
|
const mergedDefaultValues = {
|
|
84
140
|
// 변경 설명: service 확장 context 기본값을 core CCTV form context와 한 RHF scope에서 병합한다.
|
|
@@ -93,13 +149,15 @@ export default function CCTVProvider<ContextExtension extends object = object>({
|
|
|
93
149
|
return (
|
|
94
150
|
<ApiUrlContext.Provider value={{ listUrl, tokenUrl }}>
|
|
95
151
|
<RtcStreamRegistryContext.Provider value={streamRegistry}>
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
152
|
+
<RtcStreamSchedulerContext.Provider value={streamScheduler}>
|
|
153
|
+
<Form.Provider<CctvContext<ContextExtension>>
|
|
154
|
+
options={{
|
|
155
|
+
defaultValues: mergedDefaultValues,
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
{children}
|
|
159
|
+
</Form.Provider>
|
|
160
|
+
</RtcStreamSchedulerContext.Provider>
|
|
103
161
|
</RtcStreamRegistryContext.Provider>
|
|
104
162
|
</ApiUrlContext.Provider>
|
|
105
163
|
);
|
|
@@ -25,8 +25,10 @@ export default function CCTVCamListItem({
|
|
|
25
25
|
renderOverlay,
|
|
26
26
|
...cam
|
|
27
27
|
}: CctvCamListItemProps) {
|
|
28
|
+
// item은 즉시 렌더하지만 token/WHEP 시작은 hook 내부 scheduler grant 이후로 지연된다.
|
|
28
29
|
const { videoRef, ...rtcCtx } = useCctvRtcStream({ cam });
|
|
29
30
|
|
|
31
|
+
// live/error/message는 video-state util 하나를 기준으로 계산해 CamList와 Viewer 표시 규칙을 맞춘다.
|
|
30
32
|
const isLive = useMemo(() => getIsLive({ cam, ...rtcCtx }), [cam, rtcCtx]);
|
|
31
33
|
const isError = useMemo(() => getIsError({ cam, ...rtcCtx }), [cam, rtcCtx]);
|
|
32
34
|
const overlayMessage = useMemo(
|
|
@@ -44,9 +46,11 @@ export default function CCTVCamListItem({
|
|
|
44
46
|
)}
|
|
45
47
|
>
|
|
46
48
|
<CCTVVideoTemplate
|
|
49
|
+
// hook이 반환한 ref에 registry MediaStream이 attach된다.
|
|
47
50
|
ref={videoRef}
|
|
48
51
|
cam={cam}
|
|
49
52
|
className="cctv-cam-list-video-container"
|
|
53
|
+
// list card에서는 live/share 상태를 header에 노출하고 제목은 footer로 내려 보낸다.
|
|
50
54
|
headerOptions={{
|
|
51
55
|
activeLiveState: true,
|
|
52
56
|
activeTitle: false,
|
|
@@ -58,9 +62,11 @@ export default function CCTVCamListItem({
|
|
|
58
62
|
// 변경 설명: list item custom overlay는 template seam 하나만 따라간다.
|
|
59
63
|
renderOverlay={renderOverlay}
|
|
60
64
|
{...{
|
|
65
|
+
// Video.Template이 overlay/body/footer를 한 번에 판단할 수 있도록 stream 상태를 함께 넘긴다.
|
|
61
66
|
isError,
|
|
62
67
|
overlayMessage,
|
|
63
68
|
isLive,
|
|
69
|
+
streamStage: rtcCtx.streamStage,
|
|
64
70
|
canReconnect: rtcCtx.canReconnect,
|
|
65
71
|
reconnectStream: rtcCtx.reconnectStream,
|
|
66
72
|
}}
|
|
@@ -11,14 +11,29 @@ import {
|
|
|
11
11
|
getIsError,
|
|
12
12
|
} from "../../../utils/video-state";
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* CCTV; pagination list item
|
|
16
|
+
* @component
|
|
17
|
+
* @param {object} props
|
|
18
|
+
* @param {string} [props.className] pagination thumbnail item 클래스
|
|
19
|
+
* @param {string} props.cam_id 카메라 id코드
|
|
20
|
+
* @param {string} props.cam_name 카메라명
|
|
21
|
+
* @param {string} props.company_id 업체 id코드
|
|
22
|
+
* @param {boolean} props.cam_online 카메라 온라인 여부
|
|
23
|
+
* @param {string} props.cam_rtc WebRTC endpoint base URL
|
|
24
|
+
* @desc
|
|
25
|
+
* viewer 하단 thumbnail에서도 동일한 `useCctvRtcStream` 경로를 사용해 list/viewer 전환 시 registry reattach 계약을 유지한다.
|
|
26
|
+
*/
|
|
14
27
|
export default function CCTVPaginationListItem({
|
|
15
28
|
className,
|
|
16
29
|
...cam
|
|
17
30
|
}: {
|
|
18
31
|
className?: string;
|
|
19
32
|
} & CctvCompanyCameraData) {
|
|
33
|
+
// thumbnail은 즉시 렌더하고, 실제 token/WHEP 시작은 Provider scheduler가 batch 단위로 grant한다.
|
|
20
34
|
const { videoRef, ...rtcCtx } = useCctvRtcStream({ cam });
|
|
21
35
|
|
|
36
|
+
// CamList item과 동일한 util을 사용해 overlay 상태 판정 drift를 막는다.
|
|
22
37
|
const isLive = useMemo(() => getIsLive({ cam, ...rtcCtx }), [cam, rtcCtx]);
|
|
23
38
|
const isError = useMemo(() => getIsError({ cam, ...rtcCtx }), [cam, rtcCtx]);
|
|
24
39
|
const overlayMessage = useMemo(
|
|
@@ -26,6 +41,7 @@ export default function CCTVPaginationListItem({
|
|
|
26
41
|
[cam, rtcCtx],
|
|
27
42
|
);
|
|
28
43
|
|
|
44
|
+
// cam.onSelect는 render data에 주입된 선택 handler라 있을 때만 호출한다.
|
|
29
45
|
const handleSelect = useCallback(() => {
|
|
30
46
|
if (typeof cam.onSelect === "function") cam.onSelect();
|
|
31
47
|
}, [cam]);
|
|
@@ -47,9 +63,11 @@ export default function CCTVPaginationListItem({
|
|
|
47
63
|
aria-label={`${cam.cam_name} 선택`}
|
|
48
64
|
>
|
|
49
65
|
<CCTVVideoTemplate
|
|
66
|
+
// registry가 같은 streamKey의 MediaStream을 thumbnail video에 attach한다.
|
|
50
67
|
ref={videoRef}
|
|
51
68
|
cam={cam}
|
|
52
69
|
className="cctv-pagination-list-video-container"
|
|
70
|
+
// thumbnail에서는 header live/share 상태만 보이고 footer action은 최소화한다.
|
|
53
71
|
headerOptions={{
|
|
54
72
|
activeLiveState: true,
|
|
55
73
|
activeTitle: false,
|
|
@@ -59,9 +77,11 @@ export default function CCTVPaginationListItem({
|
|
|
59
77
|
}}
|
|
60
78
|
footerOptions={{ cam }}
|
|
61
79
|
{...{
|
|
80
|
+
// Video.Template overlay가 queued/token-loading/connecting/error 상태를 통합 표시한다.
|
|
62
81
|
isError,
|
|
63
82
|
overlayMessage,
|
|
64
83
|
isLive,
|
|
84
|
+
streamStage: rtcCtx.streamStage,
|
|
65
85
|
canReconnect: rtcCtx.canReconnect,
|
|
66
86
|
reconnectStream: rtcCtx.reconnectStream,
|
|
67
87
|
}}
|
|
@@ -17,6 +17,7 @@ import type { CctvVideoTemplateProps } from "../../types/props";
|
|
|
17
17
|
* @property {boolean} [isError]
|
|
18
18
|
* @property {React.ReactNode} [overlayMessage]
|
|
19
19
|
* @property {boolean} [isLive]
|
|
20
|
+
* @property {CctvRtcStreamStage} [streamStage]
|
|
20
21
|
* @property {CctvCompanyCameraData} [cam]
|
|
21
22
|
* @property {boolean} [canReconnect]
|
|
22
23
|
* @property {CctvRtcReconnectTrigger} [reconnectStream]
|
|
@@ -33,6 +34,7 @@ const CCTVVideoTemplate = forwardRef<HTMLVideoElement, CctvVideoTemplateProps>(
|
|
|
33
34
|
isError,
|
|
34
35
|
isLive,
|
|
35
36
|
overlayMessage,
|
|
37
|
+
streamStage,
|
|
36
38
|
canReconnect,
|
|
37
39
|
reconnectStream,
|
|
38
40
|
renderOverlay,
|
|
@@ -60,6 +62,7 @@ const CCTVVideoTemplate = forwardRef<HTMLVideoElement, CctvVideoTemplateProps>(
|
|
|
60
62
|
isError,
|
|
61
63
|
isLive,
|
|
62
64
|
overlayMessage,
|
|
65
|
+
streamStage,
|
|
63
66
|
canReconnect,
|
|
64
67
|
reconnectStream,
|
|
65
68
|
})
|