forked from OpenAyame/ayame
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
53 lines (46 loc) · 813 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"sync"
"github.com/gorilla/websocket"
)
// Common part of structs such as client, room, hub
type Common struct {
uuid string
name string
class string
created string
}
type Client struct {
Common
device string // device unique string
hub *Hub
conn *websocket.Conn
host string
roomId string
clientId string
send chan []byte
sync.Mutex
}
// send json data
func (c *Client) SendJSON(v interface{}) error {
c.Lock()
defer c.Unlock()
return c.conn.WriteJSON(v)
}
func (c *Client) Setup(roomId string, clientId string) *Client {
c.Lock()
defer c.Unlock()
c.roomId = roomId
c.clientId = clientId
return c
}
type User struct {
Common
nick string
mail string
SNSs map[string]string
}
type Group struct {
Common
users map[string]*User
}