connectionutils

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 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
}

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{}

	EnableAutoReconnect  bool
	MaxReconnectAttempts int
	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) SetStatus added in v0.73.0

func (c *WSConnection) SetStatus(status 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

Jump to

Keyboard shortcuts

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