Documentation
¶
Index ¶
- type AccountStore
- type AckMessage
- type CallEvent
- type CallType
- type Config
- type ContactStore
- type DeviceInfo
- type DeviceStore
- type DeviceSyncBatch
- type EncryptedFanout
- type ICEServerConfig
- type Message
- type MessageStore
- type Notification
- type PreferenceStore
- type PresenceEvent
- type ProfileStore
- type RoomInfo
- type RoomStore
- type Signal
- type SignalType
- type StoreProvider
- type SyncRequest
- type User
- type UserProfile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountStore ¶
type AccountStore interface {
CreateUser(ctx context.Context, username, password string) error
Authenticate(ctx context.Context, username, password string) (userID string, err error)
GetUser(ctx context.Context, userID string) (User, error)
DeleteUser(ctx context.Context, userID string) error
}
AccountStore defines the interface for user authentication and management.
type AckMessage ¶
type AckMessage struct {
Type string `json:"type"` // "ack"
AckID string `json:"ack_id"`
MsgID string `json:"msg_id"`
}
AckMessage is sent back to confirm message receipt.
type CallEvent ¶
type CallEvent struct {
Status string `json:"status,omitempty"` // "started" or "ended"
Type CallType `json:"type"`
RoomID string `json:"room_id"`
Caller string `json:"caller"`
Callee string `json:"callee,omitempty"`
Started time.Time `json:"started"`
Ended time.Time `json:"ended,omitempty"`
}
CallEvent represents a call lifecycle event.
type Config ¶
type Config struct {
// Port is the HTTP server listen port.
Port int `json:"port"`
// Host is the HTTP server bind address.
Host string `json:"host"`
// EnableRTC enables WebRTC functionality.
EnableRTC bool `json:"enable_rtc"`
// EnableE2EE enables end-to-end encryption key exchange facilitation.
EnableE2EE bool `json:"enable_e2ee"`
// ReadBufferSize sets the WebSocket read buffer size.
ReadBufferSize int `json:"read_buffer_size"`
// WriteBufferSize sets the WebSocket write buffer size.
WriteBufferSize int `json:"write_buffer_size"`
// MaxMessageSize is the maximum WebSocket message size in bytes.
// Messages exceeding this limit will be rejected.
MaxMessageSize int64 `json:"max_message_size"`
// EnableAuth enables JWT authentication on WebSocket connections.
// When true, clients must provide a valid JWT token to connect.
EnableAuth bool `json:"enable_auth"`
// JWTSecret is the secret key for JWT signing.
// Must be at least 32 bytes for production use.
JWTSecret string `json:"-"`
// JWTIssuer is the JWT issuer claim.
JWTIssuer string `json:"jwt_issuer"`
// JWTExpiry is the token validity duration.
JWTExpiry time.Duration `json:"jwt_expiry"`
// STUNServers is the list of STUN/TURN server URLs for WebRTC.
STUNServers []string `json:"stun_servers"`
// TURNServers contains authenticated TURN relay definitions.
TURNServers []ICEServerConfig `json:"turn_servers"`
// ICETransportPolicy controls how ICE candidates are selected.
// Supported values are "all" and "relay".
ICETransportPolicy string `json:"ice_transport_policy"`
// GracefulShutdownTimeout is the max time to wait for connections to drain.
GracefulShutdownTimeout time.Duration `json:"graceful_shutdown_timeout"`
// AllowedOrigins is the list of allowed WebSocket origins.
// If empty, all origins are rejected (secure default).
// Use ["*"] to allow all origins (not recommended for production).
AllowedOrigins []string `json:"allowed_origins"`
// RateLimitPerSecond is the max messages per second per connection.
// 0 means unlimited (not recommended for production).
RateLimitPerSecond int `json:"rate_limit_per_second"`
// RateLimitBurst is the burst capacity for rate limiting.
RateLimitBurst int `json:"rate_limit_burst"`
// EnableTLS enables HTTPS/WSS using TLS certificates.
EnableTLS bool `json:"enable_tls"`
// TLSCertFile is the path to the TLS certificate file.
TLSCertFile string `json:"tls_cert_file"`
// TLSKeyFile is the path to the TLS private key file.
TLSKeyFile string `json:"tls_key_file"`
// ReadTimeout is the maximum duration for reading the entire request.
ReadTimeout time.Duration `json:"read_timeout"`
// WriteTimeout is the maximum duration before timing out writes.
WriteTimeout time.Duration `json:"write_timeout"`
// IdleTimeout is the maximum time to wait for the next request.
IdleTimeout time.Duration `json:"idle_timeout"`
// MessageStorePath enables durable file-backed message persistence when set.
MessageStorePath string `json:"message_store_path"`
// ProductStorePath enables durable product-state persistence when set.
ProductStorePath string `json:"product_store_path"`
// AttachmentDir is the base directory for product attachment metadata/assets.
AttachmentDir string `json:"attachment_dir"`
// ReplayBatchSize caps reconnect replay batches returned to clients.
ReplayBatchSize int `json:"replay_batch_size"`
// ClusterNodeID identifies this process when pub-sub fanout is enabled.
ClusterNodeID string `json:"cluster_node_id"`
// PubSubBackend selects the cluster fanout backend: "", "memory", "redis", or "nats".
PubSubBackend string `json:"pubsub_backend"`
// Redis cluster transport settings.
RedisAddr string `json:"redis_addr"`
RedisPassword string `json:"-"`
RedisDB int `json:"redis_db"`
RedisChannel string `json:"redis_channel"`
// NATS cluster transport settings.
NATSURL string `json:"nats_url"`
NATSSubject string `json:"nats_subject"`
// Database settings for centralized persistence.
// Driver can be "sqlite", "postgres", or "mysql".
DatabaseDriver string `json:"database_driver"`
// DSN is the data source name (e.g., file path for sqlite or connection string for postgres/mysql).
DatabaseDSN string `json:"database_dsn"`
// DatabaseTablePrefix is an optional prefix for all Mana tables (e.g., "mana_").
DatabaseTablePrefix string `json:"database_table_prefix"`
// Tracing controls built-in OpenTelemetry instrumentation.
EnableTracing bool `json:"enable_tracing"`
TraceSampleRatio float64 `json:"trace_sample_ratio"`
ServiceName string `json:"service_name"`
ServiceVersion string `json:"service_version"`
}
Config holds the configuration for a Mana application.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type ContactStore ¶
type ContactStore interface {
AddContact(ctx context.Context, userID, contactID string) error
GetContacts(ctx context.Context, userID string) ([]string, error)
BlockUser(ctx context.Context, userID, targetID string) error
IsBlocked(ctx context.Context, userID, targetID string) (bool, error)
}
ContactStore defines the interface for managing contacts and blocking.
type DeviceInfo ¶
type DeviceInfo struct {
DeviceID string `json:"device_id"`
Label string `json:"label"`
Platform string `json:"platform"`
LastSeenAt time.Time `json:"last_seen_at"`
}
DeviceInfo represents a linked device.
type DeviceStore ¶
type DeviceStore interface {
RegisterDevice(ctx context.Context, userID string, device DeviceInfo) error
GetDevices(ctx context.Context, userID string) ([]DeviceInfo, error)
DeleteDevice(ctx context.Context, userID, deviceID string) error
}
DeviceStore defines the interface for managing linked devices.
type DeviceSyncBatch ¶
type DeviceSyncBatch struct {
Type string `json:"type"` // "message_sync"
SessionID string `json:"session_id,omitempty"`
DeviceID string `json:"device_id,omitempty"`
Cursor uint64 `json:"cursor,omitempty"`
HasMore bool `json:"has_more,omitempty"`
Reason string `json:"reason,omitempty"`
Messages []Message `json:"messages"`
Timestamp time.Time `json:"timestamp"`
}
DeviceSyncBatch delivers historical messages to a reconnecting device.
type EncryptedFanout ¶ added in v0.3.0
type EncryptedFanout struct {
Type string `json:"type"` // "encrypted_fanout"
SenderID string `json:"sender_id"`
Payloads map[string][]byte `json:"payloads"` // map[deviceID]encryptedPayload
}
EncryptedFanout represents a fan-out message sent to multiple devices. Used for "Signal-grade" multi-device E2EE (Sesame lite).
type ICEServerConfig ¶
type ICEServerConfig struct {
URLs []string `json:"urls"`
Username string `json:"username,omitempty"`
Credential string `json:"credential,omitempty"`
CredentialType string `json:"credential_type,omitempty"`
}
ICEServerConfig describes an authenticated ICE server, typically TURN.
type Message ¶
type Message struct {
ID string `json:"id"`
Sequence uint64 `json:"sequence,omitempty"`
Type string `json:"type"`
RoomID string `json:"room_id,omitempty"`
SenderID string `json:"sender_id"`
TargetID string `json:"target_id,omitempty"` // For 1:1 messaging
Payload []byte `json:"payload"`
Timestamp time.Time `json:"timestamp"`
AckID string `json:"ack_id,omitempty"` // For message acknowledgments
}
Message represents a communication message between peers.
type MessageStore ¶
type MessageStore interface {
SaveMessage(ctx context.Context, msg Message, recipients []string) (Message, error)
MarkDelivered(ctx context.Context, messageID, userID string) error
PendingForUser(ctx context.Context, userID string) []Message
SyncForUserSince(ctx context.Context, userID string, since time.Time) []Message
SyncForUserAfterSequence(ctx context.Context, userID string, after uint64, limit int) ([]Message, bool)
LatestSequenceForUser(ctx context.Context, userID string) uint64
GetConversation(ctx context.Context, userID, contactID string, limit int) ([]Message, error)
}
MessageStore defines the interface for persisting and retrieving messages.
type Notification ¶
type Notification struct {
Type string `json:"type"` // "notification"
ID string `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Data map[string]interface{} `json:"data,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Notification represents a server-to-client alert or background notification.
type PreferenceStore ¶
type PreferenceStore interface {
SetPreference(ctx context.Context, userID, key string, value interface{}) error
GetPreference(ctx context.Context, userID, key string) (interface{}, error)
}
PreferenceStore defines the interface for user preferences.
type PresenceEvent ¶
type PresenceEvent struct {
Type string `json:"type"` // "presence"
UserID string `json:"user_id"`
Username string `json:"username"`
RoomID string `json:"room_id"`
Online bool `json:"online"`
}
PresenceEvent represents an online/offline presence notification.
type ProfileStore ¶
type ProfileStore interface {
UpsertProfile(ctx context.Context, profile UserProfile) error
GetProfile(ctx context.Context, userID string) (UserProfile, error)
}
ProfileStore defines the interface for user profiles.
type RoomInfo ¶
type RoomInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
Members []User `json:"members"`
}
RoomInfo represents metadata about a room.
type RoomStore ¶ added in v0.3.0
type RoomStore interface {
CreateRoom(ctx context.Context, name, roomType, ownerID string, memberIDs []string) (string, error)
GetRoom(ctx context.Context, roomID string) (RoomInfo, error)
ListUserRooms(ctx context.Context, userID string) ([]RoomInfo, error)
AddMember(ctx context.Context, roomID, userID string) error
RemoveMember(ctx context.Context, roomID, userID string) error
}
RoomStore defines the interface for persisting and retrieving rooms.
type Signal ¶
type Signal struct {
Type SignalType `json:"type"`
From string `json:"from"`
To string `json:"to,omitempty"`
RoomID string `json:"room_id,omitempty"`
Payload []byte `json:"payload,omitempty"`
SDP string `json:"sdp,omitempty"`
Candidate interface{} `json:"candidate,omitempty"`
Ready bool `json:"ready,omitempty"`
AckID string `json:"ack_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Signal represents a WebRTC signaling message.
type SignalType ¶
type SignalType string
SignalType defines signaling message types.
const ( SignalOffer SignalType = "offer" SignalAnswer SignalType = "answer" SignalCandidate SignalType = "candidate" SignalSFUOffer SignalType = "sfu_offer" SignalSFUAnswer SignalType = "sfu_answer" SignalSFUCandidate SignalType = "sfu_candidate" SignalSubscribe SignalType = "subscribe" SignalLeave SignalType = "leave" SignalReady SignalType = "ready" SignalKeyExchange SignalType = "key_exchange" SignalGetPreKeyBundle SignalType = "get_prekey_bundle" SignalPreKeyRefill SignalType = "prekey_refill" SignalEncryptedFanout SignalType = "encrypted_fanout" SignalJoin SignalType = "join" SignalTyping SignalType = "typing" SignalMessage SignalType = "message" SignalMute SignalType = "mute" SignalCameraToggle SignalType = "camera_toggle" SignalScreenStart SignalType = "screen_share_start" SignalScreenStop SignalType = "screen_share_stop" SignalPin SignalType = "pin" SignalCallStart SignalType = "call_start" SignalCallEnd SignalType = "call_end" SignalSync SignalType = "message_sync" SignalSyncRequest SignalType = "sync_request" SignalICERestart SignalType = "ice_restart" SignalNetworkChange SignalType = "network_change" SignalActiveSpeaker SignalType = "active_speaker" SignalTrackAdded SignalType = "track_added" SignalError SignalType = "error" )
type StoreProvider ¶
type StoreProvider interface {
Messages() MessageStore
Accounts() AccountStore
Profiles() ProfileStore
Preferences() PreferenceStore
Contacts() ContactStore
Devices() DeviceStore
}
StoreProvider provides access to all specialized storage components.
type SyncRequest ¶
type SyncRequest struct {
Type string `json:"type"` // "sync_request"
DeviceID string `json:"device_id,omitempty"`
Cursor uint64 `json:"cursor,omitempty"`
Limit int `json:"limit,omitempty"`
}
SyncRequest allows a reconnecting client to explicitly reconcile from a known cursor.
type User ¶
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Online bool `json:"online"`
Role string `json:"role,omitempty"`
}
User represents a connected user.
type UserProfile ¶
type UserProfile struct {
UserID string `json:"user_id"`
DisplayName string `json:"display_name"`
AvatarURL string `json:"avatar_url"`
Metadata map[string]interface{} `json:"metadata"`
UpdatedAt time.Time `json:"updated_at"`
}
UserProfile is a simplified version of the profile for the core interface.