Documentation ¶
Overview ¶
Protocol:
1) We log in into a room Request: {"user":"user1","room":"room1", "avatar": 12} Response: "OK"
{ "type": "login_success" } { "type": "login_fail", "reason": "already_logged_in" } { "type": "login_fail", "reason": "room full" }
2) User can send a chat message into the room Request: {"type":"chat","text":"Hello world"}
3) Server can push back other users' chat messages Pushing:
{ "type":"chat", "messages": [ { "text":"Hello world", "user":"user2", "created":"2020-01-01 00:00:00" }, { "text":"Hello world", "user":"user3", "created":"2020-01-01 00:00:00" }, ] }
4) Sets the current state of the room. Pushing {"type":"room","users":[{name:"user1", avatar:12, is_host:true}]}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatBatch ¶
type ChatBatch struct { Type string `json:"type"` Messages []ChatBatchItem `json:"messages"` }
type ChatBatchItem ¶
type GameAction ¶
type GameAction struct { Action string `json:"action"` // kind of action Payload json.RawMessage `json:"payload,omitempty"` // optional payload }
type KickMessage ¶
type KickMessage struct {
User string `json:"user"`
}
type NewMessage ¶
type NewMessage struct {
Text string `json:"text"`
}
type Room ¶
type Room struct { Name string Host string // name of the user who created the room Registry map[string]StartGameFn // contains filtered or unexported fields }
func (*Room) SendGameAction ¶
func (*Room) SendGameChat ¶
func (r *Room) SendGameChat(m *game.NewChatMessage, users ...string)
SendGameChat message to a given user, without adding it to the history.
type Server ¶
type Server struct { Registry map[string]StartGameFn Rooms map[string]*Room // contains filtered or unexported fields }
func NewServer ¶
func NewServer(games map[string]StartGameFn) *Server
type StartGameFn ¶
type StartGameMessage ¶
type StartGameMessage struct { Game string `json:"game"` Settings json.RawMessage `json:"settings"` }
Click to show internal directories.
Click to hide internal directories.