Documentation ¶
Index ¶
- type Action
- type Client
- type Message
- func (m *Message) GetBool(key string) (bool, bool)
- func (m *Message) GetFloat64(key string) (float64, bool)
- func (m *Message) GetInt64(key string) (int64, bool)
- func (m *Message) GetString(key string) (string, bool)
- func (m *Message) Marshal() []byte
- func (m *Message) Set(key string, val interface{})
- func (m *Message) Unmarshal(data []byte)
- type MessagePayload
- type Room
- func (r *Room) AddHandler(message string, f RoomHandler)
- func (r *Room) Broadcast(message string, p *MessagePayload)
- func (r *Room) BroadcastMsg(msg *Message)
- func (r *Room) ClientsCount() int
- func (r *Room) Enter(c *Client)
- func (r *Room) Handle(a *Action)
- func (r *Room) Leave(c *Client)
- func (r *Room) OnQuit(f func(r *Room))
- func (r *Room) Quit()
- func (r *Room) Run()
- func (r *Room) SetOnEnter(f RoomCientLifecycleCallback)
- func (r *Room) SetOnLeave(f RoomCientLifecycleCallback)
- type RoomCientLifecycleCallback
- type RoomHandler
- type RoomManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a middleman between the websocket connection and the hub.
func (*Client) Broadcast ¶
func (c *Client) Broadcast(message string, payload *MessagePayload)
Broadcast Broadcasts a mesage to the room of the client
func (*Client) SendWithPayload ¶
func (c *Client) SendWithPayload(msg string, p *MessagePayload)
SendWithPayload sends a message to client
type Message ¶
type Message struct { //Room string `json:"-"` Message string `json:"m"` Payload MessagePayload `json:"p"` }
Message message datatype
func (*Message) GetFloat64 ¶
GetFloat64 try to get a float64 from payload
type MessagePayload ¶
type MessagePayload map[string]interface{}
MessagePayload Message Payload datatype
type Room ¶
Room room datatype
func (*Room) AddHandler ¶
func (r *Room) AddHandler(message string, f RoomHandler)
AddHandler adds a handler for the given msg
func (*Room) Broadcast ¶
func (r *Room) Broadcast(message string, p *MessagePayload)
Broadcast broadcasts the given message to all room clients
func (*Room) BroadcastMsg ¶
BroadcastMsg broadcasts the given message to all room clients
func (*Room) ClientsCount ¶
ClientsCount returns the number of clients connected
func (*Room) SetOnEnter ¶
func (r *Room) SetOnEnter(f RoomCientLifecycleCallback)
SetOnEnter sets room onEnter callback
func (*Room) SetOnLeave ¶
func (r *Room) SetOnLeave(f RoomCientLifecycleCallback)
SetOnLeave sets room OnLeave callback
type RoomCientLifecycleCallback ¶
type RoomCientLifecycleCallback func(c *Client)
RoomCientLifecycleCallback RoomCientLifecycleCallback datatype
type RoomManager ¶
RoomManager room mamaber datatype
func (*RoomManager) HandleConnection ¶
func (rm *RoomManager) HandleConnection(c *gin.Context, roomName string)
HandleConnection handles websocket request
func (*RoomManager) OnQuitRoom ¶
func (rm *RoomManager) OnQuitRoom(r *Room)
OnQuitRoom OnQuitRoom gets called when a room quits