@7365admin1/layer-common 4.97.1-staging.627 → 4.97.1-staging.629

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.
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  New smart detection, in two steps.
3
- Step 1: name it, pick a camera, drag a box over the area to watch on the camera's latest picture.
3
+ Step 1: name it, pick a camera, drag a box over the area to watch on the camera's live view.
4
4
  Step 2: list the results (what the area can look like) and which ones should raise an alert.
5
5
  The box is saved as fractions of the picture (0..1) so it stays right at any screen size.
6
6
  -->
@@ -42,26 +42,23 @@
42
42
  </v-row>
43
43
 
44
44
  <template v-if="camera">
45
- <v-progress-linear v-if="imgLoading" indeterminate class="mb-2" />
46
45
  <div
47
46
  ref="stage"
48
47
  class="cctv-dc__stage"
49
48
  role="img"
50
- :aria-label="`Latest picture from ${camera}. Drag to draw a box over the area.`"
49
+ :aria-label="`Live view of ${camera}. Drag to draw a box over the area.`"
51
50
  @pointerdown.prevent="down"
52
51
  @pointermove="move"
53
52
  @pointerup="up"
54
53
  @pointercancel="up"
55
54
  >
56
- <img v-if="image" :src="image" alt="" class="cctv-dc__img" draggable="false" />
57
- <div v-else-if="!imgLoading" class="cctv-dc__none">No picture available yet. The engine may be offline. You can still draw a box.</div>
55
+ <CctvEngineLiveTile :key="`${engine}/${camera}`" :engine-id="engine" :camera="camera" natural class="cctv-dc__live" />
58
56
  <div v-if="box" class="cctv-dc__box" :style="boxStyle" />
59
57
  </div>
60
58
  <div class="hero-muted mt-1">
61
59
  <template v-if="cropIsUsable(crop)">Area set. Drag again to change it.</template>
62
60
  <template v-else>Press and drag on the picture to draw a box around the area. Make it big enough to see clearly.</template>
63
61
  </div>
64
- <CctvEngineNotice v-if="imgError" class="mt-2" tone="info" :error="imgError" title="The latest picture could not be loaded" body="The engine may be offline. You can still draw a box on the grey area." />
65
62
  </template>
66
63
  </template>
67
64
 
@@ -115,7 +112,7 @@
115
112
  </template>
116
113
 
117
114
  <script setup lang="ts">
118
- import { computed, onBeforeUnmount, ref, watch } from "vue";
115
+ import { computed, ref, watch } from "vue";
119
116
  import {
120
117
  cropFromDrag, cropIsUsable, DEFAULT_RESULTS, detectionNameProblem, MIN_PHOTOS_PER_RESULT, resultsProblem, toWord,
121
118
  type TCrop,
@@ -123,7 +120,7 @@ import {
123
120
 
124
121
  const props = defineProps<{ modelValue: boolean; engine: string }>();
125
122
  const emit = defineEmits<{ (e: "update:modelValue", v: boolean): void; (e: "created", message: string): void }>();
126
- const { listCameras, latestImage, createClassifier } = useCctvEngine();
123
+ const { listCameras, createClassifier } = useCctvEngine();
127
124
 
128
125
  const step = ref(1);
129
126
  const name = ref("");
@@ -131,9 +128,6 @@ const camera = ref("");
131
128
  const cameras = ref<any[]>([]);
132
129
  const camLoading = ref(false);
133
130
  const camError = ref<unknown>(null);
134
- const image = ref("");
135
- const imgLoading = ref(false);
136
- const imgError = ref<unknown>(null);
137
131
  const crop = ref<TCrop | null>(null);
138
132
  const states = ref<string[]>([...DEFAULT_RESULTS]);
139
133
  const alertStates = ref<string[]>(["rubbish"]);
@@ -176,11 +170,6 @@ function setStates(v: string[]) {
176
170
  alertStates.value = alertStates.value.filter((a) => clean.includes(a));
177
171
  }
178
172
 
179
- function freeImage() {
180
- if (image.value) URL.revokeObjectURL(image.value);
181
- image.value = "";
182
- }
183
-
184
173
  async function loadCameras() {
185
174
  cameras.value = [];
186
175
  camError.value = null;
@@ -194,20 +183,6 @@ async function loadCameras() {
194
183
  camLoading.value = false;
195
184
  }
196
185
  }
197
- async function loadImage() {
198
- freeImage();
199
- crop.value = null;
200
- imgError.value = null;
201
- if (!camera.value) return;
202
- imgLoading.value = true;
203
- try {
204
- image.value = await latestImage(props.engine, camera.value);
205
- } catch (e) {
206
- imgError.value = e;
207
- } finally {
208
- imgLoading.value = false;
209
- }
210
- }
211
186
 
212
187
  async function create() {
213
188
  saving.value = true;
@@ -236,7 +211,6 @@ function reset() {
236
211
  states.value = [...DEFAULT_RESULTS];
237
212
  alertStates.value = ["rubbish"];
238
213
  error.value = null;
239
- freeImage();
240
214
  }
241
215
  function close(v: boolean) {
242
216
  emit("update:modelValue", v);
@@ -248,13 +222,11 @@ watch(() => props.modelValue, (open) => {
248
222
  loadCameras();
249
223
  }
250
224
  }, { immediate: true });
251
- watch(camera, loadImage);
252
- onBeforeUnmount(freeImage);
225
+ watch(camera, () => (crop.value = null));
253
226
  </script>
254
227
 
255
228
  <style scoped>
256
229
  .cctv-dc__stage { position: relative; background: #111; border-radius: 10px; overflow: hidden; min-height: 180px; user-select: none; cursor: crosshair; touch-action: none; }
257
- .cctv-dc__img { width: 100%; display: block; pointer-events: none; }
258
- .cctv-dc__none { color: #ddd; padding: 60px 16px; text-align: center; font-size: 13px; aspect-ratio: 16 / 9; }
230
+ .cctv-dc__live { pointer-events: none; }
259
231
  .cctv-dc__box { position: absolute; border: 2px solid #fff; background: rgba(30, 136, 229, 0.3); box-shadow: 0 0 0 1px #1e88e5; pointer-events: none; }
260
232
  </style>
@@ -4,7 +4,7 @@
4
4
  Offline engine / failures are shown on the tile in plain words with a Try again button.
5
5
  -->
6
6
  <template>
7
- <div class="cctv-tile" :class="{ 'cctv-tile--big': big }" data-test="cctv-tile">
7
+ <div class="cctv-tile" :class="{ 'cctv-tile--big': big, 'cctv-tile--natural': natural }" data-test="cctv-tile">
8
8
  <video v-show="mode === 'live'" ref="video" autoplay muted playsinline class="cctv-tile__media" />
9
9
  <img v-if="mode === 'still' && still" :src="still" :alt="`Latest picture from ${camera}`" class="cctv-tile__media" />
10
10
 
@@ -37,7 +37,8 @@
37
37
  import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
38
38
  import { cctvNotice, STILL_REFRESH_MS } from "../../utils/cctv-engine";
39
39
 
40
- const props = defineProps<{ engineId: string; camera: string; big?: boolean }>();
40
+ // natural: keep the camera's own shape (no 16:9 box) so drawings laid over the tile line up with the picture.
41
+ const props = defineProps<{ engineId: string; camera: string; big?: boolean; natural?: boolean }>();
41
42
 
42
43
  const { webrtcAnswer, latestImage } = useCctvEngine();
43
44
 
@@ -86,7 +87,8 @@ async function tryWebrtc(token: number) {
86
87
  const conn = new RTCPeerConnection({ iceServers: stun ? [{ urls: stun }] : [] });
87
88
  pc = conn;
88
89
  conn.addTransceiver("video", { direction: "recvonly" });
89
- conn.addTransceiver("audio", { direction: "recvonly" });
90
+ // Video only: asking for sound can make the engine open a second connection to a recorder that
91
+ // has no audio on this stream, and recorders block boxes that open too many.
90
92
  const connected = new Promise<void>((resolve, reject) => {
91
93
  // A track is announced as soon as the answer is read, before any picture can arrive (the engine
92
94
  // may be unreachable for video). "Live" waits for the first decoded frame; otherwise stills.
@@ -175,6 +177,8 @@ onBeforeUnmount(stop);
175
177
  <style scoped>
176
178
  .cctv-tile { position: relative; background: #000; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; color: #fff; }
177
179
  .cctv-tile__media { width: 100%; height: 100%; object-fit: contain; display: block; }
180
+ .cctv-tile--natural { aspect-ratio: auto; min-height: 180px; border-radius: 0; }
181
+ .cctv-tile--natural .cctv-tile__media { height: auto; }
178
182
  .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; }
179
183
  .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)); }
180
184
  .cctv-tile__name { flex: 1; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@@ -1,5 +1,5 @@
1
1
  <!--
2
- Zones & wrong-way. Draw areas on the camera's latest picture (click to add corners). Zones name an area
2
+ Zones & wrong-way. Draw areas on the camera's live view (click to add corners). Zones name an area
3
3
  (for alerts and wrong-way rules); masks tell the engine to ignore an area (motion / objects).
4
4
  Coordinates are saved as fractions of the picture (0..1), so they stay right at any screen size.
5
5
  -->
@@ -17,11 +17,10 @@
17
17
  class="cctv-zn__stage"
18
18
  :class="{ 'cctv-zn__stage--draw': canEdit }"
19
19
  role="img"
20
- :aria-label="`Latest picture from ${camera}. ${canEdit ? 'Click to add a corner.' : ''}`"
20
+ :aria-label="`Live view of ${camera}. ${canEdit ? 'Click to add a corner.' : ''}`"
21
21
  @click="addPoint"
22
22
  >
23
- <img v-if="image" :src="image" alt="" class="cctv-zn__img" draggable="false" />
24
- <div v-else class="cctv-zn__none">No picture available yet - you can still draw, but placing is easier with a picture.</div>
23
+ <CctvEngineLiveTile :key="`${engine}/${camera}`" :engine-id="engine" :camera="camera" natural />
25
24
  <svg viewBox="0 0 1 1" preserveAspectRatio="none" class="cctv-zn__svg" aria-hidden="true">
26
25
  <polygon v-for="(z, i) in zones" :key="`z${i}`" :points="svg(z.points)" :fill="color(i, 0.25)" :stroke="color(i, 1)" stroke-width="2" vector-effect="non-scaling-stroke" />
27
26
  <polygon v-for="(m, i) in masks" :key="`m${i}`" :points="svg(m.points)" fill="rgba(0,0,0,0.45)" stroke="#fff" stroke-dasharray="6 4" stroke-width="2" vector-effect="non-scaling-stroke" />
@@ -65,7 +64,6 @@
65
64
  </div>
66
65
  </v-col>
67
66
  </v-row>
68
- <CctvEngineNotice v-if="imageError && !error" class="mt-2" :error="imageError" title="The latest picture could not be loaded" body="The engine may be offline. You can still draw, then save when it is back." tone="info" />
69
67
  </template>
70
68
 
71
69
  <v-divider class="my-6" />
@@ -74,14 +72,14 @@
74
72
  </template>
75
73
 
76
74
  <script setup lang="ts">
77
- import { computed, onBeforeUnmount, ref, watch } from "vue";
75
+ import { computed, ref, watch } from "vue";
78
76
  import {
79
77
  buildZonesBody, CCTV_PERMISSIONS, isValidPolygon, pointFromClick, polygonToSvgPoints, readZonesReply,
80
78
  type TMask, type TPoint, type TZone,
81
79
  } from "../../utils/cctv-engine";
82
80
 
83
81
  const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
84
- const { getZones, saveZones, latestImage } = useCctvEngine();
82
+ const { getZones, saveZones } = useCctvEngine();
85
83
 
86
84
  const engine = ref("");
87
85
  const camera = ref("");
@@ -98,8 +96,6 @@ const masks = ref<TMask[]>([]);
98
96
  const draft = ref<TPoint[]>([]);
99
97
  const kind = ref<"zone" | "motion" | "object">("zone");
100
98
  const zoneName = ref("");
101
- const image = ref("");
102
- const imageError = ref<unknown>(null);
103
99
  const loading = ref(false);
104
100
  const error = ref<unknown>(null);
105
101
  const saving = ref(false);
@@ -134,26 +130,19 @@ function readZones(res: any) {
134
130
  ({ zones: zones.value, masks: masks.value } = readZonesReply(res));
135
131
  }
136
132
 
137
- function freeImage() {
138
- if (image.value) URL.revokeObjectURL(image.value);
139
- image.value = "";
140
- }
141
-
142
133
  async function load() {
143
134
  zones.value = [];
144
135
  masks.value = [];
145
136
  draft.value = [];
146
137
  saveMsg.value = "";
147
138
  error.value = null;
148
- imageError.value = null;
149
- freeImage();
150
139
  if (!engine.value || !camera.value) return;
151
140
  loading.value = true;
152
- const [z, img] = await Promise.allSettled([getZones(engine.value, camera.value), latestImage(engine.value, camera.value)]);
153
- if (z.status === "fulfilled") readZones(z.value);
154
- else error.value = z.reason;
155
- if (img.status === "fulfilled") image.value = img.value;
156
- else imageError.value = img.reason;
141
+ try {
142
+ readZones(await getZones(engine.value, camera.value));
143
+ } catch (e) {
144
+ error.value = e;
145
+ }
157
146
  loading.value = false;
158
147
  }
159
148
 
@@ -176,14 +165,11 @@ async function save() {
176
165
  }
177
166
 
178
167
  watch([engine, camera], load);
179
- onBeforeUnmount(freeImage);
180
168
  </script>
181
169
 
182
170
  <style scoped>
183
171
  .cctv-zn__stage { position: relative; background: #111; border-radius: 10px; overflow: hidden; min-height: 180px; user-select: none; }
184
172
  .cctv-zn__stage--draw { cursor: crosshair; }
185
- .cctv-zn__img { width: 100%; display: block; }
186
- .cctv-zn__none { color: #ddd; padding: 60px 16px; text-align: center; font-size: 13px; aspect-ratio: 16 / 9; }
187
173
  .cctv-zn__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
188
174
  .cctv-zn__dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; border: 2px solid #1e88e5; pointer-events: none; }
189
175
  </style>
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.97.1-staging.627",
5
+ "version": "4.97.1-staging.629",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",