rift-web-chat
WebAssembly browser chat client for Rift over WebSocket relay.
This crate provides a simple, self-contained API for text-only encrypted chat in the browser. It connects to the rift-ws-relay WebSocket server and uses the same protocol framing and AES-GCM encryption as the rest of the Rift stack.
Features
- WebSocket transport via
web-sys- no additional JS dependencies - AES-GCM encryption compatible with existing Rift protocol
- Invite-based sessions - create/join with
rift://z/...invite URLs - Callback-based API for easy JavaScript integration
- Minimal footprint - compiles to ~50KB gzipped WASM
Installation
# Install wasm-pack
# Build for web
Usage
import init from './pkg/rift_web_chat.js';
await ;
// Create an invite for a new room
const invite = ;
console.log;
// Or inspect an existing invite
const info = ;
console.log;
// Connect to the relay
const chat = ;
// Set up event handlers
chat.;
chat.;
chat.;
chat.;
// Later: disconnect
chat.;
API
WebChat
Main chat client class.
| Method | Description |
|---|---|
new WebChat(relay_url, invite_url) |
Connect to relay and join room |
send(text) |
Send a text message |
on_message(callback) |
Set handler for incoming messages |
on_peer_event(callback) |
Set handler for join/leave events |
on_connect(callback) |
Set handler for connection established |
on_disconnect(callback) |
Set handler for disconnection |
on_error(callback) |
Set handler for errors |
disconnect() |
Close the connection |
peer_id |
Your peer ID (hex string) |
room |
Channel/room name |
session_id |
Session ID (hex string) |
is_connected |
Connection state |
Standalone Functions
| Function | Description |
|---|---|
create_invite(channel, password?) |
Generate a new invite URL |
inspect_invite(url) |
Parse invite without joining |
generate_peer_id() |
Generate a random peer ID |
Running the Relay
The relay listens on ws://localhost:8787/ws by default.
Protocol
Messages are encrypted with AES-256-GCM using the invite's channel key, then base64-encoded and wrapped in a JSON envelope for the WebSocket relay:
The inner frame uses the standard Rift protocol format (RFT1 magic, version, length, bincode-encoded header + encrypted payload).
License
Apache-2.0 OR MIT