-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.go
More file actions
45 lines (33 loc) · 768 Bytes
/
socket.go
File metadata and controls
45 lines (33 loc) · 768 Bytes
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
package main
import (
"encoding/json"
"github.com/googollee/go-socket.io"
"github.com/r4mp/c3an/core"
"log"
)
type Engel struct {
Text string
Time string
Id int
Issuer string
}
func receiveMessages() {
var engel Engel
client, err := socketio.Dial("http://ara.uberspace.de:62961/")
if err != nil {
log.Fatal(err)
}
client.On("engel", func(ns *socketio.NameSpace, message string) {
log.Println(message)
err := json.Unmarshal([]byte(message), &engel)
if err == nil {
core.SendNotificationToAllRegisteredDevices(engel.Text, 0, "bingbong.aiff")
} else {
log.Println("Can't unmarshal message: " + message)
}
})
client.On("reload", func(ns *socketio.NameSpace, message string) {
log.Println(message)
})
client.Run()
}