Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ConnManager stores all Conn types by their uuid ConnManager = struct { Conns *sync.Map }{ Conns: new(sync.Map), } // Emitter emits received Messages with non-reserved event names Emitter = emission.NewEmitter() )
RoomManager stores all Room types by their name
Functions ¶
func HandleData ¶
HandleData handles incoming, error free messages
func SocketHandler ¶
func SocketHandler(cr CookieReader) http.HandlerFunc
SocketHandler calls NewConnection, starts the returned Conn's writer, joins the root room, and finally starts the Conn's reader
Types ¶
type Conn ¶
type Conn struct { Cookie *sync.Map Socket *websocket.Conn ID string Send chan []byte Rooms *sync.Map }
Conn type represents a single client
func NewConnection ¶
func NewConnection(w http.ResponseWriter, r *http.Request, cr CookieReader) *Conn
NewConnection upgrades an HTTP connection and creates a new Conn type
type Message ¶
type Message struct { RoomLength int `json:"roomLength"` // room name length Room string `json:"room"` // room name EventLength int `json:"eventLength"` // event name length Event string `json:"event"` // event name DstLength int `json:"dstLength"` // destination id length Dst string `json:"dst"` // destination id SrcLength int `json:"srcLength"` // source id length Src string `json:"src"` // source id PayloadLength int `json:"payloadLength"` // payload length Payload []byte `json:"payload"` // payload }
Message protocol followed by wsrooms servers and clients
func BytesToMessage ¶
BytesToMessage returns a Message type from bytes
func ConstructMessage ¶
ConstructMessage constructs and returns a new Message type
type Room ¶
type Room struct { Name string Members *sync.Map Send chan *RoomMessage // contains filtered or unexported fields }
Room type represents a communication channel
type RoomMessage ¶
RoomMessage used only with a room's Send channel
Click to show internal directories.
Click to hide internal directories.