emitter

package
v3.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package emitter provides broadcast capabilities for Socket.IO via Valkey pub/sub.

Package emitter provides an API for broadcasting messages to Socket.IO servers via Valkey without requiring a full Socket.IO server instance.

Package emitter provides types and interfaces for broadcasting messages to Socket.IO servers using Valkey pub/sub.

Package emitter provides an API for broadcasting messages to Socket.IO servers via Valkey without requiring a full Socket.IO server instance.

Package emitter provides a sharded broadcast operator for emitting events via Valkey Sharded Pub/Sub.

Index

Constants

View Source
const (
	// DefaultEmitterKey is the default Valkey key prefix for the emitter.
	DefaultEmitterKey = "socket.io"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastMessage

type BroadcastMessage = adapter.BroadcastMessage

BroadcastMessage is an alias for adapter.BroadcastMessage.

type BroadcastOperator

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

BroadcastOperator provides a fluent API for broadcasting events to Socket.IO clients via Valkey.

func MakeBroadcastOperator

func MakeBroadcastOperator() *BroadcastOperator

MakeBroadcastOperator creates a new BroadcastOperator with empty room sets and default flags.

func NewBroadcastOperator

func NewBroadcastOperator(
	client *valkey.ValkeyClient,
	broadcastOptions *BroadcastOptions,
	rooms *types.Set[socket.Room],
	exceptRooms *types.Set[socket.Room],
	flags *socket.BroadcastFlags,
) *BroadcastOperator

NewBroadcastOperator creates and initializes a new BroadcastOperator.

func (*BroadcastOperator) Compress

func (b *BroadcastOperator) Compress(compress bool) BroadcastOperatorInterface

func (*BroadcastOperator) Construct

func (b *BroadcastOperator) Construct(
	client *valkey.ValkeyClient,
	broadcastOptions *BroadcastOptions,
	rooms *types.Set[socket.Room],
	exceptRooms *types.Set[socket.Room],
	flags *socket.BroadcastFlags,
)

Construct initializes the BroadcastOperator.

func (*BroadcastOperator) DisconnectSockets

func (b *BroadcastOperator) DisconnectSockets(state bool) error

DisconnectSockets disconnects all matching socket instances.

func (*BroadcastOperator) Emit

func (b *BroadcastOperator) Emit(ev string, args ...any) error

Emit broadcasts an event with the given name and arguments to all targeted clients.

func (*BroadcastOperator) Except

func (*BroadcastOperator) In

func (*BroadcastOperator) SocketsJoin

func (b *BroadcastOperator) SocketsJoin(rooms ...socket.Room) error

SocketsJoin makes all matching socket instances join the specified rooms.

func (*BroadcastOperator) SocketsLeave

func (b *BroadcastOperator) SocketsLeave(rooms ...socket.Room) error

SocketsLeave makes all matching socket instances leave the specified rooms.

func (*BroadcastOperator) To

func (*BroadcastOperator) Volatile

type BroadcastOperatorInterface

type BroadcastOperatorInterface interface {
	To(room ...socket.Room) BroadcastOperatorInterface
	In(room ...socket.Room) BroadcastOperatorInterface
	Except(room ...socket.Room) BroadcastOperatorInterface
	Compress(compress bool) BroadcastOperatorInterface
	Volatile() BroadcastOperatorInterface
	Emit(ev string, args ...any) error
	SocketsJoin(rooms ...socket.Room) error
	SocketsLeave(rooms ...socket.Room) error
	DisconnectSockets(state bool) error
}

BroadcastOperatorInterface defines the common interface for broadcast operators.

type BroadcastOptions

type BroadcastOptions struct {
	Nsp              string
	BroadcastChannel string
	RequestChannel   string
	Parser           valkey.Parser
	Sharded          bool
	SubscriptionMode valkey.SubscriptionMode
}

BroadcastOptions contains configuration for broadcasting messages to Valkey channels.

type ClusterMessage

type ClusterMessage = adapter.ClusterMessage

ClusterMessage is an alias for adapter.ClusterMessage.

type DisconnectSocketsMessage

type DisconnectSocketsMessage = adapter.DisconnectSocketsMessage

DisconnectSocketsMessage is an alias for adapter.DisconnectSocketsMessage.

type Emitter

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

Emitter broadcasts messages to Socket.IO servers using Valkey pub/sub.

func MakeEmitter

func MakeEmitter() *Emitter

MakeEmitter creates a new Emitter with default options and the root namespace.

func NewEmitter

func NewEmitter(client *valkey.ValkeyClient, opts *EmitterOptions, nsps ...string) *Emitter

NewEmitter creates and initializes a new Emitter with the given Valkey client and options.

func (*Emitter) Compress

func (e *Emitter) Compress(compress bool) BroadcastOperatorInterface

Compress sets the compress flag.

func (*Emitter) Construct

func (e *Emitter) Construct(client *valkey.ValkeyClient, opts *EmitterOptions, nsps ...string)

Construct initializes the Emitter with the given Valkey client, options, and namespace.

func (*Emitter) DisconnectSockets

func (e *Emitter) DisconnectSockets(state bool) error

DisconnectSockets disconnects all matching socket instances.

func (*Emitter) Emit

func (e *Emitter) Emit(ev string, args ...any) error

Emit broadcasts an event to all clients in the namespace.

func (*Emitter) Except

func (e *Emitter) Except(rooms ...socket.Room) BroadcastOperatorInterface

Except excludes specific room(s) from event emission.

func (*Emitter) In

In is an alias for To.

func (*Emitter) Of

func (e *Emitter) Of(nsp string) *Emitter

Of returns a new Emitter for the specified namespace.

func (*Emitter) ServerSideEmit

func (e *Emitter) ServerSideEmit(args ...any) error

ServerSideEmit sends a message to all Socket.IO servers in the cluster.

func (*Emitter) SocketsJoin

func (e *Emitter) SocketsJoin(rooms ...socket.Room) error

SocketsJoin makes all matching socket instances join the specified rooms.

func (*Emitter) SocketsLeave

func (e *Emitter) SocketsLeave(rooms ...socket.Room) error

SocketsLeave makes all matching socket instances leave the specified rooms.

func (*Emitter) To

To targets specific room(s) for event emission.

func (*Emitter) Volatile

func (e *Emitter) Volatile() BroadcastOperatorInterface

Volatile sets the volatile flag.

type EmitterOptions

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

EmitterOptions holds configuration options for the Valkey emitter.

func DefaultEmitterOptions

func DefaultEmitterOptions() *EmitterOptions

DefaultEmitterOptions creates a new EmitterOptions instance with default values.

func (*EmitterOptions) Assign

Assign copies non-nil option values from another EmitterOptionsInterface.

func (*EmitterOptions) GetRawKey

func (o *EmitterOptions) GetRawKey() types.Optional[string]

func (*EmitterOptions) GetRawParser

func (o *EmitterOptions) GetRawParser() types.Optional[valkey.Parser]

func (*EmitterOptions) GetRawSharded

func (o *EmitterOptions) GetRawSharded() types.Optional[bool]

func (*EmitterOptions) GetRawSubscriptionMode

func (o *EmitterOptions) GetRawSubscriptionMode() types.Optional[valkey.SubscriptionMode]

func (*EmitterOptions) Key

func (o *EmitterOptions) Key() string

func (*EmitterOptions) Parser

func (o *EmitterOptions) Parser() valkey.Parser

func (*EmitterOptions) SetKey

func (o *EmitterOptions) SetKey(key string)

func (*EmitterOptions) SetParser

func (o *EmitterOptions) SetParser(parser valkey.Parser)

func (*EmitterOptions) SetSharded

func (o *EmitterOptions) SetSharded(sharded bool)

func (*EmitterOptions) SetSubscriptionMode

func (o *EmitterOptions) SetSubscriptionMode(mode valkey.SubscriptionMode)

func (*EmitterOptions) Sharded

func (o *EmitterOptions) Sharded() bool

func (*EmitterOptions) SubscriptionMode

func (o *EmitterOptions) SubscriptionMode() valkey.SubscriptionMode

type EmitterOptionsInterface

type EmitterOptionsInterface interface {
	SetKey(string)
	GetRawKey() types.Optional[string]
	Key() string

	SetParser(valkey.Parser)
	GetRawParser() types.Optional[valkey.Parser]
	Parser() valkey.Parser

	SetSharded(bool)
	GetRawSharded() types.Optional[bool]
	Sharded() bool

	SetSubscriptionMode(valkey.SubscriptionMode)
	GetRawSubscriptionMode() types.Optional[valkey.SubscriptionMode]
	SubscriptionMode() valkey.SubscriptionMode
}

EmitterOptionsInterface defines the interface for configuring emitter options.

type Packet

type Packet = valkey.ValkeyPacket

Packet is an alias for valkey.ValkeyPacket.

type Request

type Request = valkey.ValkeyRequest

Request is an alias for valkey.ValkeyRequest.

type Response

type Response = valkey.ValkeyResponse

Response is an alias for valkey.ValkeyResponse.

type ServerSideEmitMessage

type ServerSideEmitMessage = adapter.ServerSideEmitMessage

ServerSideEmitMessage is an alias for adapter.ServerSideEmitMessage.

type ShardedBroadcastOperator

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

ShardedBroadcastOperator broadcasts events via Valkey Sharded Pub/Sub (SPUBLISH).

func MakeShardedBroadcastOperator

func MakeShardedBroadcastOperator() *ShardedBroadcastOperator

MakeShardedBroadcastOperator creates a new ShardedBroadcastOperator with default values.

func NewShardedBroadcastOperator

func NewShardedBroadcastOperator(
	valkeyClient *valkey.ValkeyClient,
	broadcastOptions *BroadcastOptions,
	rooms *types.Set[socket.Room],
	exceptRooms *types.Set[socket.Room],
	flags *socket.BroadcastFlags,
) *ShardedBroadcastOperator

NewShardedBroadcastOperator creates and initializes a new ShardedBroadcastOperator.

func (*ShardedBroadcastOperator) Compress

func (*ShardedBroadcastOperator) Construct

func (b *ShardedBroadcastOperator) Construct(
	valkeyClient *valkey.ValkeyClient,
	broadcastOptions *BroadcastOptions,
	rooms *types.Set[socket.Room],
	exceptRooms *types.Set[socket.Room],
	flags *socket.BroadcastFlags,
)

Construct initializes the ShardedBroadcastOperator.

func (*ShardedBroadcastOperator) DisconnectSockets

func (b *ShardedBroadcastOperator) DisconnectSockets(state bool) error

DisconnectSockets disconnects the matching socket instances.

func (*ShardedBroadcastOperator) Emit

func (b *ShardedBroadcastOperator) Emit(ev string, args ...any) error

Emit emits an event to all targeted clients using SPUBLISH.

func (*ShardedBroadcastOperator) Except

func (*ShardedBroadcastOperator) In

func (*ShardedBroadcastOperator) SocketsJoin

func (b *ShardedBroadcastOperator) SocketsJoin(rooms ...socket.Room) error

SocketsJoin makes the matching socket instances join the specified rooms.

func (*ShardedBroadcastOperator) SocketsLeave

func (b *ShardedBroadcastOperator) SocketsLeave(rooms ...socket.Room) error

SocketsLeave makes the matching socket instances leave the specified rooms.

func (*ShardedBroadcastOperator) To

func (*ShardedBroadcastOperator) Volatile

type SocketsJoinLeaveMessage

type SocketsJoinLeaveMessage = adapter.SocketsJoinLeaveMessage

SocketsJoinLeaveMessage is an alias for adapter.SocketsJoinLeaveMessage.

Jump to

Keyboard shortcuts

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