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.
Streaming with GenosRTC
The Streaming feature inGDB, powered by GenosRTC, enables real-time communication and data synchronization between connected peers. This functionality is particularly useful for applications that require live updates, such as collaborative tools, multiplayer games, or real-time tracking systems.
Overview
Verify that WebRTC is enabled
GenosDB requires an active WebRTC environment to establish peer-to-peer connections.You can quickly check whether your browser supports WebRTC using the following external tool:
WebRTC Leak Test
URL: https://browserleaks.com/webrtcDescription: This page detects whether your browser has WebRTC enabled and shows the IP addresses exposed through WebRTC. If the tool reports that WebRTC is disabled or blocked, GenosDB will not be able to initiate P2P communication.
Finding public, private, and paid Nostr relays
When using custom relay configurations through therelayUrls option, developers may need a reliable directory of active Nostr relays. This is useful for selecting high-availability relays, building private relay sets, or evaluating which relays to include for production environments.
You can explore and filter available relays using the following external resource:
Nostr Relay Finder
URL: https://legacy.nostr.watch/relays/findDescription: A searchable directory of Nostr relays that includes information about availability, latency, geographic distribution, access policies, pricing, and stability. This resource helps developers select the appropriate relays to include in the
relayUrls array when configuring GenosDB.
Streaming allows peers (clients) to send and receive data in real time through shared communication channels. Each peer can publish data to a channel, and all other connected peers will receive the updates instantly. This ensures that all participants in the system stay synchronized with minimal latency.
Key Concepts
- Peers: Clients connected to the same
room. Each peer has a unique identifier (peerId) to distinguish it from others. - Data Channels: Logical communication pathways where structured data is exchanged. Peers create or connect to a named channel to send and receive messages.
- Media Streams: Media flows (audio/video) that can be sent directly to other peers.
How It Works
-
Initialization:
- A peer initializes
GDB. The database name serves as theroomID. - Upon instantiation, the peer automatically joins the room and begins discovering other peers.
- A peer initializes
-
Data Publishing:
- A peer can send data through a named data channel (
Data Channel). - The data is broadcast to all other peers in the room or to specific targets.
- A peer can send data through a named data channel (
-
Data Subscription:
- Peers listen for
messageevents on a channel to receive incoming data. - When new data is received, the peer processes it according to its application logic.
- Peers listen for
-
Peer Lifecycle:
- Peers can join or leave the room dynamically.
- The system provides events (
peer:join,peer:leave) to notify when a peer connects or disconnects.
Use Cases
- Real-Time Collaboration: Enable multiple users to edit or interact with shared content simultaneously.
- Live Tracking: Track the movement or status of objects in real time, such as GPS coordinates or game character positions.
- Notifications: Broadcast alerts or updates to all connected clients instantly.
Example Workflow
Below is a generic example demonstrating how to use the Streaming feature in your application, adapted to the GenosRTC API.Audio Streaming
Audio streaming allows peers to broadcast their microphone audio to other connected peers in real time. This is ideal for applications like voice chat, conference calls, or live audio broadcasting.Example: Real-Time Audio Streaming
Explanation
- Microphone Access:
getUserMediacaptures the user’s microphone audio. - Broadcasting Audio: The
db.room.addStream(stream)method sends the audioMediaStreamto all peers in the room. GenosRTC automatically handles sending the stream to new peers who join later. - Receiving Audio: The
db.room.on('stream:add', callback)event fires for incoming streams. The audio is played back using an<audio>element. - Cleanup: When a peer leaves (
peer:leave), their audio stream is paused, and the reference is removed.
Video Streaming
Video streaming allows peers to broadcast their webcam video to other connected peers in real time, ideal for video conferencing, live streaming, or remote collaboration.Example: Real-Time Video Streaming
Explanation
- Webcam Access:
getUserMediacaptures the user’s webcam video and audio. - Broadcasting Video:
db.room.addStream(stream)sends theMediaStreamto all peers. - Receiving Video: The
db.room.on('stream:add', ...)event handles incoming streams, which are displayed using<video>elements. - Cleanup: When a peer leaves (
peer:leave), their video element is removed from the DOM.
File Streaming
File streaming allows peers to send and receive files using GenosRTC’s Data Channels. You can build support for metadata, progress updates, and secure encryption on top of this foundation.Example: Real-Time File Streaming
This example demonstrates file transfer usingdb.room.channel.
Explanation
- Data Channel: We create a specific channel (
file-transfer) to handle file transfers, keeping them separate from other data like chat messages. - Metadata Support: Metadata (like file name, type, and a unique ID) is packaged into a single object along with the file content (
ArrayBuffer). This entire object is what’s sent through the channel. - Broadcasting Files: The
fileChannel.send()method transmits the object (metadata + payload) to all peers in the channel. - Receiving Files: The
fileChannel.on('message', ...)event receives the object. The recipient can then extract the metadata and payload to reconstruct and save the file. - Encryption: By initializing
GDBwith apassword, all data channel communications, including files, are end-to-end encrypted.
Best Practices & Considerations
- File Size Limits & Chunking: WebRTC data channels have a message size limit (which varies by browser, but is often around 256KB). For larger files, you must implement “chunking”: splitting the file into smaller pieces, sending them sequentially, and reassembling them on the receiver’s end.
- Progress Feedback: The base
db.room.channelAPI does not provide built-in progress tracking. If you implement chunking, you can also send progress messages through the same channel to create a progress bar. For example:fileChannel.send({ type: 'progress', fileId: '...', percent: 50 }). - Error Handling: Add logic to manage cases where file transfers fail due to network issues or peer disconnections.
- Handling Multiple Transfers: To differentiate between simultaneous transfers, include a unique identifier in the metadata for each file (e.g.,
{ id: 'unique-file-123' }). This allows both sender and receiver to track the state and progress of each file independently.
Cellular Mesh for Large-Scale Applications
For applications expecting 100+ concurrent peers, GenosRTC includes a Cellular Mesh overlay that organizes peers into cells with bridge nodes, reducing connections from O(N²) to O(N).| Scenario | Recommendation |
|---|---|
| Small team collaboration (< 50) | rtc: true |
| Medium rooms (50-100) | Either works |
| Large event/webinar (100+) | rtc: { cells: true } |
| Massive multiplayer (1000+) | rtc: { cells: { bridgesPerEdge: 3 } } |
- genosrtc-api-reference.md — Quick API reference
- genosrtc-cells.md — Full technical documentation (architecture, metrics, TTL, bridges)