Created
June 15, 2016 17:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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