@7365admin1/layer-common 4.13.2 → 4.14.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 894a47c: CCTV camera wall: Recorded footage — pick a start time and length and play what the camera recorded (server link, plain refusal messages); `cctv-mgmt:view-recordings` added to the Property Management and Security catalogues.
8
+
3
9
  ## 4.13.2
4
10
 
5
11
  ### Patch Changes
@@ -1119,11 +1125,11 @@
1119
1125
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
1120
1126
  own rule from two endpoints the console already calls, unprojected:
1121
1127
 
1122
- GET /api/members/user/:user/app/admin the Seven365 staff membership
1123
- GET /api/roles/id/:role that membership's role document
1128
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
1129
+ GET /api/roles/id/:role that membership's role document
1124
1130
 
1125
- owner = member.type === "admin" && role.type === "admin" && role.default === true
1126
- staff = member.type === "admin" && role.type === "admin"
1131
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
1132
+ staff = member.type === "admin" && role.type === "admin"
1127
1133
 
1128
1134
  `role.default` is the marker because it is the only property of a platform
1129
1135
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -300,7 +300,10 @@
300
300
  v-for="c in WALL_CAPABILITY_CONTROLS"
301
301
  :key="c.key"
302
302
  class="vms__cap"
303
- :class="{ 'vms__cap--off': !capability(c.key).available }"
303
+ :class="{
304
+ 'vms__cap--off': !capability(c.key).available,
305
+ 'vms__cap--wide': c.key === 'playback' && capability(c.key).available,
306
+ }"
304
307
  >
305
308
  <p class="vms__cap-title">
306
309
  {{ c.title }}
@@ -318,6 +321,50 @@
318
321
  its title and its tag.
319
322
  -->
320
323
  <p v-if="capabilityText(c)" class="vms__cap-detail">{{ capabilityText(c) }}</p>
324
+ <!--
325
+ RECORDED FOOTAGE. Only when the server says this camera can serve it;
326
+ who may watch is the server's decision (site reach + the recordings
327
+ permission), and its refusal is shown here in plain words.
328
+ -->
329
+ <div v-if="c.key === 'playback' && capability(c.key).available" class="vms__playback">
330
+ <div class="vms__playback-form">
331
+ <label class="vms__playback-field">
332
+ Start
333
+ <input v-model="playbackStart" type="datetime-local" data-test="playback-start" />
334
+ </label>
335
+ <label class="vms__playback-field">
336
+ Length
337
+ <select v-model.number="playbackMinutes" data-test="playback-length">
338
+ <option v-for="m in PLAYBACK_MINUTES" :key="m" :value="m">{{ m }} minutes</option>
339
+ </select>
340
+ </label>
341
+ <button
342
+ type="button"
343
+ class="vms__playback-btn"
344
+ :disabled="playbackLoading"
345
+ data-test="playback-play"
346
+ @click="playRecording"
347
+ >
348
+ {{ playbackLoading ? "Opening…" : "Play" }}
349
+ </button>
350
+ <button
351
+ v-if="playbackUrl"
352
+ type="button"
353
+ class="vms__playback-btn vms__playback-btn--quiet"
354
+ @click="stopRecording"
355
+ >
356
+ Close
357
+ </button>
358
+ </div>
359
+ <p v-if="playbackError" class="vms__playback-error" role="alert">{{ playbackError }}</p>
360
+ <iframe
361
+ v-if="playbackUrl"
362
+ :src="playbackUrl"
363
+ class="vms__playback-player"
364
+ title="Recorded footage"
365
+ allow="autoplay; fullscreen"
366
+ />
367
+ </div>
321
368
  <!--
322
369
  RULE 5. The line the server cannot write, because it does not know
323
370
  who the reader can go and ask. Somebody read "Not set up yet" on this
