Working authenticated connection
This commit is contained in:
42
examples/groupme.go
Normal file
42
examples/groupme.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/thesyncim/fayec"
|
||||
"github.com/thesyncim/fayec/message"
|
||||
"github.com/thesyncim/fayec/subscription"
|
||||
"time"
|
||||
)
|
||||
|
||||
var authorizationToken = "ABC"
|
||||
|
||||
var authenticationExtension message.Extension = func(message *message.Message) {
|
||||
if message.Channel == "/meta/subscribe" {
|
||||
message.Ext = map[string]string{
|
||||
"access_token": authorizationToken,
|
||||
"timestamp": string(time.Now().Unix()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
client, err := fayec.NewClient("wss://push.groupme.com/faye", fayec.WithOutExtension(authenticationExtension))
|
||||
defer client.Disconnect()
|
||||
|
||||
if err != nil {
|
||||
fmt.Errorf("Error connecting to groupme", err)
|
||||
return
|
||||
}
|
||||
var sub *subscription.Subscription
|
||||
sub, err = client.Subscribe("/user/13685836")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = sub.OnMessage(func(channel string, data message.Data) {
|
||||
fmt.Println(data)
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user