Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

auto remove

roryclear4fc45cc1f887
diff --git a/clearcam/main.html b/clearcam/main.html
index a511128..aebf41a 100644
--- a/clearcam/main.html
+++ b/clearcam/main.html
@@ -71,23 +71,36 @@
<script>
let isPortrait = false; // Track the current orientation
-
- function loadPage() {
- const url = document.getElementById('urlInput').value;
- createRectangle(url);
- }
const existingUrls = new Set();
+ const rectangles = new Map();
async function fetchDevices() {
try {
const response = await fetch('/get-devices');
const devices = await response.json();
- devices.forEach(ip => {
- const url = `http://${ip}:8080`;
+ const newUrls = new Set(devices.map(ip => `http://${ip}:8080`));
+
+ console.log('Fetched devices:', devices);
+ console.log('New URLs:', [...newUrls]);
+
+ // Add new URLs
+ newUrls.forEach(url => {
if (!existingUrls.has(url)) {
+ console.log('Adding new rectangle for:', url);
existingUrls.add(url);
- createRectangle(url);
+ const rect = createRectangle(url);
+ rectangles.set(url, rect);
+ }
+ });
+
+ // Remove rectangles for URLs no longer present
+ [...existingUrls].forEach(url => {
+ if (!newUrls.has(url)) {
+ console.log('Removing rectangle for:', url);
+ removeRectangle(url);
+ existingUrls.delete(url);
+ rectangles.delete(url);
}
});
} catch (error) {
@@ -95,6 +108,16 @@
}
}
+ function removeRectangle(url) {
+ const rect = rectangles.get(url);
+ if (rect) {
+ console.log('Removing element from DOM:', rect);
+ rect.remove();
+ } else {
+ console.warn('Rectangle not found for URL:', url);
+ }
+ }
+
function startPolling(interval = 5000) {
setInterval(fetchDevices, interval);
}
@@ -128,6 +151,7 @@
addResizeListeners(handle, rectangle);
addDragListeners(dragLeft, rectangle);
addDragListeners(dragRight, rectangle);
+ return rectangle;
}
function addResizeListeners(handle, rectangle) {