Documentation ¶
Index ¶
- Constants
- type Batch
- type Connection
- func (c *Connection) Get(key string) interface{}
- func (c *Connection) Locals(key string) interface{}
- func (c *Connection) Publish(msg *Message, filter Filter)
- func (c *Connection) SendMessage(msg *Message)
- func (c *Connection) SendMessageUnBatched(msg *Message)
- func (c *Connection) Set(key string, value interface{})
- type Filter
- type Logger
- type Message
- type MessageWithConnection
- type OnConnectionClose
- type OnEndFunc
- type Payload
- type Server
- func (s *Server) Connect(conn *Connection)
- func (s *Server) CountConnections(filter Filter) int
- func (s *Server) GetBatches() []string
- func (s *Server) Handler(c *fiber.Ctx) error
- func (s *Server) Publish(msg *Message, filter Filter)
- func (s *Server) SetOnConnectionClose(fn OnConnectionClose)
- func (s *Server) Shutdown()
- func (s *Server) Subscribe(eventName string, handler func(msg *MessageWithConnection)) error
- func (s *Server) UseBatch(event string, interval time.Duration) error
- type ServerConfig
- type ServiceContainer
- type WebsocketConn
- type WebsocketConnMock
Constants ¶
const PingInterval = (PongTimeout * 9) / 10
const PongTimeout = 60 * time.Second
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶ added in v0.9.0
type Batch struct {
// contains filtered or unexported fields
}
func (*Batch) AddPayload ¶ added in v0.9.0
AddPayload add payload to the batch
func (*Batch) GetDataAndRemoveAll ¶ added in v0.9.0
GetDataAndRemoveAll get the current payload batch and remove all data from the batch
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection on a websocket
func NewConnection ¶
func NewConnection(s *Server, wc WebsocketConn, ctx context.Context, cancel func()) *Connection
NewConnection constructor
func (*Connection) Get ¶
func (c *Connection) Get(key string) interface{}
Get the value of a key on the connection. Returns nil if the key does not exist
func (*Connection) Locals ¶ added in v0.3.0
func (c *Connection) Locals(key string) interface{}
Locals gets a local by key from the underlying connection.
func (*Connection) Publish ¶
func (c *Connection) Publish(msg *Message, filter Filter)
Publish a message to all matching connections
func (*Connection) SendMessage ¶
func (c *Connection) SendMessage(msg *Message)
SendMessage via this connection. Message can be sent batched using `UseBatch`.
func (*Connection) SendMessageUnBatched ¶ added in v0.10.0
func (c *Connection) SendMessageUnBatched(msg *Message)
SendMessageUnBatched send a message via this connection. Massage will not be batched.
func (*Connection) Set ¶
func (c *Connection) Set(key string, value interface{})
Set a key on a connection to a specific value. Overwrites old value.
type Filter ¶
type Filter func(c *Connection) bool
Filter function that checks if a connection matches some criteria
type Logger ¶
type Logger interface { Fatal(s string, args ...interface{}) ErrError(err error) Error(s string, args ...interface{}) ErrInfo(err error) Info(s string, args ...interface{}) Debug(s string, args ...interface{}) }
Logger interface
type MessageWithConnection ¶ added in v1.0.0
type MessageWithConnection struct { Message Connection *Connection `json:"-"` }
type OnConnectionClose ¶ added in v0.4.0
type OnConnectionClose func(c *Connection)
OnConnectionClose is executed when a connection is closed
type OnEndFunc ¶ added in v0.11.1
type OnEndFunc = func(c *Connection)
OnEndFunc function that is executed on connection ends
type Payload ¶ added in v0.5.0
type Payload map[string]interface{}
Payload send by a websocket connection
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server for websockets
func (*Server) Connect ¶ added in v0.7.0
func (s *Server) Connect(conn *Connection)
Connect a websocket to the server
func (*Server) CountConnections ¶ added in v0.2.0
CountConnections returns the number of currently active connections (a filter can be used to restrict the count)
func (*Server) GetBatches ¶ added in v0.9.0
GetBatches return the current list of batches registered for the server.
func (*Server) SetOnConnectionClose ¶ added in v0.4.0
func (s *Server) SetOnConnectionClose(fn OnConnectionClose)
SetOnConnectionClose sets the function that is executed when a connection is closed
func (*Server) Shutdown ¶ added in v0.4.0
func (s *Server) Shutdown()
Shutdown gracefully stops the server
func (*Server) Subscribe ¶
func (s *Server) Subscribe(eventName string, handler func(msg *MessageWithConnection)) error
Subscribe to a websocket event
type ServerConfig ¶
ServerConfig configuration of the server
type ServiceContainer ¶ added in v1.0.0
type ServiceContainer interface { GetLogger() Logger GetWebsocketsConfig() *ServerConfig }
type WebsocketConn ¶ added in v0.6.0
type WebsocketConn interface { ReadJSON(v interface{}) error WriteJSON(v interface{}) error WriteMessage(messageType int, data []byte) error Close() error Locals(key string) interface{} }
WebsocketConn websocket connection interface
type WebsocketConnMock ¶ added in v0.6.0
type WebsocketConnMock struct { Read chan interface{} Write chan interface{} LocalData map[string]interface{} DoError bool }
WebsocketConnMock mock struct for websocket connections You can set `DoError` to let any method that can return an error return errors
func NewWebsocketConnMock ¶ added in v0.6.0
func NewWebsocketConnMock() *WebsocketConnMock
NewWebsocketConnMock constructor
func (*WebsocketConnMock) Close ¶ added in v0.6.0
func (c *WebsocketConnMock) Close() error
Close the connection
func (*WebsocketConnMock) Locals ¶ added in v0.6.0
func (c *WebsocketConnMock) Locals(key string) interface{}
Locals access local data
func (*WebsocketConnMock) ReadJSON ¶ added in v0.6.0
func (c *WebsocketConnMock) ReadJSON(v interface{}) error
ReadJSON receives data from the Write chan
func (*WebsocketConnMock) WriteJSON ¶ added in v0.6.0
func (c *WebsocketConnMock) WriteJSON(v interface{}) error
WriteJSON writes data to the Read chan
func (*WebsocketConnMock) WriteMessage ¶ added in v0.11.8
func (c *WebsocketConnMock) WriteMessage(messageType int, data []byte) error
WriteMessage to the connection