Building Halalmegle

What began as a hyperbole amid a discussion theorizing reverse-Salafism later turned into a fun weekend project. Halalmegle is a random video chat where each person is visible only through a slit around the eyes.

The idea started, and mindfully stayed, as a safer Omegle-style random chat. The burqa creates the layer of safety and modesty while still letting people enjoy meeting someone new. In a post-COVID society, that is an important utility: it helps Gen Z rebuild the community and social skills lost during the pandemic by embracing Islamic values.

Modesty is a security property, not just a visual effect. The most important part was keeping people safe from the indecent exposure that plagues Omegle-style sites like Monkey. The system is built so that only the filtered canvas enters the call. There’s no trust between sender and receiver, so incoming frames are checked on the viewer’s device before they’re drawn. The server never sees the raw media either: it only pairs people and relays call setup, and the rest is peer to peer.

   
Live halalmegle.com
Stack Vanilla JS, MediaPipe Face Landmarker, Canvas 2D, WebRTC, Node.js (zero dependencies)
Hosting Fly.io single machine, Cloudflare TURN relay, GitHub Actions CI
Platform Web only, phone and desktop browsers
Built October 28–29, 2026, solo

Architecture

The whole app is three files:

File Role
index.html The single-page client
guard.js The frame checker
server.js A ~400-line, dependency-free Node.js server

Halalmegle architecture: media never touches the server; only call setup does

The sender’s browser runs face tracking and paints a white frame with a tilted slit cut around the eyes. Only that canvas stream and the microphone go into the RTCPeerConnection. The viewer’s browser plays the incoming track in a hidden <video>, copies each frame, checks it, and draws it to a visible canvas only if it passes. The server’s job is matchmaking and call setup. Once two browsers are connected, it is out of the media path entirely.

Request flow

Endpoint What it does
POST /connect Returns an opaque client ID (refused if the hashed IP is blocked or rate-limited)
POST /poll Long poll held open up to 25 seconds; delivers queued messages
POST /join Enters the matching queue; the matcher pairs the oldest compatible people and picks the WebRTC initiator
POST /signal Relays offers, answers and ICE candidates, tagged with a per-call match ID
POST /report Files a report against your most recent call
GET /ice Short-lived STUN/TURN credentials
GET /healthz { ok, online, waiting } for the platform health check

The per-call match ID on /signal means a late message from a previous call can’t land in the next one.

Decisions

Every major choice came down to two questions:

  1. Where must this logic run so the guarantee can’t be bypassed?
  2. What is the cheapest way to run it there?
Decision What I chose Why What I rejected Why the rejected path breaks later
Where filtering happens Sender’s device, before encoding The only point where the raw camera exists; face tracking runs on the user’s own GPU for free Server-side filtering (media server + ML) The server receives raw faces, so a breach or legal request violates question one; GPU media servers violate question two
Trust model Viewer re-checks every frame The receiving browser is the one place a malicious sender can’t reach; the shape check is cheap (64×64) and model-free Trusting the sender’s filter The guarantee is only as strong as the least honest user; anyone can open DevTools and send the raw camera
Media transport Peer-to-peer WebRTC, TURN as fallback Lowest latency, video stays off my infrastructure, bandwidth costs nothing Always-relayed media Bandwidth becomes the dominant cost and all media sits on my side of the trust boundary
Signaling HTTP long polling A few small messages per call; works through every proxy, network and tunnel; zero dependencies; one open poll = one person online on Fly WebSockets Adds a dependency and a class of proxy and timeout failures for no user-visible gain
Server state In memory, one instance One source of truth for who is waiting; blocks rebuilt from the reports log on restart Redis or a database Only earns its place with multiple instances, which this traffic doesn’t need
Failure mode Fail to white An occasional blank second, but no glitch can ever show more than intended Hold the last mask, or fall back to raw Leaks exactly when someone moves quickly or a second person steps into view

The landmark output is checked before a slit is cut: the two eyes must be a plausible distance apart and each eye’s width must fall between 20% and 80% of that distance. Otherwise the frame is blank. The slit is also hard-capped (60% of frame width, 16% of frame height) so a legitimate sender can never produce a frame the receiver’s guard would reject. The sender’s limits and the receiver’s limits were designed as a pair, and a test covers “the largest slit the sender allows, tilted” to keep them in sync.

Landmarks are computed on the exact video frame that gets masked, gated on currentTime changing. Running detection asynchronously on a stale frame would let the mask trail a fast head turn by a frame or two, which is exactly when skin outside the slit would leak.

IPs are stored only as salted SHA-256 hashes, and production refuses to boot without a 32+ character salt or a contact email. Reports keep at most 20 messages of 500 characters each and are pruned after 90 days on startup.

Hard problems

The hardest problem was deciding, on every single frame, whether a compressed video frame from an untrusted peer shows only the burqa filter.

1. A frame checker that survives video compression

