buffer. * Elegance through simplicity/reuse; perfection costs complexity, aim for acceptable thresholds. * >>> ACTIVELY MINIMIZE HTTP requests, the server should aim to recieve and send ONE packet per user! <<< * >>> DO NOT INTRODUCE NEW FILES. * >>> ONLY ONE BLOB PER USER COMING IN (two when bridging). ONLY 1-2 BLOBS PER USER GOING OUT. * >>> ONLY ONE KYC FOLDER PER IP, CONTAINING A SINGLE METADATA TEXT FILE, AND 1% OF THEIR SPRITESHEETS! <<< * >>> DO NOT DEVIATE FROM THIS 'DO NOT DELETE/REMOVE' BLOCK! IT IS CORRECT, YOUR CODE IS NOT. * * BLOB FORMAT: [4:vLen][JPEG×9][4:aLen][G.711 μ-law uint8 mono (8kHz default; 16kHz in HD mode, tail: sr=16000)][UTF-8 tail: key=value\n...] * Tail keys: seq, head, msg, msg_ts, bridge_target, sr * Content: 9 frames (2304ms @ 256ms/frame) + 2304ms audio (9 chunks @ 256ms, 8kHz/16kHz G.711 μ-law) + last chat msg. * Push: one blob/1000ms per client via HTTP, fire-and-forget. Upload loop starts at first camera/mic grant; * ticks are no-ops until at least one panel is seeking or connected. Idle client produces no blobs. * Server: holds ONE blob/user in RAM (new replaces old), reads FILENAME+SIZE+TAIL only — never processes * content. Filename+size MUST encode all routing metadata for the server decision (Send/Drop/Save). * * PLAYBACK: Head-anchored jitter buffer. Frames scheduled by ABSOLUTE sender-frame * index (head/firstAbs), not arrival time — playback advances monotonically across * overlapping blobs, no reset-to-0 judder when a new blob arrives. * Natural overlap: 2304ms blob duration vs ~1000ms arrival interval = ~1300ms buffer depth. * Timeline draws whichever blob covers the current absolute frame — no skip, no discard * of overlap frames. AUDIO IS BONDED TO VIDEO: each 256ms audio chunk is keyed to the same * absolute frame index as its video frame and played once, in sync with that frame (NOT a * 2304ms blast on arrival). Overlapping blobs carry duplicate chunks — each abs index plays once. * Duplicate: same seq as previous → skip. Exhausted with no new blob → blank/silence (no loop). * STALENESS: one counter per panel, bumped on any fetch yielding no NEW frame (404/204 = * no file, or duplicate seq = peer upload stalled), reset on a fresh seq. Phantom match * (never received a frame) re-seeks at 7; an established peer is declared gone at 15. * seq (tail key) used for dedup; head (tail key) drives frame scheduling. * * IDENTITY: Client generates UUID once → localStorage as MY_BASE (deviceId). Stable across reloads. * Without stable peerId: every reload creates a new sprite file, directory bloats with orphans, * glob() in match scan slows down, GET /sprite latency climbs — observed runaway slowdown. * Same user always overwrites same sprite file; directory size = unique devices ever seen. * No sessions, no cookies, no server fingerprinting, no salt, no PHP $_SESSION. * Two browsers = two IDs, no NAT collision. localStorage ≠ cookie; disclaimer holds. * NOTE: KYC is separate from identity — sharded by IP, saves a fingerprint with every ~100th * spritesheet received (probabilistic). Has no relation to localStorage deviceId. * * STORAGE: * Ephemeral: /dev/shm/nosignup/sprite/{peerId}.bin (fallback: sys_get_temp_dir) * ONE blob per user in RAM. Flat directory, no subdirectories ever. * Routing state goes in the filename (_S for seeking only). * No cleanup logic needed. Reboot wipes it. * Persistent: /var/lib/nosignup/kyc/{crc32(IP)}/metadata.log + sample.jpg * 1-in-100 sample via mt_rand — 99% of uploads skip all KYC I/O. * ONE folder per IP, ONE metadata text file, ONE sample spritesheet (overwritten). * Lazy delete: mtime > 365d → unlink on next access. No cron, no counter file. * * POLLING: Simple setInterval. No ETag, no 304. * CAMERA: Hardcoded center crop 0.75 → downscale to 80×60. 3×3 spritesheet, JPEG q=0.50. No slider. * MATCHING: Stateless. Seek/match routing encoded in filename; bridge routing via tail. * * BRIDGE: Operator sets bridge_target={peerId} in tail. /sprite checks target's tail; if fresh, * serves that file transparently instead. Operator's own fetch (targetId=remoteId) unaffected. * * CHAT: Push to feed only if message differs from last received. * DIAGNOSTICS: Verbose stats overlay, opt-in checkbox, persisted in localStorage. Default OFF. * DEVELOPMENT: Correctness first, minify after. * --------------------------------------------------------------------------------- * DO NOT DELETE/REMOVE THIS BLOCK - NOSIGNUP.CHAT — DO NOT DELETE/REMOVE THIS BLOCK * --------------------------------------------------------------------------------- */ // ===== BLOCK 1: PHP CONFIG + STORAGE DIRS ===== error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 1); $SPRITE_DIR = '/dev/shm/nosignup/sprite'; $KYC_BASE = '/var/lib/nosignup/kyc'; if (!is_dir($SPRITE_DIR) && !@mkdir($SPRITE_DIR, 0755, true)) { $SPRITE_DIR = sys_get_temp_dir() . '/nosignup_sprite'; @mkdir($SPRITE_DIR, 0755, true); } if (!is_dir($KYC_BASE) && !@mkdir($KYC_BASE, 0755, true)) { $KYC_BASE = sys_get_temp_dir() . '/nosignup_kyc'; @mkdir($KYC_BASE, 0755, true); } function lazy_expire($path) { if (file_exists($path) && (time() - filemtime($path)) > 86400 * 365) { @unlink($path); } } // sprite_info() — returns [$path, $mtime, $size] or null. function sprite_info($pid) { global $SPRITE_DIR; $pid = preg_replace('/[^a-zA-Z0-9_\-]/', '', $pid); if (strlen($pid) < 8) return null; $file = "$SPRITE_DIR/$pid.bin"; if (!is_file($file)) return null; $mt = @filemtime($file); $sz = @filesize($file); if ($mt === false || $sz === false) return null; return [$file, $mt, $sz]; } function blob_tail_get($blob, $key) { $n = strlen($blob); if ($n < 8) return null; $vLen = unpack('N', substr($blob, 0, 4))[1]; if ($vLen < 0 || 4 + $vLen + 4 > $n) return null; $aLen = unpack('N', substr($blob, 4 + $vLen, 4))[1]; $tailStart = 4 + $vLen + 4 + $aLen; if ($aLen < 0 || $tailStart > $n) return null; $tail = substr($blob, $tailStart); foreach (explode("\n", $tail) as $line) { $eq = strpos($line, '='); if ($eq !== false && substr($line, 0, $eq) === $key) { $v = substr($line, $eq + 1); return preg_replace('/[^a-zA-Z0-9_\-]/', '', $v); } } return null; } function log_kyc($peerId, $blob) { global $KYC_BASE; if (mt_rand(1, 100) !== 1) return; $pid = preg_replace('/[^a-zA-Z0-9_\-]/', '', $peerId); if ($pid === '') return; $ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0'; $ipDir = $KYC_BASE . '/' . sprintf('%08x', crc32($ip)); if (!is_dir($ipDir) && !@mkdir($ipDir, 0755, true)) return; $logFile = "$ipDir/metadata.log"; lazy_expire($logFile); @file_put_contents($logFile, time() . ",$pid,$ip\n", FILE_APPEND); if (strlen($blob) >= 4) { $vLen = unpack('N', substr($blob, 0, 4))[1]; if ($vLen > 0 && 4 + $vLen <= strlen($blob)) { @file_put_contents("$ipDir/sample.jpg", substr($blob, 4, $vLen)); } } } function write_sprite($pid, $blob) { global $SPRITE_DIR; $pid = preg_replace('/[^a-zA-Z0-9_\-]/', '', $pid); if (strlen($pid) < 8 || $blob === false || strlen($blob) === 0) return; @file_put_contents("$SPRITE_DIR/$pid.bin", $blob, LOCK_EX); $kpid = preg_match('/^(.+)_S$/', $pid, $m) ? $m[1] : $pid; log_kyc($kpid, $blob); } $a = $_GET['api'] ?? ''; if ($a !== '') { header('Cache-Control: no-store, no-cache, must-revalidate'); // ===== UPLOAD ===== if ($a === 'upload' && $_SERVER['REQUEST_METHOD'] === 'POST') { header('Content-Type: application/json'); // One blob, one or two destinations (tails identical — no bridge/chat). The client // always sends channel-suffixed peerIdL/peerIdR (never a bare peerId), so we only // need the per-channel writes below. if (isset($_FILES['blob'])) { $blobData = @file_get_contents($_FILES['blob']['tmp_name']); foreach (['L', 'R'] as $ch) { if (isset($_POST['peerId' . $ch])) { write_sprite($_POST['peerId' . $ch], $blobData); } } } // Bridge/chat case: per-panel blobs with different tails foreach (['L', 'R'] as $ch) { if (isset($_POST['peerId' . $ch], $_FILES['blob' . $ch])) { $blob = @file_get_contents($_FILES['blob' . $ch]['tmp_name']); write_sprite($_POST['peerId' . $ch], $blob); } } echo '{"ok":1}'; exit; } // ===== SPRITE FETCH ===== if ($a === 'sprite' && $_SERVER['REQUEST_METHOD'] === 'GET') { $pid = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_GET['peerId'] ?? ''); if (strlen($pid) < 8) { http_response_code(400); exit; } $now = time(); if (preg_match('/^(.+)_(L|R)_S$/', $pid, $m)) { $base = $m[1]; $ch = $m[2]; $candidates = []; foreach (glob("$SPRITE_DIR/*_{$ch}_S.bin") ?: [] as $f) { $other = basename($f, '.bin'); if ($other === $pid) continue; $mt = @filemtime($f); if ($mt === false) continue; // A live seeker rewrites its _S file every UPLOAD_MS (~1s). A _S file older // than ~3s belongs to a peer that already matched (and stopped seeking) but // whose file lingers until the 10s expiry — matching it reconnects to a ghost // ("silent reconnect to old peer / searching forever"). Require it to be fresh. if ($now - $mt > 3) continue; if (strpos($other, $base) === 0) continue; $candidates[] = $other; } if ($candidates) { $found = $candidates[array_rand($candidates)]; $remoteBase = preg_replace('/_S$/', '', $found); header('X-Match-Peer: ' . $remoteBase); header('Content-Type: application/octet-stream'); http_response_code(200); exit; } http_response_code(204); exit; } $info = sprite_info($pid); if ($info === null || ($now - $info[1]) > 10) { http_response_code(404); exit; } $blob = @file_get_contents($info[0]); if ($blob === false) { http_response_code(404); exit; } $bt = blob_tail_get($blob, 'bridge_target'); if ($bt !== null && $bt !== '' && $bt !== $pid) { $btInfo = sprite_info($bt); if ($btInfo !== null && ($now - $btInfo[1]) <= 10) { $btBlob = @file_get_contents($btInfo[0]); if ($btBlob !== false) $blob = $btBlob; } } header('Content-Type: application/octet-stream'); header('Content-Length: ' . strlen($blob)); echo $blob; exit; } http_response_code(404); exit; } // Source download — serves this file directly. No new files. if (isset($_GET['src'])) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="nosignup.php"'); header('Content-Length: ' . filesize(__FILE__)); readfile(__FILE__); exit; } ?>
one .php file. drop it on any PHP host.
no build step. no dependencies. it just runs.