adapter

package
v0.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	EMITTER_UID     string        = "emitter"
	DEFAULT_TIMEOUT time.Duration = 5000 * time.Millisecond
)

Variables

View Source
var (
	StaticSubscriptionMode  subMode = subMode{"static"}
	DynamicSubscriptionMode subMode = subMode{"dynamic"}
)

Functions

func RandomId

func RandomId() (string, error)

func Uid2

func Uid2(length int) (string, error)

Types

type AckRequest

type AckRequest interface {
	ClientCountCallback(uint64)
	Ack([]any, error)
}

func NewAckRequest

func NewAckRequest(clientCountCallback func(uint64), ack func([]any, error)) AckRequest

type ClusterAckRequest

type ClusterAckRequest interface {
	ClientCountCallback(uint64)
	Ack([]any, error)
}

func NewClusterAckRequest

func NewClusterAckRequest(clientCountCallback func(uint64), ack func([]any, error)) ClusterAckRequest

type ClusterAdapter

type ClusterAdapter interface {
	socket.Adapter

	Uid() string
	OnMessage(*ClusterMessage, int64)
	OnResponse(*ClusterMessage)
	Publish(*ClusterMessage) (int64, error)
	PublishMessage(*ClusterMessage) (int64, error)
	PublishResponse(string, *ClusterMessage) (int64, error)
}

func MakeClusterAdapter

func MakeClusterAdapter() ClusterAdapter

func NewClusterAdapter

func NewClusterAdapter(nsp socket.NamespaceInterface) ClusterAdapter

type ClusterAdapterBuilder

type ClusterAdapterBuilder struct {
	socket.AdapterConstructor
}

A cluster-ready adapter. Any extending class must:

