Skip to content

Instantly share code, notes, and snippets.

@yuksbg
Created June 15, 2016 17:00
Show Gist options
  • Save yuksbg/54e40ecc36ac44cb73daf77579a3eff4 to your computer and use it in GitHub Desktop.
Save yuksbg/54e40ecc36ac44cb73daf77579a3eff4 to your computer and use it in GitHub Desktop.
Quick and dirty example for FCM XMPP server which uses channels for comunications
package main
import (
"github.com/titan-x/gcm/ccs"
"log"
"time"
"encoding/json"
)
func sendMe(sendM chan string) {
for {
select {
case <-time.After(time.Duration(2e9)):
sendM <- "test 11"
}
}
}
func read(c *ccs.Conn, rec chan string) {
for {
m, _ := c.Receive()
go func(m *ccs.InMsg, rec chan string) {
dd, _ := json.Marshal(m)
rec <- string(dd)
}(m,rec)
}
}
func main() {
// fcm-xmpp.googleapis.com:5235 for prod
c, err := ccs.Connect("fcm-xmpp.googleapis.com:5236", "APP_ID", "APP_KEY", false)
if err != nil {
return
}
send := make(chan string)
rec := make(chan string)
go sendMe(send)
go read(c,rec)
for {
select {
case el := <-send:
log.Println(el)
_, err = c.Send(&ccs.OutMsg{To: "device_registration_id", Data: map[string]string{"test_message": el}})
case msg := <- rec:
log.Println(msg)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment