-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgcm.go
57 lines (47 loc) · 1.07 KB
/
gcm.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
54
55
56
57
package titan
import (
"log"
"strconv"
"github.com/soygul/gcm/ccs"
)
func listenGCM() {
c, err := ccs.Connect(Conf.GCM.CCSHost, Conf.GCM.SenderID, Conf.GCM.APIKey(), Conf.App.Debug)
if err != nil {
log.Fatalln("gcm: failed to connect to GCM CCS with error:", err)
}
log.Println("gcm: started")
for {
m, err := c.Receive()
if err != nil {
log.Println("gcm: error receiving message:", err)
}
go readHandler(m)
}
}
func readHandler(m *ccs.InMsg) {
t := m.Data["n.message_type"]
if t == "" {
log.Printf("gcm: malformed message from device: %+v\n", m)
return
}
switch t {
case "message":
ids := m.Data["n.to"]
if ids == "" {
log.Printf("gcm: malformed message from device: %+v\n", m)
return
}
id64, err := strconv.ParseUint(ids, 10, 32)
if err != nil || id64 == 0 {
log.Printf("gcm: invalid user ID specific in 'n.to' data field in message from device: %+v\n", m)
return
}
// id := uint32(id64)
// user, ok := users[id]
// if !ok {
// log.Printf("User not found in user list: %+v\n", m)
// }
//
// user.Send(m.Data)
}
}