The guard can’t run face detection on the incoming stream: a modified client could send a face that a model fails to find. Instead, it checks the shape of what’s not white, which is something the sender can’t fake without also failing the check.

  1. Copy the frame once into a buffer, so the frame checked is the frame shown (no time-of-check/time-of-use gap).
  2. Downsample to 64×64 and count “ink” pixels: any channel below 225. The threshold sits well below white, so codec noise and ringing in the white area don’t count.
  3. Reject if more than 45% of the frame is ink. A raw camera frame fails here.
  4. Reject if the 90th-percentile column height exceeds 50% of the frame. This catches a tall region that covers little area, such as a face pushed into a narrow strip. Using the 90th percentile instead of the max means a few noisy columns can’t hide a frame.
export const LIMITS = {
  maxFill: 0.45,   // share of the whole frame that may be non-white
  maxColumn: 0.5,  // share of a column's height that may be non-white
};

A rejected frame is never drawn. The “video hidden” note only appears after a block lasts a full second, so someone walking past in the background doesn’t trigger a scary warning. The test suite covers raw frames, tall regions, wide bands, a tilted maximum slit, light noise, and an all-white frame.

2. Keeping the sender’s and receiver’s rules in lockstep

Two independent limits (the sender’s slit cap and the receiver’s guard thresholds) create a classic drift bug: tighten one later and honest users start getting hidden. I treated them as one contract. The sender caps the slit below what the guard accepts, and a test asserts that the largest legal slit, tilted, still passes.

3. Zooming onto eyes the viewer can’t see

Each tile zooms onto the eyes, but the viewer has no landmarks for the stranger. The guard’s inkBounds reuses the same pass to find the bounding box of the non-white area, ignoring rows with fewer than 3 ink pixels and columns with fewer than 2. The zoom box eases 25% toward its target each frame and never zooms past 30% of frame width, so it doesn’t jitter or turn to mush.

4. Connecting on hostile networks

Direct P2P fails on many mobile carriers and school or office networks. The server fetches short-lived Cloudflare TURN credentials (cached for an hour, 5-second timeout, STUN-only fallback on failure). One detail: Cloudflare returns some relay URLs on port 53, which browsers block. Those entries only slowed connection setup, so the server strips them before handing the list to clients.

5. Matchmaking edge cases

Problem Fix
Stale messages: a late ICE candidate from the previous stranger can corrupt the next connection Each call gets a fresh match UUID; /signal drops anything whose match ID doesn’t equal the sender’s current call
Instant re-matches: with few people online, “Next” would often reconnect the same two people The matcher refuses to pair the same two within 30 seconds
Ghost users: closed tabs and dropped connections Anyone who stops polling for 40 seconds is removed; the queue is re-matched every 5 seconds
Telling a blocked user why The client is flagged closing and kept just long enough for the “banned” message to reach their open poll, then removed

Trust, safety and security

Random video chat is a high-abuse category, so I started from a threat model rather than a feature list. Each threat maps to a control that runs where the attacker can’t switch it off.

Threat Control Where it runs
Unfiltered video from a modified client The frame guard checks every incoming frame and never draws one that shows more than an eye slit Viewer’s browser
A filter glitch that exposes a face Fail to white on lost, multiple or implausible faces; capped slit size Sender’s browser
Harassment or explicit behavior One-tap report (nudity, underage, harassment, spam, other) with the last 20 chat messages attached Client → server
Brigading one user with fake reports Block only after 3 different reporters in 24 hours; one report per reporter per call; only against your own most recent call Server
Evading a block by waiting for a restart Blocks rebuilt on boot from the append-only reports log Server
Flooding and scraping Per-route rate limits per hashed IP; 64 KB body cap; 200-message inbox cap; 5,000-client ceiling Server
XSS, clickjacking and injected third-party scripts Strict CSP (scripts only from self and jsDelivr, models only from Google storage), frame-ancestors 'none', nosniff, no-referrer, same-origin opener policy, HSTS over HTTPS Server headers
Path traversal on static files Every path is normalized and must resolve inside public/, or 404 Server
Identifying users from logs Salted, truncated SHA-256 IP hashes only; no accounts; reports older than 90 days deleted on start Server

Outcomes and lessons

Halalmegle went from first commit to a live production site on its own domain over October 28 and 29, 2026. halalmegle.com, HTTPS with auto-renewing certificates, a health check every 30 seconds, and documented runbooks for deploys, secrets and moderation, all shipped.

   
Tests 16 automated tests: 8 for the frame guard, 8 for matching, reports, blocks, rate limits, security headers and the health endpoint
CI Node 22 and 24, plus a Docker build, on every push
Infrastructure One shared-CPU machine with 256 MB of RAM that scales to zero when nobody is online
Cost shape Media is peer to peer, so server cost doesn’t grow with call length

Put the guarantee where the attacker isn’t. The sender’s filter is a UX feature; the receiver’s guard is the security control. Designing both as one contract is what makes Halalmegle’s promise hold.

Fail closed, visibly. Every uncertain state shows white, and the UI tells the user why (“No face found · they see white”) after a short delay so blinks don’t flash warnings.

Boring infrastructure is a feature. Zero dependencies, long polling and one in-memory instance removed whole classes of problems (supply-chain risk, socket proxies, distributed state) for a product that doesn’t need them.

Call History

More Software

© 2026 Omair Khattak · RSS