Knock System Architecture & Telephony Engine

Deep technical blueprint mapping Knock's Hybrid Dual-Route calling engine (WebRTC vs Switch Telecom GSM), 16kbps Opus zero-rated audio codecs, Bi-Directional Voice Activity Detection (Bi-VAD), and automated escrow settlement.

Engine: Hybrid Dual-Route (Option B + C)
Audio Codec: 16kbps Mono Opus + FEC (~0.12 MB/min)
Wholesale SIP: Switch Telecom (sip.switchtel.co.za)
SMS Rail: SMSPortal Deduplicated
Database: Supabase PostgreSQL Pooler
πŸ—ΊοΈ Technical Schematic: Hybrid Dual-Route Calling Engine
● Live in server/telecomEngine.js Target: Vodacom β€’ MTN β€’ Cell C β€’ Telkom
Free Calling WebRTC and GSM Cellular Schematic
πŸ” Tap to expand high-resolution blueprint
01
πŸ“± Smart Keypad & Carrier Resolver

Normalizes raw input (082 123 4567, +2782...) into standard E.164. Detects network carrier based on prefix matching for Vodacom, MTN, Cell C, and Telkom.

const norm = normalizeSaPhone(rawInput);
// Returns: { cleanLocal, cleanIntl, carrier: 'VODACOM' }
02
🟒 Route C: 100% Free WebRTC Path

If destination is registered and online (active1to1Rooms.has(target)), resolves to Route C. Direct P2P audio/video with zero carrier bill and unlimited talk minutes.

route: 'OPTION_C',
costZar: 0.00, // 100% Free R0.00
action: 'INITIATE_P2P_WEBRTC'
03
🟠 Route B: 1-Time Courtesy GSM Call

If recipient is offline or has no app, routes over Switch Telecom wholesale SIP trunk (sip.switchtel.co.za) to ring their cellular phone. Hard-capped at 120 seconds.

route: 'OPTION_B', isCourtesyCall: true,
maxDurationSeconds: 120,
action: 'INITIATE_WHOLESALE_SIP'
04
πŸ”’ 2nd-Call Lockout & WhatsApp Invite

Subsequent dials to an offline number that has already used its courtesy call hit OPTION_B_LOCKED. Prompts a viral 1-tap WhatsApp invite link to onboard the contact.

route: 'OPTION_B_LOCKED',
action: 'PROMPT_APP_INVITE',
whatsappShareUrl: 'https://api.whatsapp.com/...'
05
🎑 GSM Minutes Bank & Rewards

Users make additional cellular calls using their earned GSM Minutes Bank. Funded by retail sponsor vouchers (+5m), daily wheel spins (+3 to 15m), and Capitec bank passes (+30m).

// server/rewardStore.js
wallet.earnedMinutes += 5; // per completed call
claimReward(handle, 'rew_nandos_01');
06
βœ‰οΈ Deduplicated SMS Invite Engine

After an Option B call ends, an automated SMS invite is fired via SMSPortal. A strict 30-day deduplication filter ensures numbers are never messaged twice, saving R0.24 per repeat call.

if (alreadyContacted) {
  return { sent: false, savedZar: 0.24 };
}
βš–οΈ Complete Routing State Decision Matrix
Scenario Recipient State Resolved Route Carrier / Protocol Max Duration Platform Cost User Action / Conversion
Registered Host Online Active WSS Socket OPTION_C P2P HD WebRTC (Opus 16kbps) Unlimited R0.00 Direct zero-cost voice/video call
First-Time Offline Number Offline / Not on App OPTION_B Switch Telecom SIP βž” GSM Cellular 120s (2 min cap) ~R0.18/min (Sponsor funded) Courtesy call + Automated viral SMS invite
Repeat Call (No Banked Mins) Offline / Courtesy Used OPTION_B_LOCKED Blocked (403 Forbidden) N/A R0.00 WhatsApp invite prompt + Spin Lucky Wheel
Repeat Call (With Banked Mins) Offline / Has Minutes DIRECT_GSM Switch Telecom SIP βž” GSM Cellular Exact Bank Balance Deducted from user bank Free cellular call using earned minutes
Peak Trunk Traffic (4 Lines Busy) Offline / Lines Full OPTION_B_BUSY Capacity Limit (503) N/A R0.00 "Lines busy" modal + WhatsApp skip queue
πŸŽ₯ Calling Functionalities & In-Call Collaboration Stack
● webrtc-engine.js + AnalyserNode Resolution: 1080p VP8 / H.264
Calling Functionalities and UI Schematic
πŸ” Tap to expand high-resolution blueprint
01
⚑ 1-on-1 Disposable Web-to-App

