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() }
func SendNotification(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") r.ParseForm() iBadge, err := strconv.Atoi(r.PostFormValue("badge")) if err != nil { iBadge = 0 } var jsonResult []byte var e error if r.PostFormValue("token") == "" { /*jsonResult, e = */ core.SendNotificationToAllRegisteredDevices(r.PostFormValue("message"), iBadge, r.PostFormValue("sound")) } else { jsonResult, e = core.SendNotificationToSingleDevice(r.PostFormValue("message"), iBadge, r.PostFormValue("sound"), r.PostFormValue("token")) } if e == nil { w.Write(jsonResult) } else { w.Write([]byte("{ Error: \"" + e.Error() + "\"}")) } }