Documentation
¶
Overview ¶
Package wsevent implements thread-safe event-driven communication similar to socket.IO, on the top of Gorilla's WebSocket implementation.
Index ¶
- type Client
- type Receiver
- type Server
- func (s *Server) Broadcast(room string, data string)
- func (s *Server) BroadcastJSON(room string, v interface{})
- func (s *Server) Clients() int64
- func (s *Server) Close()
- func (s *Server) Join(c *Client, r string)
- func (s *Server) Leave(client *Client, r string)
- func (s *Server) NewClient(upgrader ws.Upgrader, w http.ResponseWriter, r *http.Request) (*Client, error)
- func (s *Server) NewClientWithID(upgrader ws.Upgrader, w http.ResponseWriter, r *http.Request, id string) (*Client, error)
- func (s *Server) On(event string, f interface{})
- func (s *Server) Register(rcvr Receiver)
- func (s *Server) Rooms() map[string]int
- func (s *Server) RoomsJoined(id string) []string
- type ServerCodec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
ID string //Session ID
Request *http.Request //http Request when connection was upgraded
Token *jwt.Token //if any
// contains filtered or unexported fields
}
Client represents a server-side client
type Receiver ¶
A Receiver interface implements the Name method, which returns a name for the event, given a registered function's name.
type Server ¶
type Server struct {
//Called when the websocket connection closes. The disconnected client's
//session ID is sent as an argument
OnDisconnect func(string, *jwt.Token)
// Used to wait for all requests to complete
Requests *sync.WaitGroup
// contains filtered or unexported fields
}
Server represents an RPC server
func NewServer ¶
func NewServer(codec ServerCodec, defaultHandler interface{}) *Server
NewServer returns a new server
func (*Server) BroadcastJSON ¶
BroadcastJSON broadcasts the json encoding of v to all clients in room
func (*Server) NewClientWithID ¶
func (*Server) On ¶
On Registers a callback for the event string. It panics if the callback isn't valid
func (*Server) Register ¶
Register is similar to net/rpc's Register, expect that rcvr needs to implement the Receiver interface
func (*Server) RoomsJoined ¶
RoomsJoined returns an array of rooms the client c has been added to
type ServerCodec ¶
type ServerCodec interface {
//ReadName reads the received data and returns the method/event name
ReadName([]byte) string
//Unmarshal reads the recieved paramters in the provided object, and returns errors
//if (any) while unmarshaling, which is then sent a reply
Unmarshal([]byte, interface{}) error
//Error wraps the error returned by Unmarshal into a json-marshalable object
Error(error) interface{}
}
ServerCodec implements a codec for reading method/event names and their parameters.