- implement [ClusterAdapter#PublishMessage] and [ClusterAdapter#PublishResponse] - call [ClusterAdapter#OnMessage] and [ClusterAdapter#OnResponse]

func (*ClusterAdapterBuilder) New

type ClusterAdapterOptions

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

func DefaultClusterAdapterOptions

func DefaultClusterAdapterOptions() *ClusterAdapterOptions

func (*ClusterAdapterOptions) Assign

func (*ClusterAdapterOptions) GetRawHeartbeatInterval

func (s *ClusterAdapterOptions) GetRawHeartbeatInterval() *time.Duration

func (*ClusterAdapterOptions) GetRawHeartbeatTimeout

func (s *ClusterAdapterOptions) GetRawHeartbeatTimeout() *int64

func (*ClusterAdapterOptions) HeartbeatInterval

func (s *ClusterAdapterOptions) HeartbeatInterval() time.Duration

func (*ClusterAdapterOptions) HeartbeatTimeout

func (s *ClusterAdapterOptions) HeartbeatTimeout() int64

func (*ClusterAdapterOptions) SetHeartbeatInterval

func (s *ClusterAdapterOptions) SetHeartbeatInterval(heartbeatInterval time.Duration)

func (*ClusterAdapterOptions) SetHeartbeatTimeout

func (s *ClusterAdapterOptions) SetHeartbeatTimeout(heartbeatTimeout int64)

type ClusterAdapterOptionsInterface

type ClusterAdapterOptionsInterface interface {
	SetHeartbeatInterval(time.Duration)
	GetRawHeartbeatInterval() *time.Duration
	HeartbeatInterval() time.Duration

	SetHeartbeatTimeout(int64)
	GetRawHeartbeatTimeout() *int64
	HeartbeatTimeout() int64
}

type ClusterAdapterWithHeartbeat

type ClusterAdapterWithHeartbeat interface {
	ClusterAdapter

	SetOpts(*ClusterAdapterOptions)
}

func MakeClusterAdapterWithHeartbeat

func MakeClusterAdapterWithHeartbeat() ClusterAdapterWithHeartbeat

type ClusterAdapterWithHeartbeatBuilder

type ClusterAdapterWithHeartbeatBuilder struct {
	socket.AdapterConstructor

	Opts *ClusterAdapterOptions
}

func (*ClusterAdapterWithHeartbeatBuilder) New

type ClusterMessage

type ClusterMessage struct {
	Uid  string
	Type MessageType
	Data *ClusterMessageRecord
}

type ClusterMessageRecord

type ClusterMessageRecord struct {
	RequestId   string
	Packet      any
	ClientCount uint64
	Sockets     any
	Opts        *types.PacketOptions
	Rooms       []socket.Room
	Close       bool
}

ClusterMessage

type ClusterRequest

type ClusterRequest struct {
	Current int64

	Type      MessageType
	Resolve   func(any, error)
	Timeout   *utils.Timer
	Expected  int64
	Responses []any
}

type MessageType

type MessageType int
const (
	MESSAGE_INITIAL_HEARTBEAT         MessageType = 1
	MESSAGE_HEARTBEAT                 MessageType = 2
	MESSAGE_BROADCAST                 MessageType = 3
	MESSAGE_SOCKETS_JOIN              MessageType = 4
	MESSAGE_SOCKETS_LEAVE             MessageType = 5
	MESSAGE_DISCONNECT_SOCKETS        MessageType = 6
	MESSAGE_FETCH_SOCKETS             MessageType = 7
	MESSAGE_FETCH_SOCKETS_RESPONSE    MessageType = 8
	MESSAGE_SERVER_SIDE_EMIT          MessageType = 9
	MESSAGE_SERVER_SIDE_EMIT_RESPONSE MessageType = 10
	MESSAGE_BROADCAST_CLIENT_COUNT    MessageType = 11
	MESSAGE_BROADCAST_ACK             MessageType = 12
)

type RedisAdapter

type RedisAdapter interface {
	socket.Adapter

	SetRedis(*_types.RedisClient)
	SetOpts(*RedisAdapterOptions)

	Uid() string
	RequestsTimeout() time.Duration
	PublishOnSpecificResponseChannel() bool
	Parser() _types.Parser

	AllRooms() func(func(*types.Set[socket.Room], error))
}

func MakeRedisAdapter

func MakeRedisAdapter() RedisAdapter

type RedisAdapterBuilder

type RedisAdapterBuilder struct {
	socket.AdapterConstructor

	// a Redis client
	Redis *_types.RedisClient
	// additional options
	Opts *RedisAdapterOptions
}

func (*RedisAdapterBuilder) New

Adapter constructor.

type RedisAdapterOptions

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

func DefaultRedisAdapterOptions

func DefaultRedisAdapterOptions() *RedisAdapterOptions

func (*RedisAdapterOptions) Assign

func (*RedisAdapterOptions) GetRawKey

func (s *RedisAdapterOptions) GetRawKey() *string

func (*RedisAdapterOptions) GetRawParser

func (s *RedisAdapterOptions) GetRawParser() types.Parser

func (*RedisAdapterOptions) GetRawPublishOnSpecificResponseChannel

func (s *RedisAdapterOptions) GetRawPublishOnSpecificResponseChannel() *bool

func (*RedisAdapterOptions) GetRawRequestsTimeout

func (s *RedisAdapterOptions) GetRawRequestsTimeout() *time.Duration

func (*RedisAdapterOptions) Key

func (s *RedisAdapterOptions) Key() string

func (*RedisAdapterOptions) Parser

func (s *RedisAdapterOptions) Parser() types.Parser

func (*RedisAdapterOptions) PublishOnSpecificResponseChannel

func (s *RedisAdapterOptions) PublishOnSpecificResponseChannel() bool

func (*RedisAdapterOptions) RequestsTimeout

func (s *RedisAdapterOptions) RequestsTimeout() time.Duration

func (*RedisAdapterOptions) SetKey

func (s *RedisAdapterOptions) SetKey(key string)

func (*RedisAdapterOptions) SetParser

func (s *RedisAdapterOptions) SetParser(parser types.Parser)

func (*RedisAdapterOptions) SetPublishOnSpecificResponseChannel

func (s *RedisAdapterOptions) SetPublishOnSpecificResponseChannel(publishOnSpecificResponseChannel bool)

func (*RedisAdapterOptions) SetRequestsTimeout

func (s *RedisAdapterOptions) SetRequestsTimeout(requestsTimeout time.Duration)

type RedisAdapterOptionsInterface

type RedisAdapterOptionsInterface interface {
	SetKey(string)
	GetRawKey() *string
	Key() string

	SetRequestsTimeout(time.Duration)
	GetRawRequestsTimeout() *time.Duration
	RequestsTimeout() time.Duration

	SetPublishOnSpecificResponseChannel(bool)
	GetRawPublishOnSpecificResponseChannel() *bool
	PublishOnSpecificResponseChannel() bool

	SetParser(types.Parser)
	GetRawParser() types.Parser
	Parser() types.Parser
}

type Request

type Request struct {
	Type _types.RequestType `json:"type,omitempty" mapstructure:"type,omitempty" msgpack:"type,omitempty"`

	RequestId string                `json:"requestId,omitempty" mapstructure:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Rooms     []socket.Room         `json:"rooms,omitempty" mapstructure:"rooms,omitempty" msgpack:"rooms,omitempty"`
	Opts      *_types.PacketOptions `json:"opts,omitempty" mapstructure:"opts,omitempty" msgpack:"opts,omitempty"`
	Sid       socket.SocketId       `json:"sid,omitempty" mapstructure:"sid,omitempty" msgpack:"sid,omitempty"`
	Room      socket.Room           `json:"room,omitempty" mapstructure:"room,omitempty" msgpack:"room,omitempty"`
	Close     bool                  `json:"close,omitempty" mapstructure:"close,omitempty" msgpack:"close,omitempty"`
	Uid       string                `json:"uid,omitempty" mapstructure:"uid,omitempty" msgpack:"uid,omitempty"`
	Data      []any                 `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
	Packet    *parser.Packet        `json:"packet,omitempty" mapstructure:"packet,omitempty" msgpack:"packet,omitempty"`
}

type Response

type Response struct {
	Type        _types.RequestType `json:"type,omitempty" mapstructure:"type,omitempty" msgpack:"type,omitempty"`
	RequestId   string             `json:"requestId,omitempty" mapstructure:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Rooms       []socket.Room      `json:"rooms,omitempty" mapstructure:"rooms,omitempty" msgpack:"rooms,omitempty"`
	Sockets     []*ResponseSockets `json:"sockets,omitempty" mapstructure:"sockets,omitempty" msgpack:"sockets,omitempty"`
	Data        []any              `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
	ClientCount uint64             `json:"clientcount,omitempty" mapstructure:"clientcount,omitempty" msgpack:"clientcount,omitempty"`
	Packet      []any              `json:"packet,omitempty" mapstructure:"packet,omitempty" msgpack:"packet,omitempty"`
}

type ResponseSockets

type ResponseSockets struct {
	SocketId        socket.SocketId   `json:"id,omitempty" mapstructure:"id,omitempty" msgpack:"id,omitempty"`
	SocketHandshake *socket.Handshake `json:"handshake,omitempty" mapstructure:"handshake,omitempty" msgpack:"handshake,omitempty"`
	SocketRooms     []socket.Room     `json:"rooms,omitempty" mapstructure:"rooms,omitempty" msgpack:"rooms,omitempty"`
	SocketData      any               `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*ResponseSockets) Data

func (r *ResponseSockets) Data() any

func (*ResponseSockets) Handshake

func (r *ResponseSockets) Handshake() *socket.Handshake

func (*ResponseSockets) Id

func (*ResponseSockets) Rooms

func (r *ResponseSockets) Rooms() *types.Set[socket.Room]

type SentRequest

type SentRequest struct {
	Type     _types.RequestType
	Resolve  func(any, error)
	Timeout  *utils.Timer
	NumSub   int64
	MsgCount int64

	Rooms     []socket.Room
	Sockets   []*ResponseSockets
	Responses []any
}

type ServerRequest

type ServerRequest struct {
	RequestId string             `json:"requestId,omitempty" mapstructure:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Uid       string             `json:"uid,omitempty" mapstructure:"uid,omitempty" msgpack:"uid,omitempty"`
	Type      _types.RequestType `json:"type,omitempty" mapstructure:"type,omitempty" msgpack:"type,omitempty"`
	Data      []any              `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
}

type ShardedRedisAdapter

type ShardedRedisAdapter interface {
	ClusterAdapter

	SetRedis(*types.RedisClient)
	SetOpts(*ShardedRedisAdapterOptions)
}

func MakeShardedRedisAdapter

func MakeShardedRedisAdapter() ShardedRedisAdapter

type ShardedRedisAdapterBuilder

type ShardedRedisAdapterBuilder struct {
	socket.AdapterConstructor

	// a Redis client
	Redis *_types.RedisClient
	// additional options
	Opts *ShardedRedisAdapterOptions
}

Create a new Adapter based on Redis sharded Pub/Sub introduced in Redis 7.0.

See: https://redis.io/docs/manual/pubsub/#sharded-pubsub

func (*ShardedRedisAdapterBuilder) New

type ShardedRedisAdapterOptions

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

func DefaultShardedRedisAdapterOptions

func DefaultShardedRedisAdapterOptions() *ShardedRedisAdapterOptions

func (*ShardedRedisAdapterOptions) ChannelPrefix

func (s *ShardedRedisAdapterOptions) ChannelPrefix() string

func (*ShardedRedisAdapterOptions) GetRawChannelPrefix

func (s *ShardedRedisAdapterOptions) GetRawChannelPrefix() *string

func (*ShardedRedisAdapterOptions) GetRawSubscriptionMode

func (s *ShardedRedisAdapterOptions) GetRawSubscriptionMode() *subMode

func (*ShardedRedisAdapterOptions) SetChannelPrefix

func (s *ShardedRedisAdapterOptions) SetChannelPrefix(channelPrefix string)

func (*ShardedRedisAdapterOptions) SetSubscriptionMode

func (s *ShardedRedisAdapterOptions) SetSubscriptionMode(subMode subMode)

func (*ShardedRedisAdapterOptions) SubscriptionMode

func (s *ShardedRedisAdapterOptions) SubscriptionMode() subMode

type ShardedRedisAdapterOptionsInterface

type ShardedRedisAdapterOptionsInterface interface {
	SetChannelPrefix(string)
	GetRawChannelPrefix() *string
	ChannelPrefix() string

	SetSubscriptionMode(subMode)
	GetRawSubscriptionMode() *subMode
	SubscriptionMode() subMode
}

Jump to

Keyboard shortcuts

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