Documentation ¶
Index ¶
- Constants
- type Auth
- type BroadcastMsg
- type MultihomeBackend
- type RoomMsg
- type Socket
- func (s *Socket) Broadcast(eventName string, data interface{})
- func (s *Socket) Close()
- func (s *Socket) Emit(eventName string, data interface{}) error
- func (s *Socket) Get(key string, defaultVal interface{}) interface{}
- func (s *Socket) GetRooms() []string
- func (s *Socket) ID() string
- func (s *Socket) InRoom(roomName string) bool
- func (s *Socket) Join(roomName string)
- func (s *Socket) Leave(roomName string)
- func (s *Socket) Roomcast(roomName, eventName string, data interface{})
- func (s *Socket) Set(key string, val interface{})
- type SocketServer
- func (serv *SocketServer) EnableSignalShutdown(complete chan<- bool)
- func (serv *SocketServer) On(eventName string, handleFunc func(*Socket, []byte))
- func (serv *SocketServer) OnConnect(handleFunc func(*Socket))
- func (serv *SocketServer) OnDisconnect(handleFunc func(*Socket))
- func (serv *SocketServer) SetMultihomeBackend(b MultihomeBackend)
- func (serv *SocketServer) Shutdown() bool
- func (serv *SocketServer) WebHandler(auth Auth, origins []string) iris.HandlerFunc
Constants ¶
const (
SupportedSubProtocol string = "sac-sock"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BroadcastMsg ¶
type BroadcastMsg struct { EventName string Data interface{} }
BroadcastMsg represents an event to be dispatched to all Sockets on the SocketServer
type MultihomeBackend ¶
type MultihomeBackend interface { //Init is called as soon as the MultihomeBackend is //registered using SocketServer.SetMultihomeBackend Init() //Shutdown is called immediately after all sockets have //been closed Shutdown() //BroadcastToBackend is called everytime a BroadcastMsg is //sent by a Socket // //BroadcastToBackend must be safe for concurrent use by multiple //go routines BroadcastToBackend(*BroadcastMsg) //RoomcastToBackend is called everytime a RoomMsg is sent //by a socket, even if none of this server's sockets are //members of that room // //RoomcastToBackend must be safe for concurrent use by multiple //go routines RoomcastToBackend(*RoomMsg) //BroadcastFromBackend is called once and only once as a go routine as //soon as the MultihomeBackend is registered using //SocketServer.SetMultihomeBackend // //b consumes a BroadcastMsg and dispatches //it to all sockets on this server BroadcastFromBackend(b chan<- *BroadcastMsg) //RoomcastFromBackend is called once and only once as a go routine as //soon as the MultihomeBackend is registered using //SocketServer.SetMultihomeBackend // //r consumes a RoomMsg and dispatches it to all sockets //that are members the specified room RoomcastFromBackend(r chan<- *RoomMsg) }
MultihomeBackend is an interface for implementing a mechanism to syncronize Broadcasts and Roomcasts to multiple SocketServers running separate machines.
Sacrificial-Socket provides a MultihomeBackend for use with MongoDB in sacrificial-socket/backend
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
Socket represents a websocket connection
func (*Socket) Close ¶
func (s *Socket) Close()
Close closes the Socket connection and removes the Socket from any rooms that it was a member of
func (*Socket) Join ¶
Join adds s to the specified room. If the room does not exist, it will be created
func (*Socket) Leave ¶
Leave removes s from the specified room. If s is not a member of the room, nothing will happen. If the room is empty upon removal of s, the room will be closed
type SocketServer ¶
type SocketServer struct {
// contains filtered or unexported fields
}
SocketServer manages the coordination between sockets, rooms, events and the socket hub
func (*SocketServer) EnableSignalShutdown ¶
func (serv *SocketServer) EnableSignalShutdown(complete chan<- bool)
EnableSignalShutdown listens for linux syscalls SIGHUP, SIGINT, SIGTERM, SIGQUIT, SIGKILL and calls the SocketServer.Shutdown() to perform a clean shutdown. true will be passed into complete after the Shutdown proccess is finished
func (*SocketServer) On ¶
func (serv *SocketServer) On(eventName string, handleFunc func(*Socket, []byte))
On registers event functions to be called on individual Socket connections when the server's socket receives an Emit from the client's socket.
Any event functions registered with On, must be safe for concurrent use by multiple go routines
func (*SocketServer) OnConnect ¶
func (serv *SocketServer) OnConnect(handleFunc func(*Socket))
OnConnect registers an event function to be called whenever a new Socket connection is created
func (*SocketServer) OnDisconnect ¶
func (serv *SocketServer) OnDisconnect(handleFunc func(*Socket))
OnDisconnect registers an event function to be called as soon as a Socket connection is closed
func (*SocketServer) SetMultihomeBackend ¶
func (serv *SocketServer) SetMultihomeBackend(b MultihomeBackend)
SetMultihomeBackend registers a MultihomeBackend interface and calls it's Init() method
func (*SocketServer) Shutdown ¶
func (serv *SocketServer) Shutdown() bool
Shutdown closes all active sockets and triggers the Shutdown() method on any MultihomeBackend that is currently set.
func (*SocketServer) WebHandler ¶
func (serv *SocketServer) WebHandler(auth Auth, origins []string) iris.HandlerFunc
WebHandler returns a http.Handler to be passed into http.Handle