Add object detection, tracking, mobile notifications, and search to any security camera.
forgot to add file
roryclear032529f508e0
diff --git a/clearcam/multicamera.html b/clearcam/multicamera.htmlnew file mode 100644index 0000000..b4ce9aa--- /dev/null+++ b/clearcam/multicamera.html@@ -0,0 +1,371 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Multi-camera view</title>+ <style>+ body {+ margin: 0;+ height: 100vh;+ display: flex;+ flex-direction: column;+ justify-content: center;+ align-items: center;+ background-color: #f0f0f0;+ overflow: hidden;+ }+ .container {+ position: absolute;+ width: 360px; /* Initial width */+ height: calc(360px * 9 / 16); /* Initial height */+ border: 2px solid black;+ touch-action: none;+ }+ .handle {+ position: absolute;+ width: 20px;+ height: 20px;+ background: transparent;+ bottom: -10px;+ right: -10px;+ cursor: nwse-resize;+ border: none;+ outline: none;+ }+ .drag-bottom, .drag-left, .drag-right {+ position: absolute;+ background: rgba(0, 0, 0, 0);+ cursor: move;+ z-index: 3;+ }+ .drag-left {+ top: 0;+ left: 0;+ height: 80%;+ width: 5%;+ }+ .drag-right {+ top: 0;+ right: 0;+ height: 70%;+ width: 1%;+ }+ iframe {+ width: 100%;+ height: 100%;+ border: none;+ position: relative;+ z-index: 1;+ }+ </style>+</head>+<body>+ <script>+ let isPortrait = false; // Track the current orientation++ const existingUrls = new Set();+ const rectangles = new Map();+ const MIN_DIMENSION = 360; // Minimum dimension (width for landscape, height for portrait)++ async function fetchDevices() {+ try {+ console.log('Fetching devices...');+ const response = await fetch('/get-devices');+ const devices = await response.json();+ console.log('Devices fetched:', devices);+ const newUrls = new Set(devices.map(ip => `http://${ip}`));++ newUrls.forEach(url => {+ if (!existingUrls.has(url)) {+ existingUrls.add(url);+ const rect = createRectangle(url);+ rectangles.set(url, rect);+ updateURL();+ }+ });++ [...existingUrls].forEach(url => {+ if (!newUrls.has(url)) {+ removeRectangle(url);+ existingUrls.delete(url);+ rectangles.delete(url);+ updateURL();+ }+ });+ } catch (error) {+ console.error('Error fetching devices:', error);+ }+ }++ function removeRectangle(url) {+ const rect = rectangles.get(url);+ if (rect) {+ const rectHeight = rect.offsetHeight;+ rect.remove();++ if (window.innerWidth <= 600) {+ const allRectangles = Array.from(document.querySelectorAll('.container'));+ let currentTop = 0;+ allRectangles.forEach(rectangle => {+ rectangle.style.top = `${currentTop}px`;+ currentTop += rectangle.offsetHeight + 2;+ });+ currentTopPosition = currentTop;+ }++ console.log('Removed element from DOM:', rect);+ } else {+ console.warn('Rectangle not found for URL:', url);+ }+ }++ function startPolling() {+ const pollingInterval = 5000;+ setInterval(fetchDevices, pollingInterval);+ }++ function loadFromURL() {+ const params = new URLSearchParams(window.location.search);+ params.forEach((value, url) => {+ const rectInfo = JSON.parse(value);+ const rect = createRectangle(url);+ rect.style.left = rectInfo.left;+ rect.style.top = rectInfo.top;+ rect.style.width = rectInfo.width;+ rect.style.height = rectInfo.height;+ rect.dataset.portrait = rectInfo.portrait ? "true" : "false";+ rectangles.set(url, rect);+ existingUrls.add(url);+ });+ }++ document.addEventListener('DOMContentLoaded', () => {+ loadFromURL();+ fetchDevices();+ startPolling();+ });++ let currentTopPosition = 0;+ function createRectangle(url) {+ const rectangle = document.createElement('div');+ rectangle.className = 'container';++ if (window.innerWidth <= 600) {+ rectangle.style.left = '0';+ rectangle.style.width = '100%';+ const screenWidth = window.innerWidth;+ const rectangleHeight = screenWidth * (9 / 16);+ rectangle.style.height = `${rectangleHeight}px`;+ rectangle.style.top = `${currentTopPosition}px`;+ currentTopPosition += rectangleHeight + 2;+ } else {+ rectangle.style.left = `${Math.random() * (window.innerWidth - MIN_DIMENSION)}px`;+ rectangle.style.top = `${Math.random() * (window.innerHeight - (MIN_DIMENSION * 9 / 16))}px`;+ rectangle.style.width = `${MIN_DIMENSION}px`;+ rectangle.style.height = `calc(${MIN_DIMENSION}px * 9 / 16)`;+ }++ const iframe = document.createElement('iframe');+ iframe.src = url;+ const handle = document.createElement('div');+ handle.className = 'handle';+ const dragLeft = document.createElement('div');+ dragLeft.className = 'drag-left';+ const dragRight = document.createElement('div');+ dragRight.className = 'drag-right';++ rectangle.append(iframe, handle);+ if (window.innerWidth > 600) {+ rectangle.append(dragLeft, dragRight);+ addDragListeners(dragLeft, rectangle);+ addDragListeners(dragRight, rectangle);+ }++ document.body.appendChild(rectangle);+ addResizeListeners(handle, rectangle);+ return rectangle;+ }++ function addResizeListeners(handle, rectangle) {+ handle.addEventListener('mousedown', (e) => startResize(e, rectangle));+ handle.addEventListener('touchstart', (e) => startResize(e, rectangle));+ }++ function addDragListeners(handle, rectangle) {+ handle.addEventListener('mousedown', (e) => startDrag(e, rectangle));+ handle.addEventListener('touchstart', (e) => startDrag(e, rectangle));+ }++ function startDrag(e, rectangle) {+ e.preventDefault();+ let offsetX = (e.touches ? e.touches[0].clientX : e.clientX) - rectangle.offsetLeft;+ let offsetY = (e.touches ? e.touches[0].clientY : e.clientY) - rectangle.offsetTop;++ function drag(e) {+ let clientX = e.touches ? e.touches[0].clientX : e.clientX;+ let clientY = e.touches ? e.touches[0].clientY : e.clientY;+ rectangle.style.left = `${clientX - offsetX}px`;+ rectangle.style.top = `${clientY - offsetY}px`;+ }++ function stopDrag() {+ document.removeEventListener('mousemove', drag);+ document.removeEventListener('mouseup', stopDrag);+ document.removeEventListener('touchmove', drag);+ document.removeEventListener('touchend', stopDrag);+ rectangle.querySelector('iframe').style.pointerEvents = "auto";+ updateURL();+ }++ rectangle.querySelector('iframe').style.pointerEvents = "none";+ document.addEventListener('mousemove', drag);+ document.addEventListener('mouseup', stopDrag);+ document.addEventListener('touchmove', drag);+ document.addEventListener('touchend', stopDrag);+ }++ function startResize(e, rectangle) {+ e.preventDefault();+ let startX = e.touches ? e.touches[0].clientX : e.clientX;+ let startWidth = rectangle.offsetWidth;+ let startHeight = rectangle.offsetHeight;+ let isPortrait = rectangle.dataset.portrait === "true";++ function resize(e) {+ let clientX = e.touches ? e.touches[0].clientX : e.clientX;+ let newWidth = startWidth + (clientX - startX);+ let newHeight;++ if (isPortrait) {+ newHeight = Math.max(MIN_DIMENSION, newWidth * (16 / 9));+ newWidth = newHeight * (9 / 16);+ } else {+ newWidth = Math.max(MIN_DIMENSION, newWidth);+ newHeight = newWidth * (9 / 16);+ }++ if (Math.abs(parseFloat(rectangle.style.width) - newWidth) > 1 ||+ Math.abs(parseFloat(rectangle.style.height) - newHeight) > 1) {+ rectangle.style.width = `${newWidth}px`;+ rectangle.style.height = `${newHeight}px`;+ }+ }++ function stopResize() {+ document.removeEventListener('mousemove', resize);+ document.removeEventListener('mouseup', stopResize);+ document.removeEventListener('touchmove', resize);+ document.removeEventListener('touchend', stopResize);+ rectangle.querySelector('iframe').style.pointerEvents = "auto";+ updateURL();+ }++ rectangle.querySelector('iframe').style.pointerEvents = "none";+ document.addEventListener('mousemove', resize);+ document.addEventListener('mouseup', stopResize);+ document.addEventListener('touchmove', resize);+ document.addEventListener('touchend', stopResize);+ }++ function addEventListeners(handle, downEvent, moveEvent, upEvent) {+ handle.addEventListener(downEvent, (e) => {+ e.preventDefault();+ isResizing = true;+ startX = e.touches ? e.touches[0].clientX : e.clientX;+ startY = e.touches ? e.touches[0].clientY : e.clientY;+ startWidth = handle.parentElement.offsetWidth;+ startHeight = handle.parentElement.offsetHeight;+ handle.parentElement.querySelector('iframe').style.pointerEvents = "none";+ document.addEventListener(moveEvent, resize);+ document.addEventListener(upEvent, stopResize);+ document.body.style.cursor = "nwse-resize";+ });+ }++ window.addEventListener('message', (event) => {+ const message = event.data;++ if (message.type === 'videoContainerUpdate') {+ const { portrait } = message;++ const iframes = document.querySelectorAll('.container iframe');+ let targetIframe = null;++ for (let iframe of iframes) {+ if (iframe.contentWindow === event.source) {+ targetIframe = iframe;+ break;+ }+ }++ if (!targetIframe) return;+ const rectangle = targetIframe.closest('.container');+ if (!rectangle) return;++ const currentIsPortrait = rectangle.dataset.portrait === "true";+ if (currentIsPortrait === portrait) return;++ rectangle.dataset.portrait = portrait ? "true" : "false";++ if (window.innerWidth <= 600) {+ const currentWidth = rectangle.clientWidth;+ const newHeight = portrait+ ? Math.max(MIN_DIMENSION, currentWidth * (16 / 9))+ : Math.floor(currentWidth * (9 / 16));+ rectangle.style.height = `${newHeight}px`;++ const allRectangles = Array.from(document.querySelectorAll('.container'));+ let currentTop = 0;++ for (let i = 0; i < allRectangles.length; i++) {+ const rect = allRectangles[i];+ rect.style.top = `${currentTop}px`;+ currentTop += rect.clientHeight + 2;+ }++ const lastRectangle = allRectangles[allRectangles.length - 1];+ const lastRectangleBottom = parseInt(lastRectangle.style.top, 10) + lastRectangle.clientHeight;+ document.body.style.overflowY = 'scroll';+ document.body.style.minHeight = `${lastRectangleBottom}px`;+ } else {+ const currentWidth = rectangle.offsetWidth;+ const currentHeight = rectangle.offsetHeight;++ if (portrait) {+ // Switching to portrait: base on current height or min dimension+ const baseHeight = Math.max(MIN_DIMENSION, currentHeight);+ const newWidth = baseHeight * (9 / 16);+ const newHeight = baseHeight;+ rectangle.style.width = `${newWidth}px`;+ rectangle.style.height = `${newHeight}px`;+ } else {+ // Switching to landscape: base on current width or min dimension+ const baseWidth = Math.max(MIN_DIMENSION, currentWidth);+ const newHeight = baseWidth * (9 / 16);+ const newWidth = baseWidth;+ rectangle.style.width = `${newWidth}px`;+ rectangle.style.height = `${newHeight}px`;+ }+ }+ updateURL();+ }+ });++ function updateURL() {+ const params = new URLSearchParams();+ rectangles.forEach((rect, url) => {+ const rectInfo = {+ left: rect.style.left,+ top: rect.style.top,+ width: rect.style.width,+ height: rect.style.height,+ portrait: rect.dataset.portrait === "true"+ };+ params.append(url, JSON.stringify(rectInfo));+ });+ window.history.replaceState({}, '', `${window.location.pathname}?${params}`);+ }+ </script>+</body>+</html>