@blueharford/scrypted-spatial-awareness 0.1.10 → 0.1.14
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/dist/main.nodejs.js +1 -1
- package/dist/main.nodejs.js.map +1 -1
- package/dist/plugin.zip +0 -0
- package/out/main.nodejs.js +996 -90
- package/out/main.nodejs.js.map +1 -1
- package/out/plugin.zip +0 -0
- package/package.json +1 -1
- package/src/alerts/alert-manager.ts +25 -8
- package/src/core/tracking-engine.ts +15 -1
- package/src/main.ts +128 -30
- package/src/models/alert.ts +31 -4
package/out/main.nodejs.js
CHANGED
|
@@ -34350,14 +34350,44 @@ function socketOnError() {
|
|
|
34350
34350
|
* Alert Manager
|
|
34351
34351
|
* Generates and dispatches alerts based on tracking events
|
|
34352
34352
|
*/
|
|
34353
|
-
var
|
|
34354
|
-
|
|
34355
|
-
|
|
34353
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
34354
|
+
if (k2 === undefined) k2 = k;
|
|
34355
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
34356
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34357
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34358
|
+
}
|
|
34359
|
+
Object.defineProperty(o, k2, desc);
|
|
34360
|
+
}) : (function(o, m, k, k2) {
|
|
34361
|
+
if (k2 === undefined) k2 = k;
|
|
34362
|
+
o[k2] = m[k];
|
|
34363
|
+
}));
|
|
34364
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34365
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
34366
|
+
}) : function(o, v) {
|
|
34367
|
+
o["default"] = v;
|
|
34368
|
+
});
|
|
34369
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34370
|
+
var ownKeys = function(o) {
|
|
34371
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34372
|
+
var ar = [];
|
|
34373
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34374
|
+
return ar;
|
|
34375
|
+
};
|
|
34376
|
+
return ownKeys(o);
|
|
34377
|
+
};
|
|
34378
|
+
return function (mod) {
|
|
34379
|
+
if (mod && mod.__esModule) return mod;
|
|
34380
|
+
var result = {};
|
|
34381
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34382
|
+
__setModuleDefault(result, mod);
|
|
34383
|
+
return result;
|
|
34384
|
+
};
|
|
34385
|
+
})();
|
|
34356
34386
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
34357
34387
|
exports.AlertManager = void 0;
|
|
34358
|
-
const sdk_1 =
|
|
34388
|
+
const sdk_1 = __importStar(__webpack_require__(/*! @scrypted/sdk */ "./node_modules/@scrypted/sdk/dist/src/index.js"));
|
|
34359
34389
|
const alert_1 = __webpack_require__(/*! ../models/alert */ "./src/models/alert.ts");
|
|
34360
|
-
const { systemManager } = sdk_1.default;
|
|
34390
|
+
const { systemManager, mediaManager } = sdk_1.default;
|
|
34361
34391
|
class AlertManager {
|
|
34362
34392
|
rules = [];
|
|
34363
34393
|
recentAlerts = [];
|
|
@@ -34426,6 +34456,20 @@ class AlertManager {
|
|
|
34426
34456
|
const notifierIds = rule.notifiers.length > 0
|
|
34427
34457
|
? rule.notifiers
|
|
34428
34458
|
: this.getDefaultNotifiers();
|
|
34459
|
+
// Try to get a thumbnail from the camera
|
|
34460
|
+
let mediaObject;
|
|
34461
|
+
const cameraId = alert.details.toCameraId || alert.details.cameraId;
|
|
34462
|
+
if (cameraId) {
|
|
34463
|
+
try {
|
|
34464
|
+
const camera = systemManager.getDeviceById(cameraId);
|
|
34465
|
+
if (camera && camera.interfaces?.includes(sdk_1.ScryptedInterface.Camera)) {
|
|
34466
|
+
mediaObject = await camera.takePicture();
|
|
34467
|
+
}
|
|
34468
|
+
}
|
|
34469
|
+
catch (e) {
|
|
34470
|
+
this.console.warn(`Failed to get thumbnail from camera ${cameraId}:`, e);
|
|
34471
|
+
}
|
|
34472
|
+
}
|
|
34429
34473
|
for (const notifierId of notifierIds) {
|
|
34430
34474
|
try {
|
|
34431
34475
|
const notifier = systemManager.getDeviceById(notifierId);
|
|
@@ -34441,8 +34485,8 @@ class AlertManager {
|
|
|
34441
34485
|
trackedObjectId: alert.trackedObjectId,
|
|
34442
34486
|
timestamp: alert.timestamp,
|
|
34443
34487
|
},
|
|
34444
|
-
});
|
|
34445
|
-
this.console.log(`Notification sent to ${notifierId}`);
|
|
34488
|
+
}, mediaObject);
|
|
34489
|
+
this.console.log(`Notification sent to ${notifierId}${mediaObject ? ' with thumbnail' : ''}`);
|
|
34446
34490
|
}
|
|
34447
34491
|
catch (e) {
|
|
34448
34492
|
this.console.error(`Failed to send notification to ${notifierId}:`, e);
|
|
@@ -34454,16 +34498,18 @@ class AlertManager {
|
|
|
34454
34498
|
*/
|
|
34455
34499
|
getNotificationTitle(alert) {
|
|
34456
34500
|
const prefix = alert.severity === 'critical' ? '🚨 ' :
|
|
34457
|
-
alert.severity === 'warning' ? '⚠️ ' : '
|
|
34501
|
+
alert.severity === 'warning' ? '⚠️ ' : '';
|
|
34458
34502
|
switch (alert.type) {
|
|
34459
34503
|
case 'property_entry':
|
|
34460
|
-
return `${prefix}Entry Detected`;
|
|
34504
|
+
return `${prefix}🚶 Entry Detected`;
|
|
34461
34505
|
case 'property_exit':
|
|
34462
|
-
return `${prefix}Exit Detected`;
|
|
34506
|
+
return `${prefix}🚶 Exit Detected`;
|
|
34507
|
+
case 'movement':
|
|
34508
|
+
return `${prefix}🚶 Movement Detected`;
|
|
34463
34509
|
case 'unusual_path':
|
|
34464
34510
|
return `${prefix}Unusual Path`;
|
|
34465
34511
|
case 'dwell_time':
|
|
34466
|
-
return `${prefix}Extended Presence`;
|
|
34512
|
+
return `${prefix}⏱️ Extended Presence`;
|
|
34467
34513
|
case 'restricted_zone':
|
|
34468
34514
|
return `${prefix}Restricted Zone Alert`;
|
|
34469
34515
|
case 'lost_tracking':
|
|
@@ -35117,6 +35163,7 @@ class TrackingEngine {
|
|
|
35117
35163
|
// Check if this is a cross-camera transition
|
|
35118
35164
|
const lastSighting = (0, tracked_object_1.getLastSighting)(tracked);
|
|
35119
35165
|
if (lastSighting && lastSighting.cameraId !== sighting.cameraId) {
|
|
35166
|
+
const transitDuration = sighting.timestamp - lastSighting.timestamp;
|
|
35120
35167
|
// Add journey segment
|
|
35121
35168
|
this.state.addJourney(tracked.globalId, {
|
|
35122
35169
|
fromCameraId: lastSighting.cameraId,
|
|
@@ -35125,12 +35172,23 @@ class TrackingEngine {
|
|
|
35125
35172
|
toCameraName: sighting.cameraName,
|
|
35126
35173
|
exitTime: lastSighting.timestamp,
|
|
35127
35174
|
entryTime: sighting.timestamp,
|
|
35128
|
-
transitDuration
|
|
35175
|
+
transitDuration,
|
|
35129
35176
|
correlationConfidence: correlation.confidence,
|
|
35130
35177
|
});
|
|
35131
35178
|
this.console.log(`Object ${tracked.globalId.slice(0, 8)} transited: ` +
|
|
35132
35179
|
`${lastSighting.cameraName} → ${sighting.cameraName} ` +
|
|
35133
35180
|
`(confidence: ${(correlation.confidence * 100).toFixed(0)}%)`);
|
|
35181
|
+
// Generate movement alert for cross-camera transition
|
|
35182
|
+
await this.alertManager.checkAndAlert('movement', tracked, {
|
|
35183
|
+
fromCameraId: lastSighting.cameraId,
|
|
35184
|
+
fromCameraName: lastSighting.cameraName,
|
|
35185
|
+
toCameraId: sighting.cameraId,
|
|
35186
|
+
toCameraName: sighting.cameraName,
|
|
35187
|
+
transitTime: transitDuration,
|
|
35188
|
+
objectClass: sighting.detection.className,
|
|
35189
|
+
objectLabel: sighting.detection.label,
|
|
35190
|
+
detectionId: sighting.detectionId,
|
|
35191
|
+
});
|
|
35134
35192
|
}
|
|
35135
35193
|
// Add sighting to tracked object
|
|
35136
35194
|
this.state.addSighting(tracked.globalId, sighting);
|
|
@@ -35915,7 +35973,6 @@ exports.MqttPublisher = MqttPublisher;
|
|
|
35915
35973
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
35916
35974
|
|
|
35917
35975
|
"use strict";
|
|
35918
|
-
var __webpack_dirname__ = "src";
|
|
35919
35976
|
|
|
35920
35977
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
35921
35978
|
if (k2 === undefined) k2 = k;
|
|
@@ -35962,8 +36019,7 @@ const alert_manager_1 = __webpack_require__(/*! ./alerts/alert-manager */ "./src
|
|
|
35962
36019
|
const global_tracker_sensor_1 = __webpack_require__(/*! ./devices/global-tracker-sensor */ "./src/devices/global-tracker-sensor.ts");
|
|
35963
36020
|
const tracking_zone_1 = __webpack_require__(/*! ./devices/tracking-zone */ "./src/devices/tracking-zone.ts");
|
|
35964
36021
|
const mqtt_publisher_1 = __webpack_require__(/*! ./integrations/mqtt-publisher */ "./src/integrations/mqtt-publisher.ts");
|
|
35965
|
-
const
|
|
35966
|
-
const path = __importStar(__webpack_require__(/*! path */ "path"));
|
|
36022
|
+
const editor_html_1 = __webpack_require__(/*! ./ui/editor-html */ "./src/ui/editor-html.ts");
|
|
35967
36023
|
const { deviceManager, systemManager } = sdk_1.default;
|
|
35968
36024
|
const TRACKING_ZONE_PREFIX = 'tracking-zone:';
|
|
35969
36025
|
const GLOBAL_TRACKER_ID = 'global-tracker';
|
|
@@ -36227,24 +36283,82 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36227
36283
|
// ==================== Settings Implementation ====================
|
|
36228
36284
|
async getSettings() {
|
|
36229
36285
|
const settings = await this.storageSettings.getSettings();
|
|
36230
|
-
//
|
|
36286
|
+
// Topology editor button that opens modal overlay (appended to body for proper z-index)
|
|
36287
|
+
const onclickCode = `(function(){var e=document.getElementById('sa-topology-modal');if(e)e.remove();var m=document.createElement('div');m.id='sa-topology-modal';m.style.cssText='position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.9);z-index:2147483647;display:flex;align-items:center;justify-content:center;';var c=document.createElement('div');c.style.cssText='width:95vw;height:92vh;max-width:1800px;background:#1a1a2e;border-radius:12px;overflow:hidden;position:relative;box-shadow:0 25px 50px rgba(0,0,0,0.5);';var b=document.createElement('button');b.innerHTML='×';b.style.cssText='position:absolute;top:15px;right:15px;z-index:2147483647;background:#e94560;color:white;border:none;width:40px;height:40px;border-radius:50%;font-size:24px;cursor:pointer;';b.onclick=function(){m.remove();};var f=document.createElement('iframe');f.src='/endpoint/@blueharford/scrypted-spatial-awareness/ui/editor';f.style.cssText='width:100%;height:100%;border:none;';c.appendChild(b);c.appendChild(f);m.appendChild(c);m.onclick=function(ev){if(ev.target===m)m.remove();};document.body.appendChild(m);})()`;
|
|
36231
36288
|
settings.push({
|
|
36232
|
-
key: '
|
|
36233
|
-
title: '
|
|
36234
|
-
type: '
|
|
36235
|
-
|
|
36236
|
-
|
|
36289
|
+
key: 'topologyEditor',
|
|
36290
|
+
title: 'Topology Editor',
|
|
36291
|
+
type: 'html',
|
|
36292
|
+
value: `
|
|
36293
|
+
<style>
|
|
36294
|
+
.sa-open-btn {
|
|
36295
|
+
background: linear-gradient(135deg, #e94560 0%, #0f3460 100%);
|
|
36296
|
+
color: white;
|
|
36297
|
+
border: none;
|
|
36298
|
+
padding: 14px 28px;
|
|
36299
|
+
border-radius: 8px;
|
|
36300
|
+
font-size: 15px;
|
|
36301
|
+
font-weight: 600;
|
|
36302
|
+
cursor: pointer;
|
|
36303
|
+
display: inline-flex;
|
|
36304
|
+
align-items: center;
|
|
36305
|
+
gap: 10px;
|
|
36306
|
+
transition: transform 0.2s, box-shadow 0.2s;
|
|
36307
|
+
}
|
|
36308
|
+
.sa-open-btn:hover {
|
|
36309
|
+
transform: translateY(-2px);
|
|
36310
|
+
box-shadow: 0 8px 20px rgba(233, 69, 96, 0.4);
|
|
36311
|
+
}
|
|
36312
|
+
.sa-btn-container {
|
|
36313
|
+
padding: 20px;
|
|
36314
|
+
background: #16213e;
|
|
36315
|
+
border-radius: 8px;
|
|
36316
|
+
text-align: center;
|
|
36317
|
+
}
|
|
36318
|
+
.sa-btn-desc {
|
|
36319
|
+
color: #888;
|
|
36320
|
+
margin-bottom: 15px;
|
|
36321
|
+
font-size: 14px;
|
|
36322
|
+
}
|
|
36323
|
+
</style>
|
|
36324
|
+
<div class="sa-btn-container">
|
|
36325
|
+
<p class="sa-btn-desc">Configure camera positions, connections, and transit times</p>
|
|
36326
|
+
<button class="sa-open-btn" onclick="${onclickCode}">
|
|
36327
|
+
<span>⚙</span> Open Topology Editor
|
|
36328
|
+
</button>
|
|
36329
|
+
</div>
|
|
36330
|
+
`,
|
|
36331
|
+
group: 'Topology',
|
|
36237
36332
|
});
|
|
36238
36333
|
// Add status display
|
|
36239
36334
|
const activeCount = this.trackingState.getActiveCount();
|
|
36335
|
+
const topologyJson = this.storage.getItem('topology');
|
|
36336
|
+
let statusText = 'Not configured - add cameras and configure topology';
|
|
36337
|
+
if (this.trackingEngine) {
|
|
36338
|
+
statusText = `Active: Tracking ${activeCount} object${activeCount !== 1 ? 's' : ''}`;
|
|
36339
|
+
}
|
|
36340
|
+
else if (topologyJson) {
|
|
36341
|
+
try {
|
|
36342
|
+
const topology = JSON.parse(topologyJson);
|
|
36343
|
+
if (topology.cameras && topology.cameras.length > 0) {
|
|
36344
|
+
// Topology exists but engine not running - try to start it
|
|
36345
|
+
statusText = `Configured (${topology.cameras.length} cameras) - Starting...`;
|
|
36346
|
+
// Restart the tracking engine asynchronously
|
|
36347
|
+
this.startTrackingEngine(topology).catch(e => {
|
|
36348
|
+
this.console.error('Failed to restart tracking engine:', e);
|
|
36349
|
+
});
|
|
36350
|
+
}
|
|
36351
|
+
}
|
|
36352
|
+
catch (e) {
|
|
36353
|
+
statusText = 'Error loading topology';
|
|
36354
|
+
}
|
|
36355
|
+
}
|
|
36240
36356
|
settings.push({
|
|
36241
36357
|
key: 'status',
|
|
36242
36358
|
title: 'Tracking Status',
|
|
36243
36359
|
type: 'string',
|
|
36244
36360
|
readonly: true,
|
|
36245
|
-
value:
|
|
36246
|
-
? `Active: Tracking ${activeCount} object${activeCount !== 1 ? 's' : ''}`
|
|
36247
|
-
: 'Not configured - add cameras and configure topology',
|
|
36361
|
+
value: statusText,
|
|
36248
36362
|
group: 'Status',
|
|
36249
36363
|
});
|
|
36250
36364
|
// Add recent alerts summary
|
|
@@ -36259,14 +36373,77 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36259
36373
|
group: 'Status',
|
|
36260
36374
|
});
|
|
36261
36375
|
}
|
|
36376
|
+
// Add alert rules configuration UI
|
|
36377
|
+
const alertRules = this.alertManager.getRules();
|
|
36378
|
+
const rulesHtml = this.generateAlertRulesHtml(alertRules);
|
|
36379
|
+
settings.push({
|
|
36380
|
+
key: 'alertRulesEditor',
|
|
36381
|
+
title: 'Alert Rules',
|
|
36382
|
+
type: 'html',
|
|
36383
|
+
value: rulesHtml,
|
|
36384
|
+
group: 'Alerts',
|
|
36385
|
+
});
|
|
36262
36386
|
return settings;
|
|
36263
36387
|
}
|
|
36388
|
+
generateAlertRulesHtml(rules) {
|
|
36389
|
+
const ruleRows = rules.map(rule => `
|
|
36390
|
+
<tr data-rule-id="${rule.id}">
|
|
36391
|
+
<td style="padding:8px;border-bottom:1px solid #333;">
|
|
36392
|
+
<input type="checkbox" ${rule.enabled ? 'checked' : ''}
|
|
36393
|
+
onchange="(function(el){var rules=JSON.parse(localStorage.getItem('sa-temp-rules')||'[]');var r=rules.find(x=>x.id==='${rule.id}');if(r)r.enabled=el.checked;localStorage.setItem('sa-temp-rules',JSON.stringify(rules));})(this)" />
|
|
36394
|
+
</td>
|
|
36395
|
+
<td style="padding:8px;border-bottom:1px solid #333;color:#fff;">${rule.name}</td>
|
|
36396
|
+
<td style="padding:8px;border-bottom:1px solid #333;color:#888;">${rule.type}</td>
|
|
36397
|
+
<td style="padding:8px;border-bottom:1px solid #333;">
|
|
36398
|
+
<span style="padding:2px 8px;border-radius:4px;font-size:12px;background:${rule.severity === 'critical' ? '#e94560' :
|
|
36399
|
+
rule.severity === 'warning' ? '#f39c12' : '#3498db'};color:white;">${rule.severity}</span>
|
|
36400
|
+
</td>
|
|
36401
|
+
<td style="padding:8px;border-bottom:1px solid #333;color:#888;">${Math.round(rule.cooldown / 1000)}s</td>
|
|
36402
|
+
</tr>
|
|
36403
|
+
`).join('');
|
|
36404
|
+
const initCode = `localStorage.setItem('sa-temp-rules',JSON.stringify(${JSON.stringify(rules)}))`;
|
|
36405
|
+
const saveCode = `(function(){var rules=JSON.parse(localStorage.getItem('sa-temp-rules')||'[]');fetch('/endpoint/@blueharford/scrypted-spatial-awareness/api/alert-rules',{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify(rules)}).then(r=>r.json()).then(d=>{if(d.success)alert('Alert rules saved!');else alert('Error: '+d.error);}).catch(e=>alert('Error: '+e));})()`;
|
|
36406
|
+
return `
|
|
36407
|
+
<style>
|
|
36408
|
+
.sa-rules-table { width:100%; border-collapse:collapse; margin-top:10px; }
|
|
36409
|
+
.sa-rules-table th { text-align:left; padding:10px 8px; border-bottom:2px solid #e94560; color:#e94560; font-size:13px; }
|
|
36410
|
+
.sa-save-rules-btn {
|
|
36411
|
+
background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
|
|
36412
|
+
color: white;
|
|
36413
|
+
border: none;
|
|
36414
|
+
padding: 10px 20px;
|
|
36415
|
+
border-radius: 6px;
|
|
36416
|
+
font-size: 14px;
|
|
36417
|
+
font-weight: 600;
|
|
36418
|
+
cursor: pointer;
|
|
36419
|
+
margin-top: 15px;
|
|
36420
|
+
}
|
|
36421
|
+
.sa-save-rules-btn:hover { opacity: 0.9; }
|
|
36422
|
+
.sa-rules-container { background:#16213e; border-radius:8px; padding:15px; }
|
|
36423
|
+
.sa-rules-desc { color:#888; font-size:13px; margin-bottom:10px; }
|
|
36424
|
+
</style>
|
|
36425
|
+
<div class="sa-rules-container">
|
|
36426
|
+
<p class="sa-rules-desc">Enable or disable alert types. Movement alerts notify you when someone moves between cameras.</p>
|
|
36427
|
+
<table class="sa-rules-table">
|
|
36428
|
+
<thead>
|
|
36429
|
+
<tr>
|
|
36430
|
+
<th style="width:40px;">On</th>
|
|
36431
|
+
<th>Alert Type</th>
|
|
36432
|
+
<th>Event</th>
|
|
36433
|
+
<th>Severity</th>
|
|
36434
|
+
<th>Cooldown</th>
|
|
36435
|
+
</tr>
|
|
36436
|
+
</thead>
|
|
36437
|
+
<tbody>
|
|
36438
|
+
${ruleRows}
|
|
36439
|
+
</tbody>
|
|
36440
|
+
</table>
|
|
36441
|
+
<button class="sa-save-rules-btn" onclick="${saveCode}">Save Alert Rules</button>
|
|
36442
|
+
<script>(function(){${initCode}})();</script>
|
|
36443
|
+
</div>
|
|
36444
|
+
`;
|
|
36445
|
+
}
|
|
36264
36446
|
async putSetting(key, value) {
|
|
36265
|
-
if (key === 'openTopologyEditor') {
|
|
36266
|
-
// The UI will handle opening the editor via HTTP
|
|
36267
|
-
this.console.log('Topology editor requested - access via plugin HTTP endpoint');
|
|
36268
|
-
return;
|
|
36269
|
-
}
|
|
36270
36447
|
await this.storageSettings.putSetting(key, value);
|
|
36271
36448
|
// Handle setting changes that require engine restart
|
|
36272
36449
|
if (key === 'trackedCameras' ||
|
|
@@ -36311,11 +36488,17 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36311
36488
|
return this.handleJourneyRequest(globalId, response);
|
|
36312
36489
|
}
|
|
36313
36490
|
if (path.endsWith('/api/topology')) {
|
|
36314
|
-
return this.handleTopologyRequest(request, response);
|
|
36491
|
+
return await this.handleTopologyRequest(request, response);
|
|
36315
36492
|
}
|
|
36316
36493
|
if (path.endsWith('/api/alerts')) {
|
|
36317
36494
|
return this.handleAlertsRequest(request, response);
|
|
36318
36495
|
}
|
|
36496
|
+
if (path.endsWith('/api/alert-rules')) {
|
|
36497
|
+
return this.handleAlertRulesRequest(request, response);
|
|
36498
|
+
}
|
|
36499
|
+
if (path.endsWith('/api/cameras')) {
|
|
36500
|
+
return this.handleCamerasRequest(response);
|
|
36501
|
+
}
|
|
36319
36502
|
if (path.endsWith('/api/floor-plan')) {
|
|
36320
36503
|
return this.handleFloorPlanRequest(request, response);
|
|
36321
36504
|
}
|
|
@@ -36387,7 +36570,7 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36387
36570
|
});
|
|
36388
36571
|
}
|
|
36389
36572
|
}
|
|
36390
|
-
handleTopologyRequest(request, response) {
|
|
36573
|
+
async handleTopologyRequest(request, response) {
|
|
36391
36574
|
if (request.method === 'GET') {
|
|
36392
36575
|
const topologyJson = this.storage.getItem('topology');
|
|
36393
36576
|
const topology = topologyJson ? JSON.parse(topologyJson) : (0, topology_1.createEmptyTopology)();
|
|
@@ -36399,7 +36582,7 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36399
36582
|
try {
|
|
36400
36583
|
const topology = JSON.parse(request.body);
|
|
36401
36584
|
this.storage.setItem('topology', JSON.stringify(topology));
|
|
36402
|
-
this.startTrackingEngine(topology);
|
|
36585
|
+
await this.startTrackingEngine(topology);
|
|
36403
36586
|
response.send(JSON.stringify({ success: true }), {
|
|
36404
36587
|
headers: { 'Content-Type': 'application/json' },
|
|
36405
36588
|
});
|
|
@@ -36418,6 +36601,58 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36418
36601
|
headers: { 'Content-Type': 'application/json' },
|
|
36419
36602
|
});
|
|
36420
36603
|
}
|
|
36604
|
+
handleAlertRulesRequest(request, response) {
|
|
36605
|
+
if (request.method === 'GET') {
|
|
36606
|
+
const rules = this.alertManager.getRules();
|
|
36607
|
+
response.send(JSON.stringify(rules), {
|
|
36608
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36609
|
+
});
|
|
36610
|
+
}
|
|
36611
|
+
else if (request.method === 'PUT' || request.method === 'POST') {
|
|
36612
|
+
try {
|
|
36613
|
+
const rules = JSON.parse(request.body);
|
|
36614
|
+
this.alertManager.setRules(rules);
|
|
36615
|
+
response.send(JSON.stringify({ success: true }), {
|
|
36616
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36617
|
+
});
|
|
36618
|
+
}
|
|
36619
|
+
catch (e) {
|
|
36620
|
+
response.send(JSON.stringify({ error: 'Invalid rules JSON' }), {
|
|
36621
|
+
code: 400,
|
|
36622
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36623
|
+
});
|
|
36624
|
+
}
|
|
36625
|
+
}
|
|
36626
|
+
}
|
|
36627
|
+
handleCamerasRequest(response) {
|
|
36628
|
+
try {
|
|
36629
|
+
// Get all devices with ObjectDetector interface
|
|
36630
|
+
const cameras = [];
|
|
36631
|
+
for (const id of Object.keys(systemManager.getSystemState())) {
|
|
36632
|
+
try {
|
|
36633
|
+
const device = systemManager.getDeviceById(id);
|
|
36634
|
+
if (device && device.interfaces?.includes(sdk_1.ScryptedInterface.ObjectDetector)) {
|
|
36635
|
+
cameras.push({
|
|
36636
|
+
id: id,
|
|
36637
|
+
name: device.name || `Camera ${id}`,
|
|
36638
|
+
});
|
|
36639
|
+
}
|
|
36640
|
+
}
|
|
36641
|
+
catch (e) {
|
|
36642
|
+
// Skip devices that can't be accessed
|
|
36643
|
+
}
|
|
36644
|
+
}
|
|
36645
|
+
response.send(JSON.stringify(cameras), {
|
|
36646
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36647
|
+
});
|
|
36648
|
+
}
|
|
36649
|
+
catch (e) {
|
|
36650
|
+
this.console.error('Error getting cameras:', e);
|
|
36651
|
+
response.send(JSON.stringify([]), {
|
|
36652
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36653
|
+
});
|
|
36654
|
+
}
|
|
36655
|
+
}
|
|
36421
36656
|
handleFloorPlanRequest(request, response) {
|
|
36422
36657
|
if (request.method === 'GET') {
|
|
36423
36658
|
const imageData = this.storage.getItem('floorPlanImage');
|
|
@@ -36449,49 +36684,9 @@ class SpatialAwarenessPlugin extends sdk_1.ScryptedDeviceBase {
|
|
|
36449
36684
|
}
|
|
36450
36685
|
}
|
|
36451
36686
|
serveEditorUI(response) {
|
|
36452
|
-
|
|
36453
|
-
|
|
36454
|
-
|
|
36455
|
-
const html = fs.readFileSync(editorPath, 'utf-8');
|
|
36456
|
-
response.send(html, {
|
|
36457
|
-
headers: { 'Content-Type': 'text/html' },
|
|
36458
|
-
});
|
|
36459
|
-
}
|
|
36460
|
-
catch (e) {
|
|
36461
|
-
this.console.error('Failed to load editor UI:', e);
|
|
36462
|
-
// Fallback to basic UI
|
|
36463
|
-
const html = `
|
|
36464
|
-
<!DOCTYPE html>
|
|
36465
|
-
<html>
|
|
36466
|
-
<head>
|
|
36467
|
-
<title>Spatial Awareness - Topology Editor</title>
|
|
36468
|
-
<meta charset="utf-8">
|
|
36469
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
36470
|
-
<style>
|
|
36471
|
-
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 0; padding: 20px; background: #1a1a1a; color: #fff; }
|
|
36472
|
-
h1 { margin-top: 0; }
|
|
36473
|
-
.container { max-width: 1200px; margin: 0 auto; }
|
|
36474
|
-
.btn { background: #0066cc; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 14px; }
|
|
36475
|
-
</style>
|
|
36476
|
-
</head>
|
|
36477
|
-
<body>
|
|
36478
|
-
<div class="container">
|
|
36479
|
-
<h1>Spatial Awareness - Topology Editor</h1>
|
|
36480
|
-
<p>Error loading visual editor. Configure topology via REST API: <code>PUT /api/topology</code></p>
|
|
36481
|
-
<h3>Current Topology</h3>
|
|
36482
|
-
<pre id="topology-json" style="background: #2a2a2a; padding: 15px; border-radius: 4px; overflow: auto;"></pre>
|
|
36483
|
-
</div>
|
|
36484
|
-
<script>
|
|
36485
|
-
fetch('api/topology').then(r => r.json()).then(data => {
|
|
36486
|
-
document.getElementById('topology-json').textContent = JSON.stringify(data, null, 2);
|
|
36487
|
-
});
|
|
36488
|
-
</script>
|
|
36489
|
-
</body>
|
|
36490
|
-
</html>`;
|
|
36491
|
-
response.send(html, {
|
|
36492
|
-
headers: { 'Content-Type': 'text/html' },
|
|
36493
|
-
});
|
|
36494
|
-
}
|
|
36687
|
+
response.send(editor_html_1.EDITOR_HTML, {
|
|
36688
|
+
headers: { 'Content-Type': 'text/html' },
|
|
36689
|
+
});
|
|
36495
36690
|
}
|
|
36496
36691
|
serveStaticFile(path, response) {
|
|
36497
36692
|
// Serve static files for the UI
|
|
@@ -36587,7 +36782,7 @@ function createDefaultRules() {
|
|
|
36587
36782
|
conditions: [],
|
|
36588
36783
|
severity: 'info',
|
|
36589
36784
|
notifiers: [],
|
|
36590
|
-
cooldown:
|
|
36785
|
+
cooldown: 60000, // 1 minute
|
|
36591
36786
|
},
|
|
36592
36787
|
{
|
|
36593
36788
|
id: 'property-exit',
|
|
@@ -36597,7 +36792,17 @@ function createDefaultRules() {
|
|
|
36597
36792
|
conditions: [],
|
|
36598
36793
|
severity: 'info',
|
|
36599
36794
|
notifiers: [],
|
|
36600
|
-
cooldown:
|
|
36795
|
+
cooldown: 60000,
|
|
36796
|
+
},
|
|
36797
|
+
{
|
|
36798
|
+
id: 'movement',
|
|
36799
|
+
name: 'Movement Between Cameras',
|
|
36800
|
+
enabled: true,
|
|
36801
|
+
type: 'movement',
|
|
36802
|
+
conditions: [],
|
|
36803
|
+
severity: 'info',
|
|
36804
|
+
notifiers: [],
|
|
36805
|
+
cooldown: 10000, // 10 seconds - we want frequent movement updates
|
|
36601
36806
|
},
|
|
36602
36807
|
{
|
|
36603
36808
|
id: 'unusual-path',
|
|
@@ -36645,14 +36850,20 @@ function createDefaultRules() {
|
|
|
36645
36850
|
}
|
|
36646
36851
|
/** Generates a human-readable message for an alert */
|
|
36647
36852
|
function generateAlertMessage(type, details) {
|
|
36853
|
+
// Capitalize the object class for display (person -> Person, car -> Car, dog -> Dog)
|
|
36854
|
+
const capitalize = (s) => s ? s.charAt(0).toUpperCase() + s.slice(1) : 'Object';
|
|
36648
36855
|
const objectDesc = details.objectLabel
|
|
36649
|
-
? `${details.objectClass} (${details.objectLabel})`
|
|
36650
|
-
: details.objectClass || '
|
|
36856
|
+
? `${capitalize(details.objectClass || '')} (${details.objectLabel})`
|
|
36857
|
+
: capitalize(details.objectClass || '');
|
|
36651
36858
|
switch (type) {
|
|
36652
36859
|
case 'property_entry':
|
|
36653
36860
|
return `${objectDesc} entered property via ${details.cameraName || 'unknown camera'}`;
|
|
36654
36861
|
case 'property_exit':
|
|
36655
36862
|
return `${objectDesc} exited property via ${details.cameraName || 'unknown camera'}`;
|
|
36863
|
+
case 'movement':
|
|
36864
|
+
const transitSecs = details.transitTime ? Math.round(details.transitTime / 1000) : 0;
|
|
36865
|
+
const transitStr = transitSecs > 0 ? ` (${transitSecs}s transit)` : '';
|
|
36866
|
+
return `${objectDesc} moving from ${details.fromCameraName || 'unknown'} towards ${details.toCameraName || 'unknown'}${transitStr}`;
|
|
36656
36867
|
case 'unusual_path':
|
|
36657
36868
|
return `${objectDesc} took unusual path: ${details.actualPath || 'unknown'}`;
|
|
36658
36869
|
case 'dwell_time':
|
|
@@ -37098,6 +37309,712 @@ class TrackingState {
|
|
|
37098
37309
|
exports.TrackingState = TrackingState;
|
|
37099
37310
|
|
|
37100
37311
|
|
|
37312
|
+
/***/ },
|
|
37313
|
+
|
|
37314
|
+
/***/ "./src/ui/editor-html.ts"
|
|
37315
|
+
/*!*******************************!*\
|
|
37316
|
+
!*** ./src/ui/editor-html.ts ***!
|
|
37317
|
+
\*******************************/
|
|
37318
|
+
(__unused_webpack_module, exports) {
|
|
37319
|
+
|
|
37320
|
+
"use strict";
|
|
37321
|
+
|
|
37322
|
+
/**
|
|
37323
|
+
* Editor HTML embedded as a string for bundling
|
|
37324
|
+
*/
|
|
37325
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
37326
|
+
exports.EDITOR_HTML = void 0;
|
|
37327
|
+
exports.EDITOR_HTML = `<!DOCTYPE html>
|
|
37328
|
+
<html lang="en">
|
|
37329
|
+
<head>
|
|
37330
|
+
<meta charset="UTF-8">
|
|
37331
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
37332
|
+
<title>Spatial Awareness - Topology Editor</title>
|
|
37333
|
+
<style>
|
|
37334
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
37335
|
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif; background: #1a1a2e; color: #eee; min-height: 100vh; }
|
|
37336
|
+
.container { display: flex; height: 100vh; }
|
|
37337
|
+
.sidebar { width: 300px; background: #16213e; border-right: 1px solid #0f3460; display: flex; flex-direction: column; overflow: hidden; }
|
|
37338
|
+
.sidebar-header { padding: 20px; border-bottom: 1px solid #0f3460; }
|
|
37339
|
+
.sidebar-header h1 { font-size: 18px; font-weight: 600; margin-bottom: 5px; }
|
|
37340
|
+
.sidebar-header p { font-size: 12px; color: #888; }
|
|
37341
|
+
.sidebar-content { flex: 1; overflow-y: auto; padding: 15px; }
|
|
37342
|
+
.section { margin-bottom: 20px; }
|
|
37343
|
+
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; color: #888; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
|
|
37344
|
+
.btn { background: #0f3460; color: #fff; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 13px; transition: background 0.2s; }
|
|
37345
|
+
.btn:hover { background: #1a4a7a; }
|
|
37346
|
+
.btn-primary { background: #e94560; }
|
|
37347
|
+
.btn-primary:hover { background: #ff6b6b; }
|
|
37348
|
+
.btn-small { padding: 4px 8px; font-size: 11px; }
|
|
37349
|
+
.camera-item, .connection-item { background: #0f3460; border-radius: 6px; padding: 12px; margin-bottom: 8px; cursor: pointer; transition: background 0.2s; }
|
|
37350
|
+
.camera-item:hover, .connection-item:hover { background: #1a4a7a; }
|
|
37351
|
+
.camera-item.selected, .connection-item.selected { outline: 2px solid #e94560; }
|
|
37352
|
+
.camera-name { font-weight: 500; margin-bottom: 4px; }
|
|
37353
|
+
.camera-info { font-size: 11px; color: #888; }
|
|
37354
|
+
.editor { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
|
|
37355
|
+
.toolbar { background: #16213e; border-bottom: 1px solid #0f3460; padding: 10px 20px; display: flex; gap: 10px; align-items: center; }
|
|
37356
|
+
.toolbar-group { display: flex; gap: 5px; padding-right: 15px; border-right: 1px solid #0f3460; margin-right: 5px; }
|
|
37357
|
+
.toolbar-group:last-child { border-right: none; }
|
|
37358
|
+
.canvas-container { flex: 1; position: relative; overflow: hidden; background: #0f0f1a; }
|
|
37359
|
+
#floor-plan-canvas { position: absolute; top: 0; left: 0; }
|
|
37360
|
+
.canvas-placeholder { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; color: #666; }
|
|
37361
|
+
.canvas-placeholder h2 { margin-bottom: 15px; }
|
|
37362
|
+
.properties-panel { width: 280px; background: #16213e; border-left: 1px solid #0f3460; overflow-y: auto; padding: 15px; }
|
|
37363
|
+
.properties-panel h3 { font-size: 14px; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #0f3460; }
|
|
37364
|
+
.form-group { margin-bottom: 15px; }
|
|
37365
|
+
.form-group label { display: block; font-size: 12px; color: #888; margin-bottom: 5px; }
|
|
37366
|
+
.form-group input, .form-group select { width: 100%; padding: 8px 10px; background: #0f3460; border: 1px solid #1a4a7a; border-radius: 4px; color: #fff; font-size: 13px; }
|
|
37367
|
+
.form-group input:focus, .form-group select:focus { outline: none; border-color: #e94560; }
|
|
37368
|
+
.checkbox-group { display: flex; align-items: center; gap: 8px; }
|
|
37369
|
+
.checkbox-group input[type="checkbox"] { width: auto; }
|
|
37370
|
+
.transit-time-inputs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
|
|
37371
|
+
.transit-time-inputs input { text-align: center; }
|
|
37372
|
+
.transit-time-labels { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; font-size: 10px; color: #666; text-align: center; }
|
|
37373
|
+
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.7); z-index: 1000; align-items: center; justify-content: center; }
|
|
37374
|
+
.modal-overlay.active { display: flex; }
|
|
37375
|
+
.modal { background: #16213e; border-radius: 8px; padding: 25px; max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto; }
|
|
37376
|
+
.modal h2 { margin-bottom: 20px; }
|
|
37377
|
+
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
|
|
37378
|
+
.upload-zone { border: 2px dashed #0f3460; border-radius: 8px; padding: 40px; text-align: center; cursor: pointer; transition: border-color 0.2s, background 0.2s; }
|
|
37379
|
+
.upload-zone:hover { border-color: #e94560; background: rgba(233, 69, 96, 0.1); }
|
|
37380
|
+
.upload-zone input { display: none; }
|
|
37381
|
+
.status-bar { background: #0f3460; padding: 8px 20px; font-size: 12px; color: #888; display: flex; justify-content: space-between; }
|
|
37382
|
+
.status-indicator { display: flex; align-items: center; gap: 6px; }
|
|
37383
|
+
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #4caf50; }
|
|
37384
|
+
.status-dot.warning { background: #ff9800; }
|
|
37385
|
+
.status-dot.error { background: #f44336; }
|
|
37386
|
+
</style>
|
|
37387
|
+
</head>
|
|
37388
|
+
<body>
|
|
37389
|
+
<div class="container">
|
|
37390
|
+
<div class="sidebar">
|
|
37391
|
+
<div class="sidebar-header">
|
|
37392
|
+
<h1>Spatial Awareness</h1>
|
|
37393
|
+
<p>Topology Editor</p>
|
|
37394
|
+
</div>
|
|
37395
|
+
<div class="sidebar-content">
|
|
37396
|
+
<div class="section">
|
|
37397
|
+
<div class="section-title">
|
|
37398
|
+
<span>Cameras</span>
|
|
37399
|
+
<button class="btn btn-small" onclick="openAddCameraModal()">+ Add</button>
|
|
37400
|
+
</div>
|
|
37401
|
+
<div id="camera-list">
|
|
37402
|
+
<div class="camera-item" style="color: #666; text-align: center; cursor: default;">No cameras configured</div>
|
|
37403
|
+
</div>
|
|
37404
|
+
</div>
|
|
37405
|
+
<div class="section">
|
|
37406
|
+
<div class="section-title">
|
|
37407
|
+
<span>Connections</span>
|
|
37408
|
+
<button class="btn btn-small" onclick="openAddConnectionModal()">+ Add</button>
|
|
37409
|
+
</div>
|
|
37410
|
+
<div id="connection-list">
|
|
37411
|
+
<div class="connection-item" style="color: #666; text-align: center; cursor: default;">No connections configured</div>
|
|
37412
|
+
</div>
|
|
37413
|
+
</div>
|
|
37414
|
+
</div>
|
|
37415
|
+
</div>
|
|
37416
|
+
<div class="editor">
|
|
37417
|
+
<div class="toolbar">
|
|
37418
|
+
<div class="toolbar-group">
|
|
37419
|
+
<button class="btn" onclick="uploadFloorPlan()">Upload Image</button>
|
|
37420
|
+
<button class="btn" onclick="useBlankCanvas()">Blank Canvas</button>
|
|
37421
|
+
</div>
|
|
37422
|
+
<div class="toolbar-group">
|
|
37423
|
+
<button class="btn" id="tool-select" onclick="setTool('select')">Select</button>
|
|
37424
|
+
<button class="btn" id="tool-wall" onclick="setTool('wall')">Draw Wall</button>
|
|
37425
|
+
<button class="btn" id="tool-room" onclick="setTool('room')">Draw Room</button>
|
|
37426
|
+
<button class="btn" id="tool-camera" onclick="setTool('camera')">Place Camera</button>
|
|
37427
|
+
<button class="btn" id="tool-connect" onclick="setTool('connect')">Connect</button>
|
|
37428
|
+
</div>
|
|
37429
|
+
<div class="toolbar-group">
|
|
37430
|
+
<button class="btn" onclick="clearDrawings()">Clear Drawings</button>
|
|
37431
|
+
</div>
|
|
37432
|
+
<div class="toolbar-group">
|
|
37433
|
+
<button class="btn btn-primary" onclick="saveTopology()">Save</button>
|
|
37434
|
+
</div>
|
|
37435
|
+
</div>
|
|
37436
|
+
<div class="canvas-container">
|
|
37437
|
+
<canvas id="floor-plan-canvas"></canvas>
|
|
37438
|
+
<div class="canvas-placeholder" id="canvas-placeholder">
|
|
37439
|
+
<h2>Floor Plan Editor</h2>
|
|
37440
|
+
<p>Upload an image or use a blank canvas to draw your floor plan</p>
|
|
37441
|
+
<br>
|
|
37442
|
+
<div style="display: flex; gap: 15px; justify-content: center;">
|
|
37443
|
+
<button class="btn btn-primary" onclick="uploadFloorPlan()">Upload Image</button>
|
|
37444
|
+
<button class="btn" onclick="useBlankCanvas()">Use Blank Canvas</button>
|
|
37445
|
+
</div>
|
|
37446
|
+
</div>
|
|
37447
|
+
</div>
|
|
37448
|
+
<div class="status-bar">
|
|
37449
|
+
<div class="status-indicator">
|
|
37450
|
+
<div class="status-dot" id="status-dot"></div>
|
|
37451
|
+
<span id="status-text">Ready</span>
|
|
37452
|
+
</div>
|
|
37453
|
+
<div>
|
|
37454
|
+
<span id="camera-count">0</span> cameras | <span id="connection-count">0</span> connections
|
|
37455
|
+
</div>
|
|
37456
|
+
</div>
|
|
37457
|
+
</div>
|
|
37458
|
+
<div class="properties-panel" id="properties-panel">
|
|
37459
|
+
<h3>Properties</h3>
|
|
37460
|
+
<p style="color: #666; font-size: 13px;">Select a camera or connection to edit its properties.</p>
|
|
37461
|
+
</div>
|
|
37462
|
+
</div>
|
|
37463
|
+
|
|
37464
|
+
<div class="modal-overlay" id="add-camera-modal">
|
|
37465
|
+
<div class="modal">
|
|
37466
|
+
<h2>Add Camera</h2>
|
|
37467
|
+
<div class="form-group">
|
|
37468
|
+
<label>Camera Device</label>
|
|
37469
|
+
<select id="camera-device-select"><option value="">Loading cameras...</option></select>
|
|
37470
|
+
</div>
|
|
37471
|
+
<div class="form-group">
|
|
37472
|
+
<label>Display Name</label>
|
|
37473
|
+
<input type="text" id="camera-name-input" placeholder="e.g., Front Door Camera">
|
|
37474
|
+
</div>
|
|
37475
|
+
<div class="form-group">
|
|
37476
|
+
<label class="checkbox-group">
|
|
37477
|
+
<input type="checkbox" id="camera-entry-checkbox">
|
|
37478
|
+
Entry Point (objects can enter property here)
|
|
37479
|
+
</label>
|
|
37480
|
+
</div>
|
|
37481
|
+
<div class="form-group">
|
|
37482
|
+
<label class="checkbox-group">
|
|
37483
|
+
<input type="checkbox" id="camera-exit-checkbox">
|
|
37484
|
+
Exit Point (objects can exit property here)
|
|
37485
|
+
</label>
|
|
37486
|
+
</div>
|
|
37487
|
+
<div class="modal-actions">
|
|
37488
|
+
<button class="btn" onclick="closeModal('add-camera-modal')">Cancel</button>
|
|
37489
|
+
<button class="btn btn-primary" onclick="addCamera()">Add Camera</button>
|
|
37490
|
+
</div>
|
|
37491
|
+
</div>
|
|
37492
|
+
</div>
|
|
37493
|
+
|
|
37494
|
+
<div class="modal-overlay" id="add-connection-modal">
|
|
37495
|
+
<div class="modal">
|
|
37496
|
+
<h2>Add Connection</h2>
|
|
37497
|
+
<div class="form-group">
|
|
37498
|
+
<label>Connection Name</label>
|
|
37499
|
+
<input type="text" id="connection-name-input" placeholder="e.g., Driveway to Front Door">
|
|
37500
|
+
</div>
|
|
37501
|
+
<div class="form-group">
|
|
37502
|
+
<label>From Camera</label>
|
|
37503
|
+
<select id="connection-from-select"></select>
|
|
37504
|
+
</div>
|
|
37505
|
+
<div class="form-group">
|
|
37506
|
+
<label>To Camera</label>
|
|
37507
|
+
<select id="connection-to-select"></select>
|
|
37508
|
+
</div>
|
|
37509
|
+
<div class="form-group">
|
|
37510
|
+
<label>Transit Time (seconds)</label>
|
|
37511
|
+
<div class="transit-time-inputs">
|
|
37512
|
+
<input type="number" id="transit-min" placeholder="Min" value="3">
|
|
37513
|
+
<input type="number" id="transit-typical" placeholder="Typical" value="10">
|
|
37514
|
+
<input type="number" id="transit-max" placeholder="Max" value="30">
|
|
37515
|
+
</div>
|
|
37516
|
+
<div class="transit-time-labels">
|
|
37517
|
+
<span>Minimum</span>
|
|
37518
|
+
<span>Typical</span>
|
|
37519
|
+
<span>Maximum</span>
|
|
37520
|
+
</div>
|
|
37521
|
+
</div>
|
|
37522
|
+
<div class="form-group">
|
|
37523
|
+
<label class="checkbox-group">
|
|
37524
|
+
<input type="checkbox" id="connection-bidirectional" checked>
|
|
37525
|
+
Bidirectional (works both ways)
|
|
37526
|
+
</label>
|
|
37527
|
+
</div>
|
|
37528
|
+
<div class="modal-actions">
|
|
37529
|
+
<button class="btn" onclick="closeModal('add-connection-modal')">Cancel</button>
|
|
37530
|
+
<button class="btn btn-primary" onclick="addConnection()">Add Connection</button>
|
|
37531
|
+
</div>
|
|
37532
|
+
</div>
|
|
37533
|
+
</div>
|
|
37534
|
+
|
|
37535
|
+
<div class="modal-overlay" id="upload-modal">
|
|
37536
|
+
<div class="modal">
|
|
37537
|
+
<h2>Upload Floor Plan</h2>
|
|
37538
|
+
<div class="upload-zone" onclick="document.getElementById('floor-plan-input').click()">
|
|
37539
|
+
<p>Click to select an image<br><small>PNG, JPG, or SVG</small></p>
|
|
37540
|
+
<input type="file" id="floor-plan-input" accept="image/*" onchange="handleFloorPlanUpload(event)">
|
|
37541
|
+
</div>
|
|
37542
|
+
<div class="modal-actions">
|
|
37543
|
+
<button class="btn" onclick="closeModal('upload-modal')">Cancel</button>
|
|
37544
|
+
</div>
|
|
37545
|
+
</div>
|
|
37546
|
+
</div>
|
|
37547
|
+
|
|
37548
|
+
<script>
|
|
37549
|
+
let topology = { version: '1.0', cameras: [], connections: [], globalZones: [], floorPlan: null, drawings: [] };
|
|
37550
|
+
let selectedItem = null;
|
|
37551
|
+
let currentTool = 'select';
|
|
37552
|
+
let floorPlanImage = null;
|
|
37553
|
+
let availableCameras = [];
|
|
37554
|
+
let isDrawing = false;
|
|
37555
|
+
let drawStart = null;
|
|
37556
|
+
let currentDrawing = null;
|
|
37557
|
+
let blankCanvasMode = false;
|
|
37558
|
+
const canvas = document.getElementById('floor-plan-canvas');
|
|
37559
|
+
const ctx = canvas.getContext('2d');
|
|
37560
|
+
|
|
37561
|
+
async function init() {
|
|
37562
|
+
await loadTopology();
|
|
37563
|
+
await loadAvailableCameras();
|
|
37564
|
+
resizeCanvas();
|
|
37565
|
+
render();
|
|
37566
|
+
updateUI();
|
|
37567
|
+
}
|
|
37568
|
+
|
|
37569
|
+
async function loadTopology() {
|
|
37570
|
+
try {
|
|
37571
|
+
const response = await fetch('../api/topology');
|
|
37572
|
+
if (response.ok) {
|
|
37573
|
+
topology = await response.json();
|
|
37574
|
+
if (!topology.drawings) topology.drawings = [];
|
|
37575
|
+
if (topology.floorPlan?.imageData) {
|
|
37576
|
+
await loadFloorPlanImage(topology.floorPlan.imageData);
|
|
37577
|
+
} else if (topology.floorPlan?.type === 'blank') {
|
|
37578
|
+
blankCanvasMode = true;
|
|
37579
|
+
}
|
|
37580
|
+
}
|
|
37581
|
+
} catch (e) { console.error('Failed to load topology:', e); }
|
|
37582
|
+
}
|
|
37583
|
+
|
|
37584
|
+
async function loadAvailableCameras() {
|
|
37585
|
+
try {
|
|
37586
|
+
const response = await fetch('../api/cameras');
|
|
37587
|
+
if (response.ok) {
|
|
37588
|
+
availableCameras = await response.json();
|
|
37589
|
+
} else {
|
|
37590
|
+
availableCameras = [];
|
|
37591
|
+
}
|
|
37592
|
+
} catch (e) {
|
|
37593
|
+
console.error('Failed to load cameras:', e);
|
|
37594
|
+
availableCameras = [];
|
|
37595
|
+
}
|
|
37596
|
+
updateCameraSelects();
|
|
37597
|
+
}
|
|
37598
|
+
|
|
37599
|
+
async function saveTopology() {
|
|
37600
|
+
try {
|
|
37601
|
+
setStatus('Saving...', 'warning');
|
|
37602
|
+
const response = await fetch('../api/topology', {
|
|
37603
|
+
method: 'PUT',
|
|
37604
|
+
headers: { 'Content-Type': 'application/json' },
|
|
37605
|
+
body: JSON.stringify(topology)
|
|
37606
|
+
});
|
|
37607
|
+
if (response.ok) { setStatus('Saved successfully', 'success'); }
|
|
37608
|
+
else { setStatus('Failed to save', 'error'); }
|
|
37609
|
+
} catch (e) { console.error('Failed to save topology:', e); setStatus('Failed to save', 'error'); }
|
|
37610
|
+
}
|
|
37611
|
+
|
|
37612
|
+
function resizeCanvas() {
|
|
37613
|
+
const container = canvas.parentElement;
|
|
37614
|
+
canvas.width = container.clientWidth;
|
|
37615
|
+
canvas.height = container.clientHeight;
|
|
37616
|
+
}
|
|
37617
|
+
|
|
37618
|
+
function render() {
|
|
37619
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
37620
|
+
|
|
37621
|
+
// Draw grid for blank canvas
|
|
37622
|
+
if (blankCanvasMode && !floorPlanImage) {
|
|
37623
|
+
document.getElementById('canvas-placeholder').style.display = 'none';
|
|
37624
|
+
ctx.fillStyle = '#1a1a2e';
|
|
37625
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
37626
|
+
ctx.strokeStyle = '#2a2a4e';
|
|
37627
|
+
ctx.lineWidth = 1;
|
|
37628
|
+
const gridSize = 40;
|
|
37629
|
+
for (let x = 0; x < canvas.width; x += gridSize) {
|
|
37630
|
+
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, canvas.height); ctx.stroke();
|
|
37631
|
+
}
|
|
37632
|
+
for (let y = 0; y < canvas.height; y += gridSize) {
|
|
37633
|
+
ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(canvas.width, y); ctx.stroke();
|
|
37634
|
+
}
|
|
37635
|
+
} else if (floorPlanImage) {
|
|
37636
|
+
document.getElementById('canvas-placeholder').style.display = 'none';
|
|
37637
|
+
const scale = Math.min(canvas.width / floorPlanImage.width, canvas.height / floorPlanImage.height) * 0.9;
|
|
37638
|
+
const x = (canvas.width - floorPlanImage.width * scale) / 2;
|
|
37639
|
+
const y = (canvas.height - floorPlanImage.height * scale) / 2;
|
|
37640
|
+
ctx.drawImage(floorPlanImage, x, y, floorPlanImage.width * scale, floorPlanImage.height * scale);
|
|
37641
|
+
} else {
|
|
37642
|
+
document.getElementById('canvas-placeholder').style.display = 'block';
|
|
37643
|
+
}
|
|
37644
|
+
|
|
37645
|
+
// Draw saved drawings (walls and rooms)
|
|
37646
|
+
if (topology.drawings) {
|
|
37647
|
+
for (const drawing of topology.drawings) {
|
|
37648
|
+
if (drawing.type === 'wall') {
|
|
37649
|
+
ctx.beginPath();
|
|
37650
|
+
ctx.moveTo(drawing.x1, drawing.y1);
|
|
37651
|
+
ctx.lineTo(drawing.x2, drawing.y2);
|
|
37652
|
+
ctx.strokeStyle = '#888';
|
|
37653
|
+
ctx.lineWidth = 4;
|
|
37654
|
+
ctx.stroke();
|
|
37655
|
+
} else if (drawing.type === 'room') {
|
|
37656
|
+
ctx.strokeStyle = '#666';
|
|
37657
|
+
ctx.lineWidth = 2;
|
|
37658
|
+
ctx.strokeRect(drawing.x, drawing.y, drawing.width, drawing.height);
|
|
37659
|
+
ctx.fillStyle = 'rgba(100, 100, 150, 0.1)';
|
|
37660
|
+
ctx.fillRect(drawing.x, drawing.y, drawing.width, drawing.height);
|
|
37661
|
+
if (drawing.label) {
|
|
37662
|
+
ctx.fillStyle = '#888';
|
|
37663
|
+
ctx.font = '12px sans-serif';
|
|
37664
|
+
ctx.textAlign = 'center';
|
|
37665
|
+
ctx.fillText(drawing.label, drawing.x + drawing.width/2, drawing.y + drawing.height/2);
|
|
37666
|
+
}
|
|
37667
|
+
}
|
|
37668
|
+
}
|
|
37669
|
+
}
|
|
37670
|
+
|
|
37671
|
+
// Draw current drawing in progress
|
|
37672
|
+
if (currentDrawing) {
|
|
37673
|
+
if (currentDrawing.type === 'wall') {
|
|
37674
|
+
ctx.beginPath();
|
|
37675
|
+
ctx.moveTo(currentDrawing.x1, currentDrawing.y1);
|
|
37676
|
+
ctx.lineTo(currentDrawing.x2, currentDrawing.y2);
|
|
37677
|
+
ctx.strokeStyle = '#e94560';
|
|
37678
|
+
ctx.lineWidth = 4;
|
|
37679
|
+
ctx.stroke();
|
|
37680
|
+
} else if (currentDrawing.type === 'room') {
|
|
37681
|
+
ctx.strokeStyle = '#e94560';
|
|
37682
|
+
ctx.lineWidth = 2;
|
|
37683
|
+
ctx.strokeRect(currentDrawing.x, currentDrawing.y, currentDrawing.width, currentDrawing.height);
|
|
37684
|
+
}
|
|
37685
|
+
}
|
|
37686
|
+
for (const conn of topology.connections) {
|
|
37687
|
+
const fromCam = topology.cameras.find(c => c.deviceId === conn.fromCameraId);
|
|
37688
|
+
const toCam = topology.cameras.find(c => c.deviceId === conn.toCameraId);
|
|
37689
|
+
if (fromCam?.floorPlanPosition && toCam?.floorPlanPosition) {
|
|
37690
|
+
drawConnection(fromCam.floorPlanPosition, toCam.floorPlanPosition, conn);
|
|
37691
|
+
}
|
|
37692
|
+
}
|
|
37693
|
+
for (const camera of topology.cameras) {
|
|
37694
|
+
if (camera.floorPlanPosition) { drawCamera(camera); }
|
|
37695
|
+
}
|
|
37696
|
+
}
|
|
37697
|
+
|
|
37698
|
+
function drawCamera(camera) {
|
|
37699
|
+
const pos = camera.floorPlanPosition;
|
|
37700
|
+
const isSelected = selectedItem?.type === 'camera' && selectedItem?.id === camera.deviceId;
|
|
37701
|
+
ctx.beginPath();
|
|
37702
|
+
ctx.arc(pos.x, pos.y, 20, 0, Math.PI * 2);
|
|
37703
|
+
ctx.fillStyle = isSelected ? '#e94560' : '#0f3460';
|
|
37704
|
+
ctx.fill();
|
|
37705
|
+
ctx.strokeStyle = '#fff';
|
|
37706
|
+
ctx.lineWidth = 2;
|
|
37707
|
+
ctx.stroke();
|
|
37708
|
+
ctx.fillStyle = '#fff';
|
|
37709
|
+
ctx.font = '12px sans-serif';
|
|
37710
|
+
ctx.textAlign = 'center';
|
|
37711
|
+
ctx.textBaseline = 'middle';
|
|
37712
|
+
ctx.fillText('CAM', pos.x, pos.y);
|
|
37713
|
+
ctx.fillText(camera.name, pos.x, pos.y + 35);
|
|
37714
|
+
}
|
|
37715
|
+
|
|
37716
|
+
function drawConnection(from, to, conn) {
|
|
37717
|
+
const isSelected = selectedItem?.type === 'connection' && selectedItem?.id === conn.id;
|
|
37718
|
+
ctx.beginPath();
|
|
37719
|
+
ctx.moveTo(from.x, from.y);
|
|
37720
|
+
ctx.lineTo(to.x, to.y);
|
|
37721
|
+
ctx.strokeStyle = isSelected ? '#e94560' : '#4caf50';
|
|
37722
|
+
ctx.lineWidth = isSelected ? 4 : 2;
|
|
37723
|
+
ctx.stroke();
|
|
37724
|
+
if (!conn.bidirectional) {
|
|
37725
|
+
const angle = Math.atan2(to.y - from.y, to.x - from.x);
|
|
37726
|
+
const midX = (from.x + to.x) / 2;
|
|
37727
|
+
const midY = (from.y + to.y) / 2;
|
|
37728
|
+
ctx.beginPath();
|
|
37729
|
+
ctx.moveTo(midX, midY);
|
|
37730
|
+
ctx.lineTo(midX - 10 * Math.cos(angle - 0.5), midY - 10 * Math.sin(angle - 0.5));
|
|
37731
|
+
ctx.lineTo(midX - 10 * Math.cos(angle + 0.5), midY - 10 * Math.sin(angle + 0.5));
|
|
37732
|
+
ctx.closePath();
|
|
37733
|
+
ctx.fillStyle = isSelected ? '#e94560' : '#4caf50';
|
|
37734
|
+
ctx.fill();
|
|
37735
|
+
}
|
|
37736
|
+
}
|
|
37737
|
+
|
|
37738
|
+
function uploadFloorPlan() { document.getElementById('upload-modal').classList.add('active'); }
|
|
37739
|
+
|
|
37740
|
+
async function handleFloorPlanUpload(event) {
|
|
37741
|
+
const file = event.target.files[0];
|
|
37742
|
+
if (!file) return;
|
|
37743
|
+
const reader = new FileReader();
|
|
37744
|
+
reader.onload = async (e) => {
|
|
37745
|
+
const imageData = e.target.result;
|
|
37746
|
+
await loadFloorPlanImage(imageData);
|
|
37747
|
+
topology.floorPlan = { imageData, width: floorPlanImage.width, height: floorPlanImage.height };
|
|
37748
|
+
closeModal('upload-modal');
|
|
37749
|
+
render();
|
|
37750
|
+
};
|
|
37751
|
+
reader.readAsDataURL(file);
|
|
37752
|
+
}
|
|
37753
|
+
|
|
37754
|
+
function loadFloorPlanImage(imageData) {
|
|
37755
|
+
return new Promise((resolve) => {
|
|
37756
|
+
floorPlanImage = new Image();
|
|
37757
|
+
floorPlanImage.onload = resolve;
|
|
37758
|
+
floorPlanImage.src = imageData;
|
|
37759
|
+
});
|
|
37760
|
+
}
|
|
37761
|
+
|
|
37762
|
+
function openAddCameraModal() { document.getElementById('add-camera-modal').classList.add('active'); }
|
|
37763
|
+
|
|
37764
|
+
function addCamera() {
|
|
37765
|
+
const deviceId = document.getElementById('camera-device-select').value;
|
|
37766
|
+
if (!deviceId) {
|
|
37767
|
+
alert('Please select a camera');
|
|
37768
|
+
return;
|
|
37769
|
+
}
|
|
37770
|
+
const selectedCam = availableCameras.find(c => c.id === deviceId);
|
|
37771
|
+
const customName = document.getElementById('camera-name-input').value;
|
|
37772
|
+
const name = customName || (selectedCam ? selectedCam.name : 'New Camera');
|
|
37773
|
+
const isEntry = document.getElementById('camera-entry-checkbox').checked;
|
|
37774
|
+
const isExit = document.getElementById('camera-exit-checkbox').checked;
|
|
37775
|
+
// Use pending position from click, or default to center
|
|
37776
|
+
const pos = topology._pendingCameraPos || { x: canvas.width / 2 + Math.random() * 100 - 50, y: canvas.height / 2 + Math.random() * 100 - 50 };
|
|
37777
|
+
delete topology._pendingCameraPos;
|
|
37778
|
+
const camera = {
|
|
37779
|
+
deviceId: deviceId,
|
|
37780
|
+
nativeId: 'cam-' + Date.now(),
|
|
37781
|
+
name,
|
|
37782
|
+
isEntryPoint: isEntry,
|
|
37783
|
+
isExitPoint: isExit,
|
|
37784
|
+
trackClasses: ['person', 'car', 'animal'],
|
|
37785
|
+
floorPlanPosition: pos
|
|
37786
|
+
};
|
|
37787
|
+
topology.cameras.push(camera);
|
|
37788
|
+
closeModal('add-camera-modal');
|
|
37789
|
+
// Clear form
|
|
37790
|
+
document.getElementById('camera-name-input').value = '';
|
|
37791
|
+
document.getElementById('camera-entry-checkbox').checked = false;
|
|
37792
|
+
document.getElementById('camera-exit-checkbox').checked = false;
|
|
37793
|
+
updateCameraSelects();
|
|
37794
|
+
updateUI();
|
|
37795
|
+
render();
|
|
37796
|
+
}
|
|
37797
|
+
|
|
37798
|
+
function openAddConnectionModal() {
|
|
37799
|
+
if (topology.cameras.length < 2) { alert('Add at least 2 cameras before creating connections'); return; }
|
|
37800
|
+
updateCameraSelects();
|
|
37801
|
+
document.getElementById('add-connection-modal').classList.add('active');
|
|
37802
|
+
}
|
|
37803
|
+
|
|
37804
|
+
function updateCameraSelects() {
|
|
37805
|
+
// Update camera device select (for adding new cameras)
|
|
37806
|
+
const cameraDeviceSelect = document.getElementById('camera-device-select');
|
|
37807
|
+
if (availableCameras.length > 0) {
|
|
37808
|
+
const existingIds = topology.cameras.map(c => c.deviceId);
|
|
37809
|
+
const available = availableCameras.filter(c => !existingIds.includes(c.id));
|
|
37810
|
+
if (available.length > 0) {
|
|
37811
|
+
cameraDeviceSelect.innerHTML = '<option value="">Select a camera...</option>' +
|
|
37812
|
+
available.map(c => '<option value="' + c.id + '">' + c.name + '</option>').join('');
|
|
37813
|
+
} else {
|
|
37814
|
+
cameraDeviceSelect.innerHTML = '<option value="">All cameras already added</option>';
|
|
37815
|
+
}
|
|
37816
|
+
} else {
|
|
37817
|
+
cameraDeviceSelect.innerHTML = '<option value="">No cameras with object detection found</option>';
|
|
37818
|
+
}
|
|
37819
|
+
|
|
37820
|
+
// Update connection selects (for existing topology cameras)
|
|
37821
|
+
const options = topology.cameras.map(c => '<option value="' + c.deviceId + '">' + c.name + '</option>').join('');
|
|
37822
|
+
document.getElementById('connection-from-select').innerHTML = options;
|
|
37823
|
+
document.getElementById('connection-to-select').innerHTML = options;
|
|
37824
|
+
}
|
|
37825
|
+
|
|
37826
|
+
function addConnection() {
|
|
37827
|
+
const name = document.getElementById('connection-name-input').value;
|
|
37828
|
+
const fromId = document.getElementById('connection-from-select').value;
|
|
37829
|
+
const toId = document.getElementById('connection-to-select').value;
|
|
37830
|
+
const minTransit = parseInt(document.getElementById('transit-min').value) * 1000;
|
|
37831
|
+
const typicalTransit = parseInt(document.getElementById('transit-typical').value) * 1000;
|
|
37832
|
+
const maxTransit = parseInt(document.getElementById('transit-max').value) * 1000;
|
|
37833
|
+
const bidirectional = document.getElementById('connection-bidirectional').checked;
|
|
37834
|
+
if (fromId === toId) { alert('Please select different cameras'); return; }
|
|
37835
|
+
const connection = {
|
|
37836
|
+
id: 'conn-' + Date.now(),
|
|
37837
|
+
fromCameraId: fromId,
|
|
37838
|
+
toCameraId: toId,
|
|
37839
|
+
name: name || fromId + ' to ' + toId,
|
|
37840
|
+
exitZone: [],
|
|
37841
|
+
entryZone: [],
|
|
37842
|
+
transitTime: { min: minTransit, typical: typicalTransit, max: maxTransit },
|
|
37843
|
+
bidirectional
|
|
37844
|
+
};
|
|
37845
|
+
topology.connections.push(connection);
|
|
37846
|
+
closeModal('add-connection-modal');
|
|
37847
|
+
updateUI();
|
|
37848
|
+
render();
|
|
37849
|
+
}
|
|
37850
|
+
|
|
37851
|
+
function updateUI() {
|
|
37852
|
+
const cameraList = document.getElementById('camera-list');
|
|
37853
|
+
if (topology.cameras.length === 0) {
|
|
37854
|
+
cameraList.innerHTML = '<div class="camera-item" style="color: #666; text-align: center; cursor: default;">No cameras configured</div>';
|
|
37855
|
+
} else {
|
|
37856
|
+
cameraList.innerHTML = topology.cameras.map(c => '<div class="camera-item ' + (selectedItem?.type === 'camera' && selectedItem?.id === c.deviceId ? 'selected' : '') + '" onclick="selectCamera(\\'' + c.deviceId + '\\')"><div class="camera-name">CAM ' + c.name + '</div><div class="camera-info">' + (c.isEntryPoint ? 'Entry ' : '') + (c.isExitPoint ? 'Exit' : '') + '</div></div>').join('');
|
|
37857
|
+
}
|
|
37858
|
+
const connectionList = document.getElementById('connection-list');
|
|
37859
|
+
if (topology.connections.length === 0) {
|
|
37860
|
+
connectionList.innerHTML = '<div class="connection-item" style="color: #666; text-align: center; cursor: default;">No connections configured</div>';
|
|
37861
|
+
} else {
|
|
37862
|
+
connectionList.innerHTML = topology.connections.map(c => '<div class="connection-item ' + (selectedItem?.type === 'connection' && selectedItem?.id === c.id ? 'selected' : '') + '" onclick="selectConnection(\\'' + c.id + '\\')"><div class="camera-name">' + c.name + '</div><div class="camera-info">' + (c.transitTime.typical / 1000) + 's typical ' + (c.bidirectional ? '<->' : '->') + '</div></div>').join('');
|
|
37863
|
+
}
|
|
37864
|
+
document.getElementById('camera-count').textContent = topology.cameras.length;
|
|
37865
|
+
document.getElementById('connection-count').textContent = topology.connections.length;
|
|
37866
|
+
}
|
|
37867
|
+
|
|
37868
|
+
function selectCamera(deviceId) {
|
|
37869
|
+
selectedItem = { type: 'camera', id: deviceId };
|
|
37870
|
+
const camera = topology.cameras.find(c => c.deviceId === deviceId);
|
|
37871
|
+
showCameraProperties(camera);
|
|
37872
|
+
updateUI();
|
|
37873
|
+
render();
|
|
37874
|
+
}
|
|
37875
|
+
|
|
37876
|
+
function selectConnection(connId) {
|
|
37877
|
+
selectedItem = { type: 'connection', id: connId };
|
|
37878
|
+
const connection = topology.connections.find(c => c.id === connId);
|
|
37879
|
+
showConnectionProperties(connection);
|
|
37880
|
+
updateUI();
|
|
37881
|
+
render();
|
|
37882
|
+
}
|
|
37883
|
+
|
|
37884
|
+
function showCameraProperties(camera) {
|
|
37885
|
+
const panel = document.getElementById('properties-panel');
|
|
37886
|
+
panel.innerHTML = '<h3>Camera Properties</h3><div class="form-group"><label>Name</label><input type="text" value="' + camera.name + '" onchange="updateCameraName(\\'' + camera.deviceId + '\\', this.value)"></div><div class="form-group"><label class="checkbox-group"><input type="checkbox" ' + (camera.isEntryPoint ? 'checked' : '') + ' onchange="updateCameraEntry(\\'' + camera.deviceId + '\\', this.checked)">Entry Point</label></div><div class="form-group"><label class="checkbox-group"><input type="checkbox" ' + (camera.isExitPoint ? 'checked' : '') + ' onchange="updateCameraExit(\\'' + camera.deviceId + '\\', this.checked)">Exit Point</label></div><div class="form-group"><button class="btn" style="width: 100%; background: #f44336;" onclick="deleteCamera(\\'' + camera.deviceId + '\\')">Delete Camera</button></div>';
|
|
37887
|
+
}
|
|
37888
|
+
|
|
37889
|
+
function showConnectionProperties(connection) {
|
|
37890
|
+
const panel = document.getElementById('properties-panel');
|
|
37891
|
+
panel.innerHTML = '<h3>Connection Properties</h3><div class="form-group"><label>Name</label><input type="text" value="' + connection.name + '" onchange="updateConnectionName(\\'' + connection.id + '\\', this.value)"></div><div class="form-group"><label>Transit Time (seconds)</label><div class="transit-time-inputs"><input type="number" value="' + (connection.transitTime.min / 1000) + '" onchange="updateTransitTime(\\'' + connection.id + '\\', \\'min\\', this.value)"><input type="number" value="' + (connection.transitTime.typical / 1000) + '" onchange="updateTransitTime(\\'' + connection.id + '\\', \\'typical\\', this.value)"><input type="number" value="' + (connection.transitTime.max / 1000) + '" onchange="updateTransitTime(\\'' + connection.id + '\\', \\'max\\', this.value)"></div><div class="transit-time-labels"><span>Min</span><span>Typical</span><span>Max</span></div></div><div class="form-group"><label class="checkbox-group"><input type="checkbox" ' + (connection.bidirectional ? 'checked' : '') + ' onchange="updateConnectionBidi(\\'' + connection.id + '\\', this.checked)">Bidirectional</label></div><div class="form-group"><button class="btn" style="width: 100%; background: #f44336;" onclick="deleteConnection(\\'' + connection.id + '\\')">Delete Connection</button></div>';
|
|
37892
|
+
}
|
|
37893
|
+
|
|
37894
|
+
function updateCameraName(id, value) { const camera = topology.cameras.find(c => c.deviceId === id); if (camera) camera.name = value; updateUI(); }
|
|
37895
|
+
function updateCameraEntry(id, value) { const camera = topology.cameras.find(c => c.deviceId === id); if (camera) camera.isEntryPoint = value; }
|
|
37896
|
+
function updateCameraExit(id, value) { const camera = topology.cameras.find(c => c.deviceId === id); if (camera) camera.isExitPoint = value; }
|
|
37897
|
+
function updateConnectionName(id, value) { const conn = topology.connections.find(c => c.id === id); if (conn) conn.name = value; updateUI(); }
|
|
37898
|
+
function updateTransitTime(id, field, value) { const conn = topology.connections.find(c => c.id === id); if (conn) conn.transitTime[field] = parseInt(value) * 1000; }
|
|
37899
|
+
function updateConnectionBidi(id, value) { const conn = topology.connections.find(c => c.id === id); if (conn) conn.bidirectional = value; render(); }
|
|
37900
|
+
function deleteCamera(id) { if (!confirm('Delete this camera?')) return; topology.cameras = topology.cameras.filter(c => c.deviceId !== id); topology.connections = topology.connections.filter(c => c.fromCameraId !== id && c.toCameraId !== id); selectedItem = null; document.getElementById('properties-panel').innerHTML = '<h3>Properties</h3><p style="color: #666;">Select a camera or connection.</p>'; updateUI(); render(); }
|
|
37901
|
+
function deleteConnection(id) { if (!confirm('Delete this connection?')) return; topology.connections = topology.connections.filter(c => c.id !== id); selectedItem = null; document.getElementById('properties-panel').innerHTML = '<h3>Properties</h3><p style="color: #666;">Select a camera or connection.</p>'; updateUI(); render(); }
|
|
37902
|
+
function setTool(tool) {
|
|
37903
|
+
currentTool = tool;
|
|
37904
|
+
setStatus('Tool: ' + tool, 'success');
|
|
37905
|
+
document.querySelectorAll('.toolbar .btn').forEach(b => b.style.background = '');
|
|
37906
|
+
const btn = document.getElementById('tool-' + tool);
|
|
37907
|
+
if (btn) btn.style.background = '#e94560';
|
|
37908
|
+
}
|
|
37909
|
+
|
|
37910
|
+
function useBlankCanvas() {
|
|
37911
|
+
blankCanvasMode = true;
|
|
37912
|
+
floorPlanImage = null;
|
|
37913
|
+
topology.floorPlan = { type: 'blank', width: canvas.width, height: canvas.height };
|
|
37914
|
+
render();
|
|
37915
|
+
setStatus('Blank canvas ready - use Draw Wall or Draw Room tools', 'success');
|
|
37916
|
+
}
|
|
37917
|
+
|
|
37918
|
+
function clearDrawings() {
|
|
37919
|
+
if (!confirm('Clear all drawings (walls and rooms)?')) return;
|
|
37920
|
+
topology.drawings = [];
|
|
37921
|
+
render();
|
|
37922
|
+
setStatus('Drawings cleared', 'success');
|
|
37923
|
+
}
|
|
37924
|
+
|
|
37925
|
+
function closeModal(id) { document.getElementById(id).classList.remove('active'); }
|
|
37926
|
+
function setStatus(text, type) { document.getElementById('status-text').textContent = text; const dot = document.getElementById('status-dot'); dot.className = 'status-dot'; if (type === 'warning') dot.classList.add('warning'); if (type === 'error') dot.classList.add('error'); }
|
|
37927
|
+
|
|
37928
|
+
let dragging = null;
|
|
37929
|
+
|
|
37930
|
+
canvas.addEventListener('mousedown', (e) => {
|
|
37931
|
+
const rect = canvas.getBoundingClientRect();
|
|
37932
|
+
const x = e.clientX - rect.left;
|
|
37933
|
+
const y = e.clientY - rect.top;
|
|
37934
|
+
|
|
37935
|
+
if (currentTool === 'select') {
|
|
37936
|
+
for (const camera of topology.cameras) {
|
|
37937
|
+
if (camera.floorPlanPosition) {
|
|
37938
|
+
const dist = Math.hypot(x - camera.floorPlanPosition.x, y - camera.floorPlanPosition.y);
|
|
37939
|
+
if (dist < 25) { selectCamera(camera.deviceId); dragging = camera; return; }
|
|
37940
|
+
}
|
|
37941
|
+
}
|
|
37942
|
+
} else if (currentTool === 'wall') {
|
|
37943
|
+
isDrawing = true;
|
|
37944
|
+
drawStart = { x, y };
|
|
37945
|
+
currentDrawing = { type: 'wall', x1: x, y1: y, x2: x, y2: y };
|
|
37946
|
+
} else if (currentTool === 'room') {
|
|
37947
|
+
isDrawing = true;
|
|
37948
|
+
drawStart = { x, y };
|
|
37949
|
+
currentDrawing = { type: 'room', x: x, y: y, width: 0, height: 0 };
|
|
37950
|
+
} else if (currentTool === 'camera') {
|
|
37951
|
+
openAddCameraModal();
|
|
37952
|
+
// Will position camera at click location after adding
|
|
37953
|
+
topology._pendingCameraPos = { x, y };
|
|
37954
|
+
}
|
|
37955
|
+
});
|
|
37956
|
+
|
|
37957
|
+
canvas.addEventListener('mousemove', (e) => {
|
|
37958
|
+
const rect = canvas.getBoundingClientRect();
|
|
37959
|
+
const x = e.clientX - rect.left;
|
|
37960
|
+
const y = e.clientY - rect.top;
|
|
37961
|
+
|
|
37962
|
+
if (dragging) {
|
|
37963
|
+
dragging.floorPlanPosition.x = x;
|
|
37964
|
+
dragging.floorPlanPosition.y = y;
|
|
37965
|
+
render();
|
|
37966
|
+
} else if (isDrawing && currentDrawing) {
|
|
37967
|
+
if (currentDrawing.type === 'wall') {
|
|
37968
|
+
currentDrawing.x2 = x;
|
|
37969
|
+
currentDrawing.y2 = y;
|
|
37970
|
+
} else if (currentDrawing.type === 'room') {
|
|
37971
|
+
currentDrawing.width = x - drawStart.x;
|
|
37972
|
+
currentDrawing.height = y - drawStart.y;
|
|
37973
|
+
}
|
|
37974
|
+
render();
|
|
37975
|
+
}
|
|
37976
|
+
});
|
|
37977
|
+
|
|
37978
|
+
canvas.addEventListener('mouseup', (e) => {
|
|
37979
|
+
if (isDrawing && currentDrawing) {
|
|
37980
|
+
if (!topology.drawings) topology.drawings = [];
|
|
37981
|
+
// Normalize room coordinates if drawn backwards
|
|
37982
|
+
if (currentDrawing.type === 'room') {
|
|
37983
|
+
if (currentDrawing.width < 0) {
|
|
37984
|
+
currentDrawing.x += currentDrawing.width;
|
|
37985
|
+
currentDrawing.width = Math.abs(currentDrawing.width);
|
|
37986
|
+
}
|
|
37987
|
+
if (currentDrawing.height < 0) {
|
|
37988
|
+
currentDrawing.y += currentDrawing.height;
|
|
37989
|
+
currentDrawing.height = Math.abs(currentDrawing.height);
|
|
37990
|
+
}
|
|
37991
|
+
// Only add if room is big enough
|
|
37992
|
+
if (currentDrawing.width > 20 && currentDrawing.height > 20) {
|
|
37993
|
+
const label = prompt('Room name (optional):');
|
|
37994
|
+
if (label) currentDrawing.label = label;
|
|
37995
|
+
topology.drawings.push(currentDrawing);
|
|
37996
|
+
}
|
|
37997
|
+
} else if (currentDrawing.type === 'wall') {
|
|
37998
|
+
// Only add if wall is long enough
|
|
37999
|
+
const len = Math.hypot(currentDrawing.x2 - currentDrawing.x1, currentDrawing.y2 - currentDrawing.y1);
|
|
38000
|
+
if (len > 20) {
|
|
38001
|
+
topology.drawings.push(currentDrawing);
|
|
38002
|
+
}
|
|
38003
|
+
}
|
|
38004
|
+
isDrawing = false;
|
|
38005
|
+
currentDrawing = null;
|
|
38006
|
+
render();
|
|
38007
|
+
}
|
|
38008
|
+
dragging = null;
|
|
38009
|
+
});
|
|
38010
|
+
|
|
38011
|
+
window.addEventListener('resize', () => { resizeCanvas(); render(); });
|
|
38012
|
+
init();
|
|
38013
|
+
</script>
|
|
38014
|
+
</body>
|
|
38015
|
+
</html>`;
|
|
38016
|
+
|
|
38017
|
+
|
|
37101
38018
|
/***/ },
|
|
37102
38019
|
|
|
37103
38020
|
/***/ "assert"
|
|
@@ -37221,17 +38138,6 @@ module.exports = require("os");
|
|
|
37221
38138
|
|
|
37222
38139
|
/***/ },
|
|
37223
38140
|
|
|
37224
|
-
/***/ "path"
|
|
37225
|
-
/*!***********************!*\
|
|
37226
|
-
!*** external "path" ***!
|
|
37227
|
-
\***********************/
|
|
37228
|
-
(module) {
|
|
37229
|
-
|
|
37230
|
-
"use strict";
|
|
37231
|
-
module.exports = require("path");
|
|
37232
|
-
|
|
37233
|
-
/***/ },
|
|
37234
|
-
|
|
37235
38141
|
/***/ "stream"
|
|
37236
38142
|
/*!*************************!*\
|
|
37237
38143
|
!*** external "stream" ***!
|