connectionutils

package
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Disconnected = "Disconnected"
	Connecting   = "Connecting"
	Connected    = "Connected"
	Reconnecting = "Reconnecting"
	Closed       = "Closed"
)
View Source
const (
	LobbySessionID = "lobbySessionID"
)

Variables

This section is empty.

Functions

func DecodeWSMessage added in v0.73.0

func DecodeWSMessage(msg string) map[string]interface{}

Types

type ConnectionManager

type ConnectionManager interface {
	Save(wsConnection *WSConnection)
	Get() *WSConnection
	Close() error
}

type ConnectionStatus added in v0.73.0

type ConnectionStatus string

type LobbyWebSocketClient added in v0.73.0

type LobbyWebSocketClient struct {
	WSConn *WSConnection
	// contains filtered or unexported fields
}

LobbyWebSocketClient is the extended implementation of ConnectionManagerImpl

func NewLobbyWebSocketClient added in v0.73.0

func NewLobbyWebSocketClient(wsConn *WSConnection) *LobbyWebSocketClient

func (*LobbyWebSocketClient) ClearData added in v0.73.0

func (c *LobbyWebSocketClient) ClearData()

func (*LobbyWebSocketClient) Close added in v0.73.0

func (c *LobbyWebSocketClient) Close() error

func (*LobbyWebSocketClient) Connect added in v0.73.0

func (c *LobbyWebSocketClient) Connect(reconnecting bool) (bool, error)

func (*LobbyWebSocketClient) Get added in v0.73.0

func (*LobbyWebSocketClient) GetData added in v0.73.0

func (c *LobbyWebSocketClient) GetData(key string) interface{}

func (*LobbyWebSocketClient) HasData added in v0.73.0

func (c *LobbyWebSocketClient) HasData(key string) bool

func (*LobbyWebSocketClient) OnConnect added in v0.73.0

func (c *LobbyWebSocketClient) OnConnect(reconnecting bool)

func (*LobbyWebSocketClient) OnDisconnect added in v0.73.0

func (c *LobbyWebSocketClient) OnDisconnect(code int32, reason string)

func (*LobbyWebSocketClient) OnMessage added in v0.73.0

func (c *LobbyWebSocketClient) OnMessage(msg string)

func (*LobbyWebSocketClient) ReadWSMessage added in v0.73.0

func (c *LobbyWebSocketClient) ReadWSMessage(done chan struct{}, messageHandler func(message []byte))

func (*LobbyWebSocketClient) ReconnectDelay added in v0.73.0

func (c *LobbyWebSocketClient) ReconnectDelay(numberOfAttempts int32) float32

func (*LobbyWebSocketClient) Save added in v0.73.0

func (c *LobbyWebSocketClient) Save(conn *WSConnection)

func (*LobbyWebSocketClient) Send added in v0.73.0

func (c *LobbyWebSocketClient) Send(code int, message string) error

func (*LobbyWebSocketClient) SetData added in v0.73.0

func (c *LobbyWebSocketClient) SetData(key string, value interface{})

func (*LobbyWebSocketClient) ShouldReconnect added in v0.73.0

func (c *LobbyWebSocketClient) ShouldReconnect(code int, reason string, numberOfAttempts int) bool

func (*LobbyWebSocketClient) WSHeartbeat added in v0.73.0

func (c *LobbyWebSocketClient) WSHeartbeat(done chan struct{})

type WSConnection

type WSConnection struct {
	Conn     *websocket.Conn
	Mu       sync.RWMutex
	MuStatus sync.RWMutex

	Header http.Header
	Data   map[string]interface{}
	Meta   map[string]interface{}

	EnableAutoReconnect  bool
	MaxReconnectAttempts int
	StatusHandler        WSConnectionStatusHandler
	MessageHandler       WSConnectionMessageHandler
	// contains filtered or unexported fields
}

func NewWSConnection added in v0.73.0

func NewWSConnection(
	configRepo repository.ConfigRepository,
	tokenRepo repository.TokenRepository,
	options ...WSConnectionOption,
) (*WSConnection, error)

func NewWebsocketConnection

func NewWebsocketConnection(
	configRepo repository.ConfigRepository,
	tokenRepo repository.TokenRepository,
	messageHandler func(msg []byte),
) (*WSConnection, error)

NewWebsocketConnection Deprecated: use NewWSConnection instead

func (*WSConnection) Close added in v0.73.0

func (c *WSConnection) Close(code int, reason string) error

func (*WSConnection) DefaultCloseHandler added in v0.73.0

func (c *WSConnection) DefaultCloseHandler(code int, reason string) error

func (*WSConnection) DefaultPongHandler added in v0.73.0

func (c *WSConnection) DefaultPongHandler(text string) error

func (*WSConnection) Dial added in v0.73.0

func (c *WSConnection) Dial(url string, headers http.Header) (*websocket.Conn, error)

func (*WSConnection) GetData added in v0.73.0

func (c *WSConnection) GetData(key string) interface{}

func (*WSConnection) GetStatus added in v0.73.0

func (c *WSConnection) GetStatus() string

func (*WSConnection) Lock added in v0.74.0

func (c *WSConnection) Lock(location string)

func (*WSConnection) SetStatus added in v0.73.0

func (c *WSConnection) SetStatus(status string)

func (*WSConnection) Unlock added in v0.74.0

func (c *WSConnection) Unlock(location string)

type WSConnectionMessageHandler added in v0.73.0

type WSConnectionMessageHandler func(msg []byte)

type WSConnectionOption added in v0.73.0

type WSConnectionOption func(wsConn *WSConnection) error

func WithEnableAutoReconnect added in v0.73.0

func WithEnableAutoReconnect() WSConnectionOption

func WithMaxReconnectAttempts added in v0.73.0

func WithMaxReconnectAttempts(maxReconnectAttempts int) WSConnectionOption

func WithMessageHandler added in v0.73.0

func WithMessageHandler(handler WSConnectionMessageHandler) WSConnectionOption

func WithScheme added in v0.74.0

func WithScheme(scheme string) WSConnectionOption

func WithStatusHandler added in v0.74.0

func WithStatusHandler(handler WSConnectionStatusHandler) WSConnectionOption

func WithToken added in v0.74.0

func WithToken(token string) WSConnectionOption

type WSConnectionStatusHandler added in v0.74.0

type WSConnectionStatusHandler func(status string)

Jump to

Keyboard shortcuts

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