adapter

package
v2.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeOptions

func DecodeOptions(opts *PacketOptions) *socket.BroadcastOptions

Decode PacketOptions back into BroadcastOptions

func RandomId

func RandomId() (string, error)

func SliceMap

func SliceMap[I any, O any](i []I, converter func(I) O) (o []O)

func Tap

func Tap[T any](value T, callback func(T)) T

Tap calls the given function with the given value, then returns the value.

func Uid2

func Uid2(length int) (string, error)

Types

type Adapter

type Adapter = socket.Adapter

func MakeAdapter

func MakeAdapter() Adapter

func NewAdapter

func NewAdapter(nsp socket.Namespace) Adapter

type AdapterBuilder

type AdapterBuilder struct {
}

func (*AdapterBuilder) New

type BroadcastAck

type BroadcastAck struct {
	RequestId string `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Packet    []any  `json:"packet,omitempty" msgpack:"packet,omitempty"`
}

type BroadcastClientCount

type BroadcastClientCount struct {
	RequestId   string `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
	ClientCount uint64 `json:"clientCount,omitempty" msgpack:"clientCount,omitempty"`
}

type BroadcastMessage

type BroadcastMessage struct {
	Opts      *PacketOptions `json:"opts,omitempty" msgpack:"opts,omitempty"`
	Packet    *parser.Packet `json:"packet,omitempty" msgpack:"packet,omitempty"`
	RequestId *string        `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
}

Message for BROADCAST

type ClusterAckRequest

type ClusterAckRequest struct {
	ClientCountCallback func(uint64)
	Ack                 socket.Ack
}

type ClusterAdapter

type ClusterAdapter interface {
	Adapter

	Uid() ServerId
	OnMessage(*ClusterMessage, Offset)
	OnResponse(*ClusterResponse)
	Publish(*ClusterMessage)
	PublishAndReturnOffset(*ClusterMessage) (Offset, error)
	DoPublish(*ClusterMessage) (Offset, error)
	PublishResponse(ServerId, *ClusterResponse)
	DoPublishResponse(ServerId, *ClusterResponse) error
}

A cluster-ready adapter. Any extending interface must:

- implement [ClusterAdapter.DoPublish] and [ClusterAdapter.DoPublishResponse]

- call [ClusterAdapter.OnMessage] and [ClusterAdapter.OnResponse]

func MakeClusterAdapter

func MakeClusterAdapter() ClusterAdapter

func NewClusterAdapter

func NewClusterAdapter(nsp socket.Namespace) ClusterAdapter

type ClusterAdapterBuilder

type ClusterAdapterBuilder struct {
}

A cluster-ready adapter. Any extending interface must:

- implement [ClusterAdapter.DoPublish] and [ClusterAdapter.DoPublishResponse]

- 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(any)
}

func MakeClusterAdapterWithHeartbeat

func MakeClusterAdapterWithHeartbeat() ClusterAdapterWithHeartbeat

func NewClusterAdapterWithHeartbeat

func NewClusterAdapterWithHeartbeat(nsp socket.Namespace, opts any) ClusterAdapterWithHeartbeat

type ClusterAdapterWithHeartbeatBuilder

type ClusterAdapterWithHeartbeatBuilder struct {
	Opts ClusterAdapterOptionsInterface
}

func (*ClusterAdapterWithHeartbeatBuilder) New

type ClusterMessage

type ClusterMessage struct {
	Uid  ServerId    `json:"uid,omitempty" msgpack:"uid,omitempty"`
	Nsp  string      `json:"nsp,omitempty" msgpack:"nsp,omitempty"`
	Type MessageType `json:"type,omitempty" msgpack:"type,omitempty"`
	Data any         `json:"data,omitempty" msgpack:"data,omitempty"` // Data will hold the specific message data for different types
}

Common fields for all messages

type ClusterRequest

type ClusterRequest struct {
	Type      MessageType
	Resolve   func(*types.Slice[any])
	Timeout   *atomic.Pointer[utils.Timer]
	Expected  int64
	Current   *atomic.Int64
	Responses *types.Slice[any]
}

ClusterRequest equivalent

type ClusterResponse

type ClusterResponse = ClusterMessage

type CustomClusterRequest

type CustomClusterRequest struct {
	Type        MessageType
	Resolve     func(*types.Slice[any])
	Timeout     *atomic.Pointer[utils.Timer]
	MissingUids *types.Set[ServerId]
	Responses   *types.Slice[any]
}

type DisconnectSocketsMessage

type DisconnectSocketsMessage struct {
	Opts  *PacketOptions `json:"opts,omitempty" msgpack:"opts,omitempty"`
	Close bool           `json:"close,omitempty" msgpack:"close,omitempty"`
}

Message for DISCONNECT_SOCKETS

type FetchSocketsMessage

type FetchSocketsMessage struct {
	Opts      *PacketOptions `json:"opts,omitempty" msgpack:"opts,omitempty"`
	RequestId string         `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
}

