package ws import ( "encoding/json" "gopkg.in/olahol/melody.v1" ) type Client struct { Id string // account_typ:account_id AccountId int64 AccountType string Pid int64 Online bool RoomId string node *Node *melody.Session } func NewClient(session *melody.Session, node *Node, roomId string) *Client { client := new(Client) client.Session = session client.node = node client.Online = false client.RoomId = roomId return client } func (c *Client) BroadcastAll(msg *Message) { c.node.BroadcastAll(msg, c) } func (c *Client) Register() error { return c.node.RegisterClient(c) } func (c *Client) Send(msg *Message) { c.node.Send(msg) } func (c *Client) WriteJson(body interface{}) error { bs, err := json.Marshal(&body) if err != nil { return err } return c.Write(bs) }