@7365admin1/layer-common 4.158.0 → 4.159.0
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/CHANGELOG.md +10 -4
- package/components/CctvEngine/Alerts.vue +134 -0
- package/components/CctvEngine/CameraPicker.vue +107 -0
- package/components/CctvEngine/Engines.vue +289 -0
- package/components/CctvEngine/Events.vue +175 -0
- package/components/CctvEngine/Faces.vue +174 -0
- package/components/CctvEngine/Live.vue +88 -0
- package/components/CctvEngine/LiveTile.vue +173 -0
- package/components/CctvEngine/Notice.vue +54 -0
- package/components/CctvEngine/Plates.vue +158 -0
- package/components/CctvEngine/Playback.vue +239 -0
- package/components/CctvEngine/Shell.vue +86 -0
- package/components/CctvEngine/WrongWayRules.vue +177 -0
- package/components/CctvEngine/Zones.vue +189 -0
- package/components/CctvEngineSiteSwitch.vue +82 -0
- package/components/SiteSettings.vue +4 -0
- package/composables/useCctvEngine.ts +119 -0
- package/composables/useCctvEngineAccess.ts +49 -0
- package/composables/useCommonPermission.ts +17 -0
- package/composables/usePropertyPermission.ts +2 -0
- package/composables/useSecurityPermission.ts +2 -0
- package/composables/useSiteFeatureSettings.ts +1 -0
- package/constants/permissions.ts +11 -0
- package/package.json +1 -1
- package/utils/cctv-engine.ts +330 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
<!-- Events: what the engine saw. Filter, page through, open one for the picture, clip, zones and score. -->
|
|
2
|
+
<template>
|
|
3
|
+
<div>
|
|
4
|
+
<v-row dense>
|
|
5
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.camera" label="Camera" density="comfortable" hide-details clearable /></v-col>
|
|
6
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.label" label="Object (car, person...)" density="comfortable" hide-details clearable /></v-col>
|
|
7
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.zone" label="Zone" density="comfortable" hide-details clearable /></v-col>
|
|
8
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.face" label="Face name" density="comfortable" hide-details clearable /></v-col>
|
|
9
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.plate" label="Number plate" density="comfortable" hide-details clearable /></v-col>
|
|
10
|
+
<v-col cols="6" sm="4" md="3"><v-select v-model="f.kind" :items="EVENT_KINDS" label="Kind" density="comfortable" hide-details clearable /></v-col>
|
|
11
|
+
<v-col cols="6" sm="4" md="3"><v-select v-model="f.severity" :items="EVENT_SEVERITIES" label="Severity" density="comfortable" hide-details clearable /></v-col>
|
|
12
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.from" type="datetime-local" label="From" density="comfortable" hide-details /></v-col>
|
|
13
|
+
<v-col cols="6" sm="4" md="3"><v-text-field v-model="f.to" type="datetime-local" label="To" density="comfortable" hide-details /></v-col>
|
|
14
|
+
<v-col cols="12" sm="4" md="3" class="d-flex align-center ga-2">
|
|
15
|
+
<v-btn color="primary" @click="search">Search</v-btn>
|
|
16
|
+
<v-btn variant="text" @click="clear">Clear</v-btn>
|
|
17
|
+
</v-col>
|
|
18
|
+
</v-row>
|
|
19
|
+
|
|
20
|
+
<v-progress-linear v-if="loading" indeterminate class="mt-3" />
|
|
21
|
+
<CctvEngineNotice v-else-if="error" class="mt-3" :error="error" retry @retry="load" />
|
|
22
|
+
<CctvEngineNotice
|
|
23
|
+
v-else-if="!items.length"
|
|
24
|
+
class="mt-3"
|
|
25
|
+
:title="filtered ? 'No events match these filters' : 'No events yet'"
|
|
26
|
+
:body="filtered
|
|
27
|
+
? 'Widen the dates or clear a filter and search again.'
|
|
28
|
+
: 'Events appear here when a camera sees something the engine is watching for. If you expect some, check the engine is Online in Engines & health.'"
|
|
29
|
+
/>
|
|
30
|
+
<v-list v-else lines="two" class="mt-3">
|
|
31
|
+
<v-list-item v-for="e in items" :key="e._id" :title="titleOf(e)" :subtitle="subtitleOf(e)" @click="open(e)">
|
|
32
|
+
<template #append>
|
|
33
|
+
<v-chip v-if="e.severity === 'alert'" size="small" color="error" label class="mr-1">Alert</v-chip>
|
|
34
|
+
<v-chip size="small" label>{{ kindTitle(e.kind) }}</v-chip>
|
|
35
|
+
</template>
|
|
36
|
+
</v-list-item>
|
|
37
|
+
</v-list>
|
|
38
|
+
|
|
39
|
+
<v-pagination v-if="pages > 1" v-model="page" :length="pages" :total-visible="smAndDown ? 3 : 7" class="mt-2" @update:model-value="load" />
|
|
40
|
+
<div v-if="pageRange" class="hero-muted text-center">{{ pageRange }}</div>
|
|
41
|
+
|
|
42
|
+
<v-dialog v-model="detailOpen" max-width="900" scrollable>
|
|
43
|
+
<v-card v-if="current">
|
|
44
|
+
<v-card-title class="d-flex align-center">
|
|
45
|
+
<span class="flex-grow-1">{{ titleOf(current) }}</span>
|
|
46
|
+
<v-btn icon="mdi-close" variant="text" aria-label="Close" @click="closeDetail" />
|
|
47
|
+
</v-card-title>
|
|
48
|
+
<v-card-text>
|
|
49
|
+
<v-progress-linear v-if="mediaLoading" indeterminate />
|
|
50
|
+
<img v-if="snapshot" :src="snapshot" :alt="`Snapshot of ${titleOf(current)}`" class="cctv-ev__img" />
|
|
51
|
+
<CctvEngineNotice v-else-if="!mediaLoading && current.hasSnapshot === false" title="No picture saved" body="The engine did not keep a snapshot for this event." />
|
|
52
|
+
<CctvEngineNotice v-if="mediaError" :error="mediaError" />
|
|
53
|
+
|
|
54
|
+
<video v-if="clip" :src="clip" controls autoplay class="cctv-ev__img mt-3" />
|
|
55
|
+
<v-btn v-else-if="current.hasClip" class="mt-3" prepend-icon="mdi-play" :loading="clipLoading" @click="loadClip">Play clip</v-btn>
|
|
56
|
+
<div v-else class="hero-muted mt-3">No video clip was saved for this event.</div>
|
|
57
|
+
|
|
58
|
+
<v-table density="compact" class="mt-4">
|
|
59
|
+
<tbody>
|
|
60
|
+
<tr><th>Camera</th><td>{{ current.camera }}</td></tr>
|
|
61
|
+
<tr><th>When</th><td>{{ when(current.startTime) }}<template v-if="current.endTime"> to {{ when(current.endTime) }}</template></td></tr>
|
|
62
|
+
<tr><th>Object</th><td>{{ current.label }}<template v-if="current.subLabel"> ({{ current.subLabel }})</template></td></tr>
|
|
63
|
+
<tr v-if="current.faceName"><th>Face</th><td>{{ current.faceName }}</td></tr>
|
|
64
|
+
<tr v-if="current.plate"><th>Plate</th><td>{{ current.plate }}</td></tr>
|
|
65
|
+
<tr><th>Zones</th><td>{{ (current.zones ?? []).join(", ") || "None" }}<template v-if="(current.enteredZones ?? []).length"> (entered: {{ current.enteredZones.join(" then ") }})</template></td></tr>
|
|
66
|
+
<tr><th>Confidence</th><td>{{ scoreText(current.score) }}</td></tr>
|
|
67
|
+
<tr v-if="current.incident"><th>Incident</th><td>An incident report was created for this alert.</td></tr>
|
|
68
|
+
</tbody>
|
|
69
|
+
</v-table>
|
|
70
|
+
</v-card-text>
|
|
71
|
+
</v-card>
|
|
72
|
+
</v-dialog>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<script setup lang="ts">
|
|
77
|
+
import { computed, onBeforeUnmount, reactive, ref } from "vue";
|
|
78
|
+
import { useDisplay } from "vuetify";
|
|
79
|
+
import { EVENT_KINDS, EVENT_SEVERITIES, type TEventFilters } from "../../utils/cctv-engine";
|
|
80
|
+
|
|
81
|
+
const props = defineProps<{ site: string; access?: unknown }>();
|
|
82
|
+
const { listEvents, eventSnapshot, eventClip } = useCctvEngine();
|
|
83
|
+
const { smAndDown } = useDisplay();
|
|
84
|
+
|
|
85
|
+
const f = reactive<TEventFilters>({});
|
|
86
|
+
const items = ref<any[]>([]);
|
|
87
|
+
const page = ref(1);
|
|
88
|
+
const pages = ref(1);
|
|
89
|
+
const pageRange = ref("");
|
|
90
|
+
const loading = ref(false);
|
|
91
|
+
const error = ref<unknown>(null);
|
|
92
|
+
const filtered = computed(() => Object.entries(f).some(([k, v]) => k !== "page" && k !== "limit" && !!v));
|
|
93
|
+
|
|
94
|
+
async function load() {
|
|
95
|
+
loading.value = true;
|
|
96
|
+
error.value = null;
|
|
97
|
+
try {
|
|
98
|
+
const res: any = await listEvents(props.site, { ...f, page: page.value });
|
|
99
|
+
items.value = res?.items ?? [];
|
|
100
|
+
pages.value = Number(res?.pages) || 1;
|
|
101
|
+
pageRange.value = typeof res?.pageRange === "string" ? res.pageRange : "";
|
|
102
|
+
} catch (e) {
|
|
103
|
+
error.value = e;
|
|
104
|
+
items.value = [];
|
|
105
|
+
} finally {
|
|
106
|
+
loading.value = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function search() {
|
|
110
|
+
page.value = 1;
|
|
111
|
+
load();
|
|
112
|
+
}
|
|
113
|
+
function clear() {
|
|
114
|
+
for (const k of Object.keys(f)) delete (f as any)[k];
|
|
115
|
+
search();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const kindTitle = (k: string) => EVENT_KINDS.find((x) => x.value === k)?.title ?? k;
|
|
119
|
+
const when = (v?: string) => (v ? new Date(v).toLocaleString() : "");
|
|
120
|
+
const scoreText = (s?: number) => (typeof s === "number" ? `${Math.round(s <= 1 ? s * 100 : s)}%` : "Not given");
|
|
121
|
+
const titleOf = (e: any) => [e.label, e.faceName && `- ${e.faceName}`, e.plate && `- ${e.plate}`].filter(Boolean).join(" ") || "Event";
|
|
122
|
+
const subtitleOf = (e: any) => `${e.camera} - ${when(e.startTime)}${(e.zones ?? []).length ? ` - ${e.zones.join(", ")}` : ""}`;
|
|
123
|
+
|
|
124
|
+
// ---- detail
|
|
125
|
+
const detailOpen = ref(false);
|
|
126
|
+
const current = ref<any>(null);
|
|
127
|
+
const snapshot = ref("");
|
|
128
|
+
const clip = ref("");
|
|
129
|
+
const mediaLoading = ref(false);
|
|
130
|
+
const clipLoading = ref(false);
|
|
131
|
+
const mediaError = ref<unknown>(null);
|
|
132
|
+
|
|
133
|
+
function freeMedia() {
|
|
134
|
+
if (snapshot.value) URL.revokeObjectURL(snapshot.value);
|
|
135
|
+
if (clip.value) URL.revokeObjectURL(clip.value);
|
|
136
|
+
snapshot.value = clip.value = "";
|
|
137
|
+
mediaError.value = null;
|
|
138
|
+
}
|
|
139
|
+
async function open(e: any) {
|
|
140
|
+
freeMedia();
|
|
141
|
+
current.value = e;
|
|
142
|
+
detailOpen.value = true;
|
|
143
|
+
if (e.hasSnapshot === false) return;
|
|
144
|
+
mediaLoading.value = true;
|
|
145
|
+
try {
|
|
146
|
+
snapshot.value = await eventSnapshot(e._id);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
mediaError.value = err;
|
|
149
|
+
} finally {
|
|
150
|
+
mediaLoading.value = false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function loadClip() {
|
|
154
|
+
clipLoading.value = true;
|
|
155
|
+
mediaError.value = null;
|
|
156
|
+
try {
|
|
157
|
+
clip.value = await eventClip(current.value._id);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
mediaError.value = err;
|
|
160
|
+
} finally {
|
|
161
|
+
clipLoading.value = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function closeDetail() {
|
|
165
|
+
detailOpen.value = false;
|
|
166
|
+
freeMedia();
|
|
167
|
+
}
|
|
168
|
+
onBeforeUnmount(freeMedia);
|
|
169
|
+
|
|
170
|
+
load();
|
|
171
|
+
</script>
|
|
172
|
+
|
|
173
|
+
<style scoped>
|
|
174
|
+
.cctv-ev__img { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 8px; }
|
|
175
|
+
</style>
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Face library. Add a person's photo and name so cameras can name them in events.
|
|
3
|
+
Consent details are OPTIONAL for now (they are stored when given and shown here); adding a face is never blocked by them.
|
|
4
|
+
The shell hides this page with an explanation when face recognition is switched off for the site.
|
|
5
|
+
-->
|
|
6
|
+
<template>
|
|
7
|
+
<div>
|
|
8
|
+
<v-alert type="info" variant="tonal" density="compact" class="mb-3" icon="mdi-information-outline">
|
|
9
|
+
Faces are stored on the site's engine. Only add people who know they are being recognised, and fill in who they are and why when you can.
|
|
10
|
+
Those details are optional today, but they help when rules on consent are applied later.
|
|
11
|
+
</v-alert>
|
|
12
|
+
|
|
13
|
+
<CctvEngineCameraPicker v-model:engine="engine" no-camera :site="site" />
|
|
14
|
+
|
|
15
|
+
<template v-if="engine">
|
|
16
|
+
<div class="d-flex align-center mt-3">
|
|
17
|
+
<h3 class="hero-title flex-grow-1">Faces on this engine</h3>
|
|
18
|
+
<v-btn v-if="canEdit" color="primary" prepend-icon="mdi-account-plus-outline" @click="openForm">Add face</v-btn>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<v-progress-linear v-if="loading" indeterminate />
|
|
22
|
+
<CctvEngineNotice v-else-if="error" :error="error" retry @retry="load" />
|
|
23
|
+
<CctvEngineNotice
|
|
24
|
+
v-else-if="!faces.length"
|
|
25
|
+
title="No faces added yet"
|
|
26
|
+
body="Add a clear, front-facing photo and a name. When a camera recognises the person, their name shows on the event."
|
|
27
|
+
/>
|
|
28
|
+
<v-list v-else lines="two">
|
|
29
|
+
<v-list-item v-for="f in faces" :key="f.faceName" :title="f.faceName" :subtitle="subtitle(f)">
|
|
30
|
+
<template #prepend>
|
|
31
|
+
<v-avatar color="primary" variant="tonal"><v-icon>mdi-face-recognition</v-icon></v-avatar>
|
|
32
|
+
</template>
|
|
33
|
+
<template #append>
|
|
34
|
+
<v-chip v-if="f.consent?.revokedAt" size="small" color="warning" label class="mr-2">Consent withdrawn</v-chip>
|
|
35
|
+
<v-btn v-if="canEdit" icon="mdi-delete-outline" variant="text" size="small" aria-label="Delete face" @click="askDelete(f)" />
|
|
36
|
+
</template>
|
|
37
|
+
</v-list-item>
|
|
38
|
+
</v-list>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<v-dialog v-model="formOpen" max-width="520" scrollable>
|
|
42
|
+
<v-card>
|
|
43
|
+
<v-card-title>Add a face</v-card-title>
|
|
44
|
+
<v-card-text>
|
|
45
|
+
<v-file-input v-model="photo" label="Photo" accept="image/jpeg,image/png" prepend-icon="mdi-camera" density="comfortable" show-size hint="One person, face clearly visible, good light." persistent-hint />
|
|
46
|
+
<v-text-field v-model="form.faceName" label="Name" density="comfortable" class="mt-3" hint="Shown on events, e.g. Tan Wei Ming." persistent-hint />
|
|
47
|
+
<div class="text-subtitle-2 mt-4">Consent details (optional)</div>
|
|
48
|
+
<v-select v-model="form.personType" :items="PERSON_TYPES" label="Who is this" density="comfortable" clearable />
|
|
49
|
+
<v-text-field v-model="form.purpose" label="Purpose (e.g. Staff gate entry)" density="comfortable" />
|
|
50
|
+
<v-text-field v-model="form.retentionUntil" type="date" label="Keep until" density="comfortable" />
|
|
51
|
+
<div v-if="problem" class="text-error" role="alert">{{ problem }}</div>
|
|
52
|
+
<CctvEngineNotice v-if="formError" class="mt-2" :error="formError" />
|
|
53
|
+
</v-card-text>
|
|
54
|
+
<v-card-actions>
|
|
55
|
+
<v-spacer />
|
|
56
|
+
<v-btn variant="text" @click="formOpen = false">Cancel</v-btn>
|
|
57
|
+
<v-btn color="primary" :loading="saving" @click="save">Add face</v-btn>
|
|
58
|
+
</v-card-actions>
|
|
59
|
+
</v-card>
|
|
60
|
+
</v-dialog>
|
|
61
|
+
|
|
62
|
+
<v-dialog v-model="deleteOpen" max-width="440">
|
|
63
|
+
<v-card>
|
|
64
|
+
<v-card-title>Delete {{ target?.faceName }}?</v-card-title>
|
|
65
|
+
<v-card-text>The face is removed from the engine and the consent record is marked withdrawn. Past events keep the name.</v-card-text>
|
|
66
|
+
<v-card-actions>
|
|
67
|
+
<v-spacer />
|
|
68
|
+
<v-btn variant="text" @click="deleteOpen = false">Keep</v-btn>
|
|
69
|
+
<v-btn color="error" :loading="saving" @click="doDelete">Delete</v-btn>
|
|
70
|
+
</v-card-actions>
|
|
71
|
+
</v-card>
|
|
72
|
+
</v-dialog>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<script setup lang="ts">
|
|
77
|
+
import { computed, reactive, ref, watch } from "vue";
|
|
78
|
+
import { CCTV_PERMISSIONS } from "../../utils/cctv-engine";
|
|
79
|
+
|
|
80
|
+
const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
|
|
81
|
+
const { listFaces, enrolFace, deleteFace } = useCctvEngine();
|
|
82
|
+
const canEdit = computed(() => props.access?.can(CCTV_PERMISSIONS.manageFaces) ?? false);
|
|
83
|
+
|
|
84
|
+
const PERSON_TYPES = [
|
|
85
|
+
{ value: "resident", title: "Resident" },
|
|
86
|
+
{ value: "staff", title: "Staff" },
|
|
87
|
+
{ value: "other", title: "Other" },
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const engine = ref("");
|
|
91
|
+
const faces = ref<any[]>([]);
|
|
92
|
+
const loading = ref(false);
|
|
93
|
+
const error = ref<unknown>(null);
|
|
94
|
+
|
|
95
|
+
async function load() {
|
|
96
|
+
faces.value = [];
|
|
97
|
+
error.value = null;
|
|
98
|
+
if (!engine.value) return;
|
|
99
|
+
loading.value = true;
|
|
100
|
+
try {
|
|
101
|
+
const res: any = await listFaces(engine.value);
|
|
102
|
+
faces.value = res?.items ?? [];
|
|
103
|
+
} catch (e) {
|
|
104
|
+
error.value = e;
|
|
105
|
+
} finally {
|
|
106
|
+
loading.value = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
watch(engine, load);
|
|
110
|
+
|
|
111
|
+
function subtitle(f: any) {
|
|
112
|
+
const c = f.consent;
|
|
113
|
+
if (!c) return "No consent details recorded";
|
|
114
|
+
return [PERSON_TYPES.find((p) => p.value === c.personType)?.title, c.purpose, c.retentionUntil && `keep until ${new Date(c.retentionUntil).toLocaleDateString()}`].filter(Boolean).join(" - ") || "No consent details recorded";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const form = reactive({ faceName: "", personType: null as string | null, purpose: "", retentionUntil: "" });
|
|
118
|
+
const photo = ref<File[] | File | null>(null);
|
|
119
|
+
const formOpen = ref(false);
|
|
120
|
+
const saving = ref(false);
|
|
121
|
+
const problem = ref("");
|
|
122
|
+
const formError = ref<unknown>(null);
|
|
123
|
+
|
|
124
|
+
function openForm() {
|
|
125
|
+
Object.assign(form, { faceName: "", personType: null, purpose: "", retentionUntil: "" });
|
|
126
|
+
photo.value = null;
|
|
127
|
+
problem.value = "";
|
|
128
|
+
formError.value = null;
|
|
129
|
+
formOpen.value = true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function save() {
|
|
133
|
+
const file = Array.isArray(photo.value) ? photo.value[0] : photo.value;
|
|
134
|
+
if (!file) return void (problem.value = "Choose a photo.");
|
|
135
|
+
if (!form.faceName.trim()) return void (problem.value = "Enter the person's name.");
|
|
136
|
+
problem.value = "";
|
|
137
|
+
saving.value = true;
|
|
138
|
+
formError.value = null;
|
|
139
|
+
// Consent is optional: send only what was filled in.
|
|
140
|
+
const consent: Record<string, string> = {};
|
|
141
|
+
if (form.personType) consent.personType = form.personType;
|
|
142
|
+
if (form.purpose.trim()) consent.purpose = form.purpose.trim();
|
|
143
|
+
if (form.retentionUntil) consent.retentionUntil = form.retentionUntil;
|
|
144
|
+
try {
|
|
145
|
+
await enrolFace(engine.value, file, form.faceName.trim(), consent);
|
|
146
|
+
formOpen.value = false;
|
|
147
|
+
await load();
|
|
148
|
+
} catch (e) {
|
|
149
|
+
formError.value = e;
|
|
150
|
+
} finally {
|
|
151
|
+
saving.value = false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const deleteOpen = ref(false);
|
|
156
|
+
const target = ref<any>(null);
|
|
157
|
+
const askDelete = (f: any) => {
|
|
158
|
+
target.value = f;
|
|
159
|
+
deleteOpen.value = true;
|
|
160
|
+
};
|
|
161
|
+
async function doDelete() {
|
|
162
|
+
saving.value = true;
|
|
163
|
+
try {
|
|
164
|
+
await deleteFace(engine.value, target.value.faceName);
|
|
165
|
+
deleteOpen.value = false;
|
|
166
|
+
await load();
|
|
167
|
+
} catch (e) {
|
|
168
|
+
deleteOpen.value = false;
|
|
169
|
+
error.value = e;
|
|
170
|
+
} finally {
|
|
171
|
+
saving.value = false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
</script>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!-- Live view: one camera, or a grid of 4 / 9 / 16. On a phone the grid never goes past two columns. -->
|
|
2
|
+
<template>
|
|
3
|
+
<div>
|
|
4
|
+
<CctvEngineCameraPicker v-model:engine="engine" no-camera :site="site" @engines="onEngines" />
|
|
5
|
+
|
|
6
|
+
<template v-if="engine">
|
|
7
|
+
<div class="d-flex flex-wrap align-center ga-3 my-3">
|
|
8
|
+
<v-btn-toggle v-model="tiles" mandatory density="comfortable" divided color="primary" aria-label="Grid size">
|
|
9
|
+
<v-btn v-for="l in GRID_LAYOUTS" :key="l.key" :value="l.key" size="small">{{ l.key === 1 ? "Single" : l.key }}</v-btn>
|
|
10
|
+
</v-btn-toggle>
|
|
11
|
+
<v-select
|
|
12
|
+
v-model="picked"
|
|
13
|
+
:items="cameras"
|
|
14
|
+
item-title="name"
|
|
15
|
+
item-value="name"
|
|
16
|
+
label="Cameras shown"
|
|
17
|
+
multiple
|
|
18
|
+
chips
|
|
19
|
+
closable-chips
|
|
20
|
+
density="comfortable"
|
|
21
|
+
hide-details
|
|
22
|
+
:hint="`Up to ${tiles}. Empty = the first ${tiles} on this engine.`"
|
|
23
|
+
class="cctv-live__picker"
|
|
24
|
+
:max-width="smAndDown ? undefined : 420"
|
|
25
|
+
/>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<v-progress-linear v-if="loading" indeterminate />
|
|
29
|
+
<CctvEngineNotice v-else-if="error" :error="error" retry @retry="loadCameras" />
|
|
30
|
+
<CctvEngineNotice
|
|
31
|
+
v-else-if="!cameras.length"
|
|
32
|
+
title="This engine has no cameras yet"
|
|
33
|
+
body="Cameras are added to the engine itself. Once the engine reports them they appear here; if you just set it up, check it shows Online in Engines & health."
|
|
34
|
+
/>
|
|
35
|
+
<div v-else class="cctv-live__grid" :style="{ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` }">
|
|
36
|
+
<CctvEngineLiveTile v-for="c in shown" :key="`${engine}/${c.name}`" :engine-id="engine" :camera="c.name" />
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script setup lang="ts">
|
|
43
|
+
import { computed, ref, watch } from "vue";
|
|
44
|
+
import { useDisplay } from "vuetify";
|
|
45
|
+
import { GRID_LAYOUTS, gridColumns, pickGridCameras } from "../../utils/cctv-engine";
|
|
46
|
+
|
|
47
|
+
defineProps<{ site: string; access?: unknown }>();
|
|
48
|
+
|
|
49
|
+
const { listCameras } = useCctvEngine();
|
|
50
|
+
const { smAndDown } = useDisplay();
|
|
51
|
+
|
|
52
|
+
const engine = ref("");
|
|
53
|
+
const tiles = ref<number>(4);
|
|
54
|
+
const picked = ref<string[]>([]);
|
|
55
|
+
const cameras = ref<{ name: string }[]>([]);
|
|
56
|
+
const loading = ref(false);
|
|
57
|
+
const error = ref<unknown>(null);
|
|
58
|
+
|
|
59
|
+
const shown = computed(() => pickGridCameras(cameras.value, picked.value.slice(0, tiles.value), tiles.value));
|
|
60
|
+
const columns = computed(() => gridColumns(tiles.value, smAndDown.value));
|
|
61
|
+
|
|
62
|
+
function onEngines(list: any[]) {
|
|
63
|
+
if (!engine.value && list[0]) engine.value = list[0]._id;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function loadCameras() {
|
|
67
|
+
cameras.value = [];
|
|
68
|
+
picked.value = [];
|
|
69
|
+
error.value = null;
|
|
70
|
+
if (!engine.value) return;
|
|
71
|
+
loading.value = true;
|
|
72
|
+
try {
|
|
73
|
+
const res: any = await listCameras(engine.value);
|
|
74
|
+
cameras.value = res?.items ?? [];
|
|
75
|
+
} catch (e) {
|
|
76
|
+
error.value = e;
|
|
77
|
+
} finally {
|
|
78
|
+
loading.value = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
watch(engine, loadCameras, { immediate: true });
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<style scoped>
|
|
86
|
+
.cctv-live__grid { display: grid; gap: 8px; }
|
|
87
|
+
.cctv-live__picker { min-width: 220px; flex: 1; }
|
|
88
|
+
</style>
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One live camera. Tries WebRTC (smooth video, receive-only); if the browser or network cannot, falls back to the
|
|
3
|
+
latest still picture refreshed every 2 seconds and says so with a "Low-bandwidth view" label.
|
|
4
|
+
Offline engine / failures are shown on the tile in plain words with a Try again button.
|
|
5
|
+
-->
|
|
6
|
+
<template>
|
|
7
|
+
<div class="cctv-tile" :class="{ 'cctv-tile--big': big }" data-test="cctv-tile">
|
|
8
|
+
<video v-show="mode === 'live'" ref="video" autoplay muted playsinline class="cctv-tile__media" />
|
|
9
|
+
<img v-if="mode === 'still' && still" :src="still" :alt="`Latest picture from ${camera}`" class="cctv-tile__media" />
|
|
10
|
+
|
|
11
|
+
<div v-if="mode === 'connecting'" class="cctv-tile__msg" role="status">
|
|
12
|
+
<v-progress-circular indeterminate size="22" /> <span>Connecting to {{ camera }}...</span>
|
|
13
|
+
</div>
|
|
14
|
+
<div v-else-if="mode === 'error'" class="cctv-tile__msg" role="alert">
|
|
15
|
+
<strong>{{ notice.title }}</strong>
|
|
16
|
+
<span>{{ notice.body }}</span>
|
|
17
|
+
<v-btn size="x-small" variant="tonal" @click="start">Try again</v-btn>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<div class="cctv-tile__bar">
|
|
21
|
+
<span class="cctv-tile__name">{{ camera }}</span>
|
|
22
|
+
<v-chip v-if="mode === 'live'" size="x-small" color="success" label>Live</v-chip>
|
|
23
|
+
<v-chip
|
|
24
|
+
v-else-if="mode === 'still'"
|
|
25
|
+
size="x-small"
|
|
26
|
+
color="warning"
|
|
27
|
+
label
|
|
28
|
+
title="Live video could not start, so this picture refreshes every 2 seconds instead."
|
|
29
|
+
>
|
|
30
|
+
Low-bandwidth view
|
|
31
|
+
</v-chip>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
38
|
+
import { cctvNotice, STILL_REFRESH_MS } from "../../utils/cctv-engine";
|
|
39
|
+
|
|
40
|
+
const props = defineProps<{ engineId: string; camera: string; big?: boolean }>();
|
|
41
|
+
|
|
42
|
+
const { webrtcAnswer, latestImage } = useCctvEngine();
|
|
43
|
+
|
|
44
|
+
const mode = ref<"connecting" | "live" | "still" | "error">("connecting");
|
|
45
|
+
const still = ref("");
|
|
46
|
+
const failure = ref<unknown>(null);
|
|
47
|
+
const video = ref<HTMLVideoElement | null>(null);
|
|
48
|
+
const notice = computed(() => cctvNotice(failure.value));
|
|
49
|
+
|
|
50
|
+
let pc: RTCPeerConnection | null = null;
|
|
51
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
52
|
+
let run = 0; // bumps on every start/stop so a late answer from an old attempt is ignored
|
|
53
|
+
|
|
54
|
+
function stop() {
|
|
55
|
+
run++;
|
|
56
|
+
if (timer) clearTimeout(timer);
|
|
57
|
+
timer = null;
|
|
58
|
+
if (pc) {
|
|
59
|
+
pc.ontrack = null;
|
|
60
|
+
pc.onconnectionstatechange = null;
|
|
61
|
+
pc.close();
|
|
62
|
+
pc = null;
|
|
63
|
+
}
|
|
64
|
+
if (video.value) video.value.srcObject = null;
|
|
65
|
+
if (still.value) URL.revokeObjectURL(still.value);
|
|
66
|
+
still.value = "";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function gathered(conn: RTCPeerConnection, ms = 2000) {
|
|
70
|
+
return new Promise<void>((resolve) => {
|
|
71
|
+
if (conn.iceGatheringState === "complete") return resolve();
|
|
72
|
+
const done = () => {
|
|
73
|
+
conn.removeEventListener("icegatheringstatechange", check);
|
|
74
|
+
resolve();
|
|
75
|
+
};
|
|
76
|
+
const check = () => conn.iceGatheringState === "complete" && done();
|
|
77
|
+
conn.addEventListener("icegatheringstatechange", check);
|
|
78
|
+
setTimeout(done, ms);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function tryWebrtc(token: number) {
|
|
83
|
+
if (typeof RTCPeerConnection === "undefined") throw new Error("no-webrtc");
|
|
84
|
+
const stun = String(useRuntimeConfig().public.CCTV_STUN_URL ?? "");
|
|
85
|
+
const conn = new RTCPeerConnection({ iceServers: stun ? [{ urls: stun }] : [] });
|
|
86
|
+
pc = conn;
|
|
87
|
+
conn.addTransceiver("video", { direction: "recvonly" });
|
|
88
|
+
conn.addTransceiver("audio", { direction: "recvonly" });
|
|
89
|
+
const connected = new Promise<void>((resolve, reject) => {
|
|
90
|
+
conn.ontrack = (ev) => {
|
|
91
|
+
if (token !== run || !video.value) return;
|
|
92
|
+
video.value.srcObject = ev.streams[0] ?? new MediaStream([ev.track]);
|
|
93
|
+
resolve();
|
|
94
|
+
};
|
|
95
|
+
conn.onconnectionstatechange = () => {
|
|
96
|
+
if (token !== run) return;
|
|
97
|
+
if (conn.connectionState === "failed") reject(new Error("webrtc-failed"));
|
|
98
|
+
if (conn.connectionState === "disconnected" || conn.connectionState === "closed") {
|
|
99
|
+
if (mode.value === "live") fallbackToStill(token);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
setTimeout(() => reject(new Error("webrtc-timeout")), 10000);
|
|
103
|
+
});
|
|
104
|
+
await conn.setLocalDescription(await conn.createOffer());
|
|
105
|
+
await gathered(conn);
|
|
106
|
+
const answer = await webrtcAnswer(props.engineId, props.camera, conn.localDescription!.sdp);
|
|
107
|
+
if (token !== run) return;
|
|
108
|
+
await conn.setRemoteDescription({ type: "answer", sdp: answer.sdp });
|
|
109
|
+
await connected;
|
|
110
|
+
if (token === run) mode.value = "live";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function pollStill(token: number) {
|
|
114
|
+
if (token !== run) return;
|
|
115
|
+
try {
|
|
116
|
+
if (!document.hidden) {
|
|
117
|
+
const next = await latestImage(props.engineId, props.camera);
|
|
118
|
+
if (token !== run) return URL.revokeObjectURL(next);
|
|
119
|
+
if (still.value) URL.revokeObjectURL(still.value);
|
|
120
|
+
still.value = next;
|
|
121
|
+
mode.value = "still";
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
if (token !== run) return;
|
|
125
|
+
failure.value = e;
|
|
126
|
+
mode.value = "error";
|
|
127
|
+
return; // stop polling on a refusal; "Try again" restarts it
|
|
128
|
+
}
|
|
129
|
+
timer = setTimeout(() => pollStill(token), STILL_REFRESH_MS);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function fallbackToStill(token: number) {
|
|
133
|
+
if (token !== run) return;
|
|
134
|
+
if (pc) {
|
|
135
|
+
pc.close();
|
|
136
|
+
pc = null;
|
|
137
|
+
}
|
|
138
|
+
pollStill(token);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function start() {
|
|
142
|
+
stop();
|
|
143
|
+
const token = run;
|
|
144
|
+
mode.value = "connecting";
|
|
145
|
+
failure.value = null;
|
|
146
|
+
try {
|
|
147
|
+
await tryWebrtc(token);
|
|
148
|
+
} catch (e: any) {
|
|
149
|
+
if (token !== run) return;
|
|
150
|
+
// The engine being offline is the same for the still picture, so say it instead of pretending to fall back.
|
|
151
|
+
if (cctvNotice(e).kind === "offline" || Number(e?.statusCode) === 401 || Number(e?.statusCode) === 403) {
|
|
152
|
+
failure.value = e;
|
|
153
|
+
mode.value = "error";
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
fallbackToStill(token);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
onMounted(() => {
|
|
161
|
+
// declared above: start() reads only refs defined before this runs
|
|
162
|
+
watch(() => [props.engineId, props.camera], start, { immediate: true });
|
|
163
|
+
});
|
|
164
|
+
onBeforeUnmount(stop);
|
|
165
|
+
</script>
|
|
166
|
+
|
|
167
|
+
<style scoped>
|
|
168
|
+
.cctv-tile { position: relative; background: #000; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; color: #fff; }
|
|
169
|
+
.cctv-tile__media { width: 100%; height: 100%; object-fit: contain; display: block; }
|
|
170
|
+
.cctv-tile__msg { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; text-align: center; padding: 12px; font-size: 12px; overflow: auto; }
|
|
171
|
+
.cctv-tile__bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.75)); }
|
|
172
|
+
.cctv-tile__name { flex: 1; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
173
|
+
</style>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One place that says, in plain words, what a state means and what to do next:
|
|
3
|
+
an API refusal (pass `error`), or an empty / loading / info state (pass `title` + `body`).
|
|
4
|
+
-->
|
|
5
|
+
<template>
|
|
6
|
+
<div
|
|
7
|
+
class="hero-notice hero-notice--panel cctv-notice"
|
|
8
|
+
:class="{ 'hero-notice--error': tone === 'error' }"
|
|
9
|
+
:role="tone === 'error' ? 'alert' : 'status'"
|
|
10
|
+
data-test="cctv-notice"
|
|
11
|
+
>
|
|
12
|
+
<div class="d-flex align-start ga-3">
|
|
13
|
+
<v-icon :icon="icon" size="22" class="mt-1" />
|
|
14
|
+
<div class="flex-grow-1">
|
|
15
|
+
<div class="hero-notice__title">{{ shown.title }}</div>
|
|
16
|
+
<div class="hero-notice__body">{{ shown.body }}</div>
|
|
17
|
+
<div v-if="$slots.default" class="mt-2"><slot /></div>
|
|
18
|
+
<v-btn v-if="retry" size="small" variant="tonal" class="mt-3" @click="$emit('retry')">Try again</v-btn>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script setup lang="ts">
|
|
25
|
+
import { computed } from "vue";
|
|
26
|
+
import { cctvNotice } from "../../utils/cctv-engine";
|
|
27
|
+
|
|
28
|
+
const props = defineProps<{
|
|
29
|
+
error?: unknown;
|
|
30
|
+
title?: string;
|
|
31
|
+
body?: string;
|
|
32
|
+
/** "info" (default for title/body), "error" (default for `error`). */
|
|
33
|
+
tone?: "info" | "error";
|
|
34
|
+
/** Show the Try again button (emits `retry`). */
|
|
35
|
+
retry?: boolean;
|
|
36
|
+
}>();
|
|
37
|
+
defineEmits<{ (e: "retry"): void }>();
|
|
38
|
+
|
|
39
|
+
const fromError = computed(() => (props.error ? cctvNotice(props.error) : null));
|
|
40
|
+
const shown = computed(() => ({
|
|
41
|
+
title: props.title ?? fromError.value?.title ?? "",
|
|
42
|
+
body: props.body ?? fromError.value?.body ?? "",
|
|
43
|
+
}));
|
|
44
|
+
const tone = computed(() => props.tone ?? (props.error ? "error" : "info"));
|
|
45
|
+
const icon = computed(() => {
|
|
46
|
+
switch (fromError.value?.kind) {
|
|
47
|
+
case "offline": return "mdi-lan-disconnect";
|
|
48
|
+
case "disabled":
|
|
49
|
+
case "face-off": return "mdi-toggle-switch-off-outline";
|
|
50
|
+
case "denied": return "mdi-lock-outline";
|
|
51
|
+
default: return tone.value === "error" ? "mdi-alert-circle-outline" : "mdi-information-outline";
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
</script>
|