Documentation
¶
Overview ¶
Package broadcast provides a high-level broadcasting system for real-time communication built on top of the WebSocket package and supporting multiple drivers
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnauthorized = errors.New("unauthorized channel access") // ErrDriverNotFound is returned when a driver is not found ErrDriverNotFound = errors.New("broadcast driver not found") )
Functions ¶
func SetPresenceData ¶
func SetPresenceData(fn PresenceDataFunc)
SetPresenceData sets the default presence data function
Types ¶
type Authorizer ¶
Authorizer is a function that authorizes channel access
type Broadcaster ¶
type Broadcaster interface {
// Channel returns a channel builder for broadcasting
Channel(names ...string) *ChannelBuilder
// Private returns a private channel builder
Private(name string) *ChannelBuilder
// Presence returns a presence channel builder
Presence(name string) *ChannelBuilder
// Auth handles channel authorization
Auth(channel string, socketID string, user interface{}) (interface{}, error)
// Leave handles user leaving presence channel
Leave(channel string, socketID string) error
}
Broadcaster defines the main broadcasting interface
type ChannelBuilder ¶
type ChannelBuilder struct {
// contains filtered or unexported fields
}
ChannelBuilder builds broadcast operations
func Channel ¶
func Channel(names ...string) *ChannelBuilder
Channel returns a channel builder for the given channels
func Presence ¶
func Presence(name string) *ChannelBuilder
Presence returns a presence channel builder
func (*ChannelBuilder) Emit ¶
func (cb *ChannelBuilder) Emit(event string, data interface{}) error
Emit broadcasts an event to the channels
func (*ChannelBuilder) ToOthers ¶
func (cb *ChannelBuilder) ToOthers(socketID string) *ChannelBuilder
ToOthers excludes a socket from broadcast
func (*ChannelBuilder) When ¶
func (cb *ChannelBuilder) When(condition bool) *ChannelBuilder
When adds a condition to the broadcast
type Driver ¶
type Driver interface {
// Broadcast sends an event to channels
Broadcast(channels []string, event string, data interface{}) error
// BroadcastExcept broadcasts to all except specified socket
BroadcastExcept(channels []string, event string, data interface{}, socketID string) error
// GetClients returns clients in a channel
GetClients(channel string) []string
}
Driver defines the interface for broadcast drivers
type Event ¶
type Event interface {
BroadcastOn() []string // Channels to broadcast on
BroadcastAs() string // Event name
BroadcastWith() interface{} // Data to broadcast
BroadcastWhen() bool // Conditional broadcasting
}
Event represents a broadcast event
type PresenceDataFunc ¶
type PresenceDataFunc func(channel string, user interface{}) interface{}
PresenceDataFunc returns presence data for a user