Single-use calling links (knock.at/profile). Guests tap once to call via mobile browser. No cell phone numbers are revealed to either party.

02
πŸ’° Paid Monetized Consultation

Gated by PayShap / Capitec Pay / Card. Locks call action until consultation fee clears into escrow. Protected by the 2-Minute Grace Cancellation window.

03
πŸ‘₯ Decentralized Group Mesh Rooms

Multi-peer audio rooms (/room/:id). Anonymous retro avatars with real-time glowing green speaking rings and floating haptic reaction emojis.

04
⭐ VIP Studio & Real-Time Watermark

Renders camera stream to HTML5 Canvas in real-time. Injects verified badge and promo watermark into video frames before saving to disk.

05
πŸ“Š Bi-Directional VAD (Bi-VAD)

Web Audio AnalyserNode tracks host vs guest speech volume in real time. If host stays silent for 60s, triggers a 30s auto-refund warning.

06
πŸ’¬ Ephemeral In-Call Chat Eraser

Real-time text chat over encrypted RTCDataChannel. The moment either party hangs up, the chat array is wiped from memory with zero trace.

🌐 End-to-End System Infrastructure & Network Topology
● Architecture Locked v4.0
πŸ—οΈ Multi-Tier System Topology Architecture

Knock operates as an Event-Driven Modular Monolith. High-level feature sets never invoke each other directly; they subscribe to asynchronous events emitted by the core WebRTC engine on the EventBus.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              KNOCK CLIENT LAYER                              β”‚
β”‚  β€’ Host Dashboard PWA   β€’ Guest Web Caller   β€’ Anonymous Group Mesh  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό (HTTPS REST / 3001)                       β–Ό (WSS WebSockets)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       EXPRESS REST API       β”‚            β”‚    WSS SIGNALING MESH ENGINE β”‚
β”‚ β€’ Payment & Escrow Checkout  β”‚            β”‚ β€’ SDP / ICE Candidate Relay  β”‚
β”‚ β€’ Link & Availability Store  β”‚            β”‚ β€’ Room State & Host Register β”‚
β”‚ β€’ Telemetry Audit Engine     β”‚            β”‚ β€’ VAPID Push Wakeup Dispatch β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚                                          β”‚
               β–Ό                                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  SUPABASE POSTGRESQL POOLER  β”‚            β”‚     COTURN NAT RELAY (3478)  β”‚
β”‚ β€’ hosts, links, transactions β”‚            β”‚ β€’ STUN / TURN UDP & TCP      β”‚
β”‚ β€’ contacted_recipients (SMS) β”‚            β”‚ β€’ Cellular CGNAT Traversal  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ’° Proof-of-Consultation (PoC) & Escrow Settlement Engine
● 85% Creator / 15% Platform Split
πŸ›‘ 2-Minute Grace Cancellation

If a client feels unsatisfied or called by mistake, they can tap [ End & 100% Refund ] within 120 seconds. The escrow hold releases funds back to the client immediately with zero creator fee.

πŸ“‰ Dropped Call Protection (< 30s)

Calls terminating under 30 seconds trigger AUTO_REFUNDED_CALL_TOO_SHORT. Prevents bad cellular connections from eating user funds.

πŸŽ™οΈ Silent Host Flagging (< 8% Speech)

If call duration is ≥ 60s but the host's Web Audio decibel energy account for less than 8% of the time, the escrow is paused with FLAGGED_ABSENTEE_HOST for dispute audit.

βœ… Settled Consultation (≥ 60s & ≥ 8%)

Funds clear instantly into Host Wallet. The server mints an immutable cryptographic token: knk_proof_... stored in the PostgreSQL ledger.