broadcast

package
v0.9.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
var (
	// ErrUnauthorized is returned when channel authorization fails
	ErrUnauthorized = errors.New("unauthorized channel access")

	// ErrDriverNotFound is returned when a driver is not found
	ErrDriverNotFound = errors.New("broadcast driver not found")
)

Functions

This section is empty.

Types

type Authorizer

type Authorizer func(channel string, user interface{}) bool

Authorizer is a function that authorizes channel access

type BroadcastManager added in v0.9.11

type BroadcastManager struct {
	// contains filtered or unexported fields
}

BroadcastManager is the default implementation

func New

func New(driver Driver) *BroadcastManager

New creates a new broadcaster with the given driver

func (*BroadcastManager) Auth added in v0.9.11

func (b *BroadcastManager) Auth(channel string, socketID string, user interface{}) (interface{}, error)

Auth handles channel authorization

func (*BroadcastManager) Channel added in v0.9.11

func (b *BroadcastManager) Channel(names ...string) *ChannelBuilder

Channel returns a channel builder for the given channels

func (*BroadcastManager) Leave added in v0.9.11

func (b *BroadcastManager) Leave(channel string, socketID string) error

Leave handles user leaving presence channel

func (*BroadcastManager) Presence added in v0.9.11

func (b *BroadcastManager) Presence(name string) *ChannelBuilder

Presence returns a presence channel builder

func (*BroadcastManager) Private added in v0.9.11

func (b *BroadcastManager) Private(name string) *ChannelBuilder

Private returns a private channel builder

func (*BroadcastManager) SetAuthorizer added in v0.9.11

func (b *BroadcastManager) SetAuthorizer(fn Authorizer)

SetAuthorizer sets the channel authorizer

func (*BroadcastManager) SetPresenceData added in v0.9.11

func (b *BroadcastManager) SetPresenceData(fn PresenceDataFunc)

SetPresenceData sets the presence data function

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 (*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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL