← Back to Docs

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:

2. Advanced E2EE

Mana doesn't just encrypt messages; it manages the entire session lifecycle. With E2EE enabled, the framework automatically handles:

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.

main.go
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())
}