connectionutils

package
v0.1.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: 2

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

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

Types

type ConnectionManager

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

type LobbyWebSocketClient

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

LobbyWebSocketClient is the extended implementation of ConnectionManagerImpl

func NewLobbyWebSocketClient

func NewLobbyWebSocketClient(wsConn *WSConnection) *LobbyWebSocketClient

func (*LobbyWebSocketClient) ClearData

func (c *LobbyWebSocketClient) ClearData()

func (*LobbyWebSocketClient) Close

func (c *LobbyWebSocketClient) Close() error

func (*LobbyWebSocketClient) Connect

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

func (*LobbyWebSocketClient) Get

func (*LobbyWebSocketClient) GetData

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

func (*LobbyWebSocketClient) HasData

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

func (*LobbyWebSocketClient) OnConnect

func (c *LobbyWebSocketClient) OnConnect(reconnecting bool)

func (*LobbyWebSocketClient) OnDisconnect

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

func (*LobbyWebSocketClient) OnMessage

func (c *LobbyWebSocketClient) OnMessage(msg string)

func (*LobbyWebSocketClient) ReadWSMessage

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

func (*LobbyWebSocketClient) ReconnectDelay

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

func (*LobbyWebSocketClient) Save

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

func (*LobbyWebSocketClient) Send

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

func (*LobbyWebSocketClient) SetData

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

func (*LobbyWebSocketClient) ShouldReconnect

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

func (*LobbyWebSocketClient) WSHeartbeat

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

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

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

func (*WSConnection) DefaultCloseHandler

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

func (*WSConnection) DefaultPongHandler

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

func (*WSConnection) Dial

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

func (*WSConnection) GetData

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

func (*WSConnection) GetStatus

func (c *WSConnection) GetStatus() string

func (*WSConnection) Lock

func (c *WSConnection) Lock(location string)

func (*WSConnection) SetStatus

func (c *WSConnection) SetStatus(status string)

func (*WSConnection) Unlock

func (c *WSConnection) Unlock(location string)

type WSConnectionMessageHandler

type WSConnectionMessageHandler func(msg []byte)

type WSConnectionOption

type WSConnectionOption func(wsConn *WSConnection) error

func WithEnableAutoReconnect

func WithEnableAutoReconnect() WSConnectionOption

func WithMaxReconnectAttempts

func WithMaxReconnectAttempts(maxReconnectAttempts int) WSConnectionOption

func WithMessageHandler

func WithMessageHandler(handler WSConnectionMessageHandler) WSConnectionOption

func WithScheme

func WithScheme(scheme string) WSConnectionOption

func WithStatusHandler

func WithStatusHandler(handler WSConnectionStatusHandler) WSConnectionOption

func WithToken

func WithToken(token string) WSConnectionOption

type WSConnectionStatusHandler

type WSConnectionStatusHandler func(status string)

Jump to

Keyboard shortcuts

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