emitter

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const UID = "emitter"

Variables

View Source
var RESERVED_EVENTS = types.NewSet(
	"connect",
	"connect_error",
	"disconnect",
	"disconnecting",
	"newListener",
	"removeListener",
)

Functions

This section is empty.

Types

type BroadcastFlags

type BroadcastFlags struct {
	Volatile bool `json:"volatile,omitempty" msgpack:"volatile,omitempty"`
	Compress bool `json:"compress,omitempty" msgpack:"compress,omitempty"`
}

type BroadcastOperator

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

func NewBroadcastOperator

func NewBroadcastOperator(redisClient *redis.Client, broadcastOptions *BroadcastOptions, rooms *types.Set[socket.Room], exceptRooms *types.Set[socket.Room], flags *BroadcastFlags) *BroadcastOperator

func (*BroadcastOperator) Compress

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

Sets the compress flag.

func (*BroadcastOperator) DisconnectSockets

func (b *BroadcastOperator) DisconnectSockets(state bool)

Makes the matching socket instances disconnect

func (*BroadcastOperator) Emit

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

Emits to all clients.

func (*BroadcastOperator) Except

func (b *BroadcastOperator) Except(room ...socket.Room) *BroadcastOperator

Excludes a room when emitting.

func (*BroadcastOperator) In

Targets a room when emitting.

func (*BroadcastOperator) SocketsJoin

func (b *BroadcastOperator) SocketsJoin(room ...socket.Room)

Makes the matching socket instances join the specified rooms

func (*BroadcastOperator) SocketsLeave

func (b *BroadcastOperator) SocketsLeave(room ...socket.Room)

Makes the matching socket instances leave the specified rooms

func (*BroadcastOperator) To

Targets a room when emitting.

func (*BroadcastOperator) Volatile

func (b *BroadcastOperator) Volatile() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).

type BroadcastOptions

type BroadcastOptions struct {
	Nsp              string
	BroadcastChannel string
	RequestChannel   string
	Parser           Parser
}

type Emitter

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

func NewEmitter

func NewEmitter(redisClient *redis.Client, opts *EmitterOptions, nsps ...string) *Emitter

func (*Emitter) Compress

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

Sets the compress flag.

compress - if `true`, compresses the sending data

func (*Emitter) DisconnectSockets

func (e *Emitter) DisconnectSockets(state bool)

Makes the matching socket instances disconnect

func (*Emitter) Emit

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

Emits to all clients.

func (*Emitter) Except

func (e *Emitter) Except(room ...socket.Room) *BroadcastOperator

Excludes a room when emitting.

func (*Emitter) In

func (e *Emitter) In(room ...socket.Room) *BroadcastOperator

Targets a room when emitting.

func (*Emitter) Of

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

Return a new emitter for the given namespace.

func (*Emitter) ServerSideEmit

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

Send a packet to the Socket.IO servers in the cluster

args - any number of serializable arguments

func (*Emitter) SocketsJoin

func (e *Emitter) SocketsJoin(room ...socket.Room)

Makes the matching socket instances join the specified rooms

func (*Emitter) SocketsLeave

func (e *Emitter) SocketsLeave(room ...socket.Room)

Makes the matching socket instances leave the specified rooms

func (*Emitter) To

func (e *Emitter) To(room ...socket.Room) *BroadcastOperator

Targets a room when emitting.

func (*Emitter) Volatile

func (e *Emitter) Volatile() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).

type EmitterOptions

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

func DefaultEmitterOptions

func DefaultEmitterOptions() *EmitterOptions

func (*EmitterOptions) Assign

func (*EmitterOptions) GetRawKey

func (s *EmitterOptions) GetRawKey() *string

func (*EmitterOptions) GetRawParser

func (s *EmitterOptions) GetRawParser() Parser

func (*EmitterOptions) Key

func (s *EmitterOptions) Key() string

func (*EmitterOptions) Parser

func (s *EmitterOptions) Parser() Parser

func (*EmitterOptions) SetKey

func (s *EmitterOptions) SetKey(key string)

func (*EmitterOptions) SetParser

func (s *EmitterOptions) SetParser(parser Parser)

type EmitterOptionsInterface

type EmitterOptionsInterface interface {
	SetKey(key string)
	GetRawKey() *string
	Key() string

	SetParser(parser Parser)
	GetRawParser() Parser
	Parser() Parser
}

type Packet

type Packet struct {
	Uid   string         `json:"uid,omitempty" msgpack:"uid,omitempty"`
	Type  RequestType    `json:"type,omitempty" msgpack:"type,omitempty"`
	Data  any            `json:"data,omitempty" msgpack:"data,omitempty"`
	Opts  *PacketOptions `json:"opts,omitempty" msgpack:"opts,omitempty"`
	Close bool           `json:"close,omitempty" msgpack:"close,omitempty"`
	Rooms []socket.Room  `json:"rooms,omitempty" msgpack:"rooms,omitempty"`
}

type PacketOptions

type PacketOptions struct {
	Rooms  []socket.Room   `json:"rooms,omitempty" msgpack:"rooms,omitempty"`
	Except []socket.Room   `json:"except,omitempty" msgpack:"except,omitempty"`
	Flags  *BroadcastFlags `json:"flags,omitempty" msgpack:"flags,omitempty"`
}

type Parser

type Parser interface {
	Encode(any) ([]byte, error)
}

type RequestType

type RequestType int
const (
	SOCKETS           RequestType = 0x0
	ALL_ROOMS         RequestType = 0x1
	REMOTE_JOIN       RequestType = 0x2
	REMOTE_LEAVE      RequestType = 0x3
	REMOTE_DISCONNECT RequestType = 0x4
	REMOTE_FETCH      RequestType = 0x5
	SERVER_SIDE_EMIT  RequestType = 0x6
)

Jump to

Keyboard shortcuts

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