Documentation ¶
Index ¶
- Variables
- type Client
- type Config
- type Message
- type Server
- func (s *Server) Broadcast(room, name string, code int, data []byte)
- func (s *Server) BroadcastAll(name string, code int, data []byte)
- func (s *Server) OnConnClose(fn func(*Client))
- func (s *Server) OnConnReady(fn func(*Client))
- func (s *Server) OnConnected(fn func(w http.ResponseWriter, r *http.Request) (room, name string, ok bool))
- func (s *Server) OnMessage(fn func(*Message))
- func (s *Server) OnRoomClose(fn func(room string))
- func (s *Server) OnRoomReady(fn func(room string))
- func (s *Server) OnServClose(fn func())
- func (s *Server) Run(ctx context.Context)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, room, name string) error
- type WorkerConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = &Config{ SignBufferCount: 128, CastBufferCount: 128, Worker: WorkerConfig{ SignBufferCount: 128, CastBufferCount: 128, Local: false, }, }
DefaultConfig is a server with all fields set to the default values.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // register, unregister room buffer count SignBufferCount int // broadcast message to room buffer count CastBufferCount int Worker WorkerConfig }
Config describes the configuration of the server.
type Message ¶
type Message struct { Room string Name string Code int Data []byte // contains filtered or unexported fields }
Message represents a message send and received from the Websocket connection.
Code is websocket Opcode Name is user custom Name
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is lightcable core Server. use callback notification message broadcast message, A Server auto create and manage multiple goroutines every room create worker
func (*Server) Broadcast ¶
Broadcast will room all websocket connection send message https://www.rfc-editor.org/rfc/rfc6455.html#section-11.8 code is websocket Opcode name is custom name, this will be callback OnMessage
func (*Server) BroadcastAll ¶
BroadcastAll will all room all websocket connection send message
func (*Server) OnConnClose ¶
OnConnClose will Client error or websocket close or server close if context server closed err == nil
func (*Server) OnConnReady ¶
OnConnReady websocket connection successfully and join room this will block worker
func (*Server) OnConnected ¶
func (s *Server) OnConnected(fn func(w http.ResponseWriter, r *http.Request) (room, name string, ok bool))
OnConnected auth this websocket connection callback ok: true Allows connection; false Reject connection Maybe Concurrent. unique ID need self use sync.Mutex
func (*Server) OnMessage ¶
OnMessage will all Websocket Conn Recv Message will callback this function This have Block worker. Block this room
func (*Server) OnRoomClose ¶
OnRoomClose worker all websocket connection closed, worker close
func (*Server) OnRoomReady ¶
OnRoomReady Create a new room successfully
func (*Server) OnServClose ¶
func (s *Server) OnServClose(fn func())
OnServClose server safely shutdown done callback
func (*Server) Run ¶
Run need use 'go server.Run(context.Background())' run daemon in order to concurrency. server instance only a run
type WorkerConfig ¶ added in v0.2.0
type WorkerConfig struct { // register, unregister client buffer count SignBufferCount int // broadcast message to client buffer count CastBufferCount int // If you set this option as `false` // The server will not broadcast to you messages you send. // Look like MQTTv5 nolocal Local bool }
Worker Config describes the configuration of the server. server should worker, every worker use this configuration