Documentation Index
Fetch the complete documentation index at: https://mintlify.com/estebanrfp/gdb/llms.txt
Use this file to discover all available pages before exploring further.
GenosRTC API Reference
EveryGDB instance includes a powerful internal P2P module called GenosRTC. This module is exposed via the db.room object and provides a high-level API for real-time peer-to-peer (P2P) communication using WebRTC. It is designed for sending data streams, audio, and video directly between users’ browsers in a decentralized manner.
Getting Started
To use the P2P functionalities, simply import and instantiateGDB. The GenosRTC API is automatically available via the db.room object on your database instance.
The db.room API
The db.room object is your main interface for all P2P interactions powered by GenosRTC.
Event Handling
Listen to room events to know when peers join or leave, and when they send media streams.db.room.on(eventName, callback)
Registers a callback function for a specific event.
eventName{string}: The name of the event ('peer:join','peer:leave','stream:add').callback{Function}: The function to execute.
-
peer:join: Fires when a new peer joins the room.- Callback:
(peerId: string, type?: string) => void—typeidentifies the peer’s declared kind (e.g.'superpeer'for a Fallback Server);undefinedfor regular peers. Informational — do not use it for trust decisions.
- Callback:
-
peer:leave: Fires when a peer disconnects.- Callback:
(peerId: string) => void
- Callback:
-
stream:add: Fires when a peer sends aMediaStream(audio/video).- Callback:
(stream: MediaStream, peerId: string, metadata?: any) => void
- Callback:
Data Channels
Data channels are perfect for sending messages, coordinates, game states, or any kind of custom information.db.room.channel(type)
Creates or connects to a named data channel. This is the recommended way to send structured data.
type{string}: Channel identifier in UTF‑8 (max 12 bytes — longer names throw).- Returns: A
channelobject.
channel.send(data, targets?)
Sends data through the channel.
data: Any serializable data (JSON, string, binary).targets{string | string[]}: (Optional) A single peer ID or an array of peer IDs. If omitted, sends to all.
channel.on('message', callback)
Registers a callback to fire when a full message is received.
- Callback:
(data, peerId) => void
Media Streams (Audio/Video)
Methods for managing the sending ofMediaStream objects.
db.room.addStream(stream, targets?, meta?): Sends yourMediaStream(e.g., from a webcam) to peers.db.room.removeStream(stream, targets?): Stops sending a stream.db.room.replaceTrack(oldTrack, newTrack, stream, targets?): Replaces a track in a stream (e.g., to switch cameras or mute/unmute).
Room & Peer Management
db.room.leave(): Disconnects the local user from the room and all peers.db.room.getPeers(): Returns an object of the activeRTCPeerConnectionobjects, keyed bypeerId.db.room.ping(peerId): Measures the latency (in ms) to a specific peer. Returns a promise that resolves with the round-trip time.
🔷 Cellular Mesh Network
For massive scalability, GenosRTC includes a Cellular Mesh Overlay that organizes peers into “cells” with bridge nodes for inter-cell communication, reducing connections from O(N²) to O(N).Enabling
Mesh API
Mesh Events
Scalability
| Metric | Standard | Cellular (10k peers) |
|---|---|---|
| Connections/peer | ~10,000 | ≈ cell size + bridges (tens) |
| Message hops | 1 | ~10 |
| Max peers | ~100 | Massive scale |
When to Use
| Peers | Recommendation |
|---|---|
| < 100 | rtc: true |
| 100+ | rtc: { cells: true } |
Note: All peers should use the same cells configuration for optimal performance.