Message for FETCH_SOCKETS

type FetchSocketsResponse

type FetchSocketsResponse struct {
	RequestId string            `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Sockets   []*SocketResponse `json:"sockets,omitempty" msgpack:"sockets,omitempty"`
}

type MessageType

type MessageType int
const (
	INITIAL_HEARTBEAT MessageType = iota + 1
	HEARTBEAT
	BROADCAST
	SOCKETS_JOIN
	SOCKETS_LEAVE
	DISCONNECT_SOCKETS
	FETCH_SOCKETS
	FETCH_SOCKETS_RESPONSE
	SERVER_SIDE_EMIT
	SERVER_SIDE_EMIT_RESPONSE
	BROADCAST_CLIENT_COUNT
	BROADCAST_ACK
	ADAPTER_CLOSE
)

type Offset

type Offset string

The unique ID of a message (for the connection state recovery feature)

type PacketOptions

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

PacketOptions represents the options for broadcasting messages.

func EncodeOptions

func EncodeOptions(opts *socket.BroadcastOptions) *PacketOptions

Encode BroadcastOptions into PacketOptions

type RemoteSocket

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

Expose of subset of the attributes and methods of the Socket struct

func MakeRemoteSocket

func MakeRemoteSocket() *RemoteSocket

func NewRemoteSocket

func NewRemoteSocket(details *SocketResponse) *RemoteSocket

func (*RemoteSocket) Construct

func (r *RemoteSocket) Construct(details *SocketResponse)

func (*RemoteSocket) Data

func (r *RemoteSocket) Data() any

func (*RemoteSocket) Handshake

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

func (*RemoteSocket) Id

func (r *RemoteSocket) Id() socket.SocketId

func (*RemoteSocket) Rooms

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

type ServerId

type ServerId string

The unique ID of a server

const (
	EMITTER_UID     ServerId      = "emitter"
	DEFAULT_TIMEOUT time.Duration = 5_000 * time.Millisecond
)

type ServerSideEmitMessage

type ServerSideEmitMessage struct {
	RequestId *string `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Packet    []any   `json:"packet,omitempty" msgpack:"packet,omitempty"`
}

Message for SERVER_SIDE_EMIT

type ServerSideEmitResponse

type ServerSideEmitResponse struct {
	RequestId string `json:"requestId,omitempty" msgpack:"requestId,omitempty"`
	Packet    []any  `json:"packet,omitempty" msgpack:"packet,omitempty"`
}

type SessionAwareAdapter

type SessionAwareAdapter = socket.SessionAwareAdapter

func MakeSessionAwareAdapter

func MakeSessionAwareAdapter() SessionAwareAdapter

func NewSessionAwareAdapter

func NewSessionAwareAdapter(nsp socket.Namespace) SessionAwareAdapter

type SessionAwareAdapterBuilder

type SessionAwareAdapterBuilder struct {
}

func (*SessionAwareAdapterBuilder) New

type SocketResponse

type SocketResponse struct {
	Id        socket.SocketId   `json:"id,omitempty" msgpack:"id,omitempty"`
	Handshake *socket.Handshake `json:"handshake,omitempty" msgpack:"handshake,omitempty"`
	Rooms     []socket.Room     `json:"rooms,omitempty" msgpack:"rooms,omitempty"`
	Data      any               `json:"data,omitempty" msgpack:"data,omitempty"`
}

type SocketsJoinLeaveMessage

type SocketsJoinLeaveMessage struct {
	Opts  *PacketOptions `json:"opts,omitempty" msgpack:"opts,omitempty"`
	Rooms []socket.Room  `json:"rooms,omitempty" msgpack:"rooms,omitempty"`
}

Message for SOCKETS_JOIN, SOCKETS_LEAVE

Jump to

Keyboard shortcuts

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