@@ -358,6 +405,9 @@ import {
358
405
  UNVERIFIED_DETAIL,
359
406
  WALL_CAPABILITY_CONTROLS,
360
407
  WALL_LAYOUTS,
408
+ PLAYBACK_MINUTES,
409
+ playbackErrorMessage,
410
+ playbackWindow,
361
411
  type TWallCamera,
362
412
  type TWallCameraHealth,
363
413
  type TWallLayoutKey,
@@ -401,7 +451,7 @@ const props = defineProps<{ site: string }>();
401
451
 
402
452
  /* ---------------------------------------------------------------- the data */
403
453
 
404
- const { getSiteWall, getSiteHealth } = useSiteSettings();
454
+ const { getSiteWall, getSiteHealth, getCameraPlayback } = useSiteSettings();
405
455
 
406
456
  const cameras = ref<TWallCamera[]>([]);
407
457
  const loading = ref(true);
@@ -578,6 +628,43 @@ function togglePick(id: string) {
578
628
  */
579
629
  const focusedId = ref("");
580
630
  const focused = computed(() => focusedCamera(tiles.value, focusedId.value));
631
+ // A recording belongs to the camera it was opened for.
632
+ watch(() => focused.value?._id, stopRecording);
633
+
634
+ /* -------------------------------------------------------- recorded footage */
635
+
636
+ const playbackStart = ref("");
637
+ const playbackMinutes = ref<number>(10);
638
+ const playbackUrl = ref("");
639
+ const playbackError = ref("");
640
+ const playbackLoading = ref(false);
641
+
642
+ function stopRecording() {
643
+ playbackUrl.value = "";
644
+ playbackError.value = "";
645
+ }
646
+
647
+ async function playRecording() {
648
+ const camera = focused.value;
649
+ if (!camera) return;
650
+ const span = playbackWindow(playbackStart.value, playbackMinutes.value);
651
+ playbackUrl.value = "";
652
+ if ("error" in span) {
653
+ playbackError.value = span.error;
654
+ return;
655
+ }
656
+ playbackError.value = "";
657
+ playbackLoading.value = true;
658
+ try {
659
+ const link = await getCameraPlayback(camera._id, span.start, span.end);
660
+ // Still the same camera: a click elsewhere while this was loading wins.
661
+ if (focused.value?._id === camera._id) playbackUrl.value = link.playerUrl;
662
+ } catch (error) {
663
+ playbackError.value = playbackErrorMessage(error);
664
+ } finally {
665
+ playbackLoading.value = false;
666
+ }
667
+ }
581
668
 
582
669
  function capability(key: string) {
583
670
  return capabilityView(focused.value, key);
@@ -1156,6 +1243,78 @@ async function toggleFullscreen() {
1156
1243
  than filled, which is what says "not switched on"; the fade was saying it a
1157
1244
  second time at the cost of the words.
1158
1245
  */
1246
+ .vms__cap--wide {
1247
+ grid-column: 1 / -1;
1248
+ }
1249
+
1250
+ .vms__playback {
1251
+ margin-top: 8px;
1252
+ }
1253
+
1254
+ .vms__playback-form {
1255
+ display: flex;
1256
+ flex-wrap: wrap;
1257
+ align-items: flex-end;
1258
+ gap: 8px;
1259
+ }
1260
+
1261
+ .vms__playback-field {
1262
+ display: flex;
1263
+ flex-direction: column;
1264
+ gap: 2px;
1265
+ font-size: 12px;
1266
+ color: var(--vms-text-dim);
1267
+ }
1268
+
1269
+ .vms__playback-field input,
1270
+ .vms__playback-field select {
1271
+ min-height: 32px;
1272
+ padding: 4px 8px;
1273
+ border: 1px solid var(--vms-line);
1274
+ border-radius: var(--vms-radius);
1275
+ background: var(--vms-chrome);
1276
+ color: var(--vms-text);
1277
+ color-scheme: dark;
1278
+ font: inherit;
1279
+ }
1280
+
1281
+ .vms__playback-btn {
1282
+ min-height: 32px;
1283
+ padding: 4px 14px;
1284
+ border: 1px solid var(--vms-accent);
1285
+ border-radius: var(--vms-radius);
1286
+ background: var(--vms-accent);
1287
+ color: #07090c;
1288
+ font-weight: 600;
1289
+ cursor: pointer;
1290
+ }
1291
+
1292
+ .vms__playback-btn:disabled {
1293
+ opacity: 0.7;
1294
+ cursor: progress;
1295
+ }
1296
+
1297
+ .vms__playback-btn--quiet {
1298
+ background: transparent;
1299
+ color: var(--vms-text);
1300
+ }
1301
+
1302
+ .vms__playback-error {
1303
+ margin: 6px 0 0;
1304
+ font-size: 12px;
1305
+ color: #f2b8b5;
1306
+ }
1307
+
1308
+ .vms__playback-player {
1309
+ display: block;
1310
+ width: 100%;
1311
+ max-width: 960px;
1312
+ aspect-ratio: 16 / 9;
1313
+ margin-top: 8px;
1314
+ border: 0;
1315
+ background: #000;
1316
+ }
1317
+
1159
1318
  .vms__cap-detail {
1160
1319
  margin: 0;
1161
1320
  font-size: 12px;
@@ -519,6 +519,10 @@ export default function usePropertyPermission() {
519
519
  check: true,
520
520
  description: "Allows the user to view the site's CCTV cameras.",
521
521
  },
522
+ "view-recordings": {
523
+ check: true,
524
+ description: "Allows the user to watch what the site's CCTV cameras recorded.",
525
+ },
522
526
  },
523
527
  "nfc-patrol": {
524
528
  "see-all-nfc-patrol": {
@@ -706,6 +706,10 @@ export default function useSecurityPermission() {
706
706
  check: true,
707
707
  description: "Allows the user to view the site's CCTV cameras.",
708
708
  },
709
+ "view-recordings": {
710
+ check: true,
711
+ description: "Allows the user to watch what the site's CCTV cameras recorded.",
712
+ },
709
713
  },
710
714
 
711
715
  members: memberPermissions,
@@ -305,6 +305,24 @@ export default function () {
305
305
  * Unpaginated by design: a wall shows a site's cameras, and paging them was
306
306
  * an artefact of borrowing the CRUD list.
307
307
  */
308
+ /**
309
+ * A short-lived link to play one camera's recording for a past window
310
+ * (at most 30 minutes): `{ playerUrl, streamUrl, start, end, expiresAt }`.
311
+ * Site reach and `cctv-mgmt:view-recordings` are checked by the server.
312
+ */
313
+ async function getCameraPlayback(cameraId: string, start: string, end: string) {
314
+ return await useNuxtApp().$api<{
315
+ playerUrl: string;
316
+ streamUrl: string;
317
+ start: string;
318
+ end: string;
319
+ expiresAt: string;
320
+ }>(`/api/site-cameras/id/${cameraId}/playback`, {
321
+ method: "GET",
322
+ query: { start, end },
323
+ });
324
+ }
325
+
308
326
  async function getSiteWall(siteId: string) {
309
327
  return await useNuxtApp().$api<Record<string, any>>(
310
328
  `/api/site-cameras/site/${siteId}/wall`,
@@ -403,6 +421,7 @@ export default function () {
403
421
  }
404
422
 
405
423
  return {
424
+ getCameraPlayback,
406
425
  getSiteById,
407
426
  getSiteLevels,
408
427
  getSiteUnits,
@@ -332,7 +332,7 @@ export const PERMISSIONS = {
332
332
  ],
333
333
  // Owner answer Q9, 2026-09-11: seeing the CCTV wall. Distinct from
334
334
  // `site-settings:manage-cctv-camera`, which is camera setup.
335
- "cctv-mgmt": ["see-all-cctv"],
335
+ "cctv-mgmt": ["see-all-cctv", "view-recordings"],
336
336
  "billing-mgmt": [
337
337
  "see-all-billing-summary",
338
338
  "see-all-billing-items",
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.13.2",
5
+ "version": "4.14.0",
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.",
@@ -413,6 +413,8 @@ export const CAPABILITY_NEXT_STEPS: Record<string, string> = {
413
413
  "Not switchable from this page. This one moves real hardware, so a Seven365 backend lead has to approve it before it is turned on in the server's configuration.",
414
414
  "device-no-ptz":
415
415
  "This camera cannot move, so there is nothing to switch on. A different camera would be needed.",
416
+ "relay-playback-not-configured":
417
+ "Not switchable from this page. Recorded footage is turned on per video service in the server's configuration — your Seven365 administrator sets it up.",
416
418
  "no-recorder-configured":
417
419
  "Not switchable from this page. This camera's video service has no recorder linked to it in the server's configuration — your Seven365 administrator adds it.",
418
420
  "no-channel-in-address":
@@ -461,7 +463,7 @@ export const WALL_CAPABILITY_CONTROLS = [
461
463
  {
462
464
  key: "playback",
463
465
  title: "Recorded footage",
464
- ready: "This camera can serve recorded footage. The playback controls are not on this screen yet.",
466
+ ready: "Pick a date, a start time and how long, then press Play to watch what this camera recorded.",
465
467
  },
466
468
  {
467
469
  key: "events",
@@ -1044,3 +1046,47 @@ export function clampPan(
1044
1046
  export function zoomStep(scale: number, deltaY: number): number {
1045
1047
  return clampZoom(deltaY < 0 ? scale * 1.25 : scale / 1.25);
1046
1048
  }
1049
+
1050
+ /* ------------------------------------------------------- recorded footage */
1051
+
1052
+ /** The lengths a person can pick. The server allows at most 30 minutes. */
1053
+ export const PLAYBACK_MINUTES = [5, 10, 15, 30] as const;
1054
+
1055
+ /**
1056
+ * A `datetime-local` value (the viewer's own clock) plus a length, as the
1057
+ * window the server is asked for — or the sentence saying why not.
1058
+ */
1059
+ export function playbackWindow(
1060
+ localStart: string,
1061
+ minutes: number,
1062
+ now: Date = new Date()
1063
+ ): { start: string; end: string } | { error: string } {
1064
+ const start = localStart ? new Date(localStart) : null;
1065
+ if (!start || Number.isNaN(start.getTime())) {
1066
+ return { error: "Pick the date and time to start from." };
1067
+ }
1068
+ if (!PLAYBACK_MINUTES.includes(minutes as (typeof PLAYBACK_MINUTES)[number])) {
1069
+ return { error: "Pick how long to watch." };
1070
+ }
1071
+ const end = new Date(start.getTime() + minutes * 60_000);
1072
+ if (end.getTime() > now.getTime()) {
1073
+ return {
1074
+ error: "That time has not finished recording yet. Pick an earlier start, or a shorter length.",
1075
+ };
1076
+ }
1077
+ return { start: start.toISOString(), end: end.toISOString() };
1078
+ }
1079
+
1080
+ /** What to tell the person when the server refuses a recording. */
1081
+ export function playbackErrorMessage(error: unknown): string {
1082
+ const e = error as { statusCode?: number; status?: number; data?: { message?: string } } | null;
1083
+ const status = e?.statusCode ?? e?.status ?? 0;
1084
+ const said = e?.data?.message?.trim();
1085
+ if (status === 401) return "Your session has ended. Sign in again to watch recorded footage.";
1086
+ if (status === 403) return said || "You do not have permission to watch recorded footage.";
1087
+ if (status === 404) return "This camera is not available to you.";
1088
+ if (status === 409) return said || "Recorded footage is not set up for this camera yet.";
1089
+ if (status === 429) return "Too many requests. Wait a minute and try again.";
1090
+ if (status === 400 && said) return said;
1091
+ return "The recording could not be opened. Try again in a moment.";
1092
+ }