Notification Hub Implementation
Mana provides a centralized hub to deliver push notifications across the platform. This is managed by the NotificationHub, which ensures delivery to every connected device for a specific user.
1. Targeted Delivery
You can send notifications to specific users by their UserID. Mana internally tracks which WebSocket connections belong to which user and routes the data accordingly.
2. Custom Data Payloads
Every notification can include a core.Notification object. This includes:
- Title & Body: Standard user-facing content.
- Data (JSON): Custom metadata to trigger client-side actions (e.g., navigating to a specific room, vibrating the device).
3. Cross-Platform Handlers
The Mana frontend libraries (Go, JS, Flutter) provide hooks to react to these notifications, allowing you to show UI toasts or system-level popups instantly.
main.go
package main
import (
"github.com/Aswanidev-vs/mana"
"github.com/Aswanidev-vs/mana/core"
)
func main() {
app := mana.New(mana.DefaultConfig())
// 1. Trigger a cross-platform notification.
// The Hub delivers this to alice-456 on all devices.
app.NotificationHub().Send(ctx, "alice-456", core.Notification{
Title: "New Friend Request",
Body: "Bob wants to connect with you.",
Data: map[string]interface{}{"user_id": "bob-123", "action": "view_profile"},
})
// 2. Lifecycle
app.Start()
}