Golden Path Implementation
The full example demonstrates a production-ready RTC server utilizing Mana's "Batteries Included" philosophy. It combines authentication, WebRTC signaling, and database persistence into a single unified instance.
1. Configuration
We start by initializing core.DefaultConfig(). This provides sensible defaults for performance and security. In this example, we explicitly enable:
- EnableRTC: Activates the WebRTC signaling hub.
- EnableE2EE: Enables the X3DH and Double Ratchet key exchange pipelines.
- DatabaseDriver: Sets up SQLite for high-performance relational persistence.
2. Advanced E2EE
Mana doesn't just encrypt messages; it manages the entire session lifecycle. With E2EE enabled, the framework automatically handles:
- X3DH Handshakes: Securely establishing keys for new peers.
- Double Ratchet: Ensuring perfect forward secrecy for every packet.
- Self-Healing: Automatically re-negotiating sessions if a decryption error occurs.
3. Media Control (WebRTC)
The framework provides granular hooks for call lifecycle events. You can monitor when calls start, end, or when users toggle their media states (mute/camera).
4. SQL Batteries
While this example uses SQLite for simplicity, you can swap the DatabaseDriver to postgres or mysql without changing a single line of business logic.
package main
import (
"log"
"github.com/Aswanidev-vs/mana"
"github.com/Aswanidev-vs/mana/core"
"github.com/Aswanidev-vs/mana/storage/db"
_ "modernc.org/sqlite"
)
func main() {
// 1. Initialize with all batteries included
cfg := core.DefaultConfig()
cfg.EnableRTC = true
cfg.EnableE2EE = true
cfg.DatabaseDriver = db.SQLite
cfg.DatabaseDSN = "full_example.db"
app := mana.New(cfg)
// 2. Lifecycle hooks
app.OnMessage(func(msg core.Message) {
log.Printf("New Message in %s", msg.RoomID)
})
app.OnCallStart(func(event core.CallEvent) {
log.Printf("Call started by %s", event.Caller)
})
// 3. Start the engine
log.Fatal(app.Start())
}