##Triggering Events
client := pusher.Client{
AppId: app_id,
Key: app_key,
Secret: app_secret,
}
data := map[string]string{"message": "hello world"}
client.Trigger("test_channel", "my_event", data)
In place of the ""
in the last example, we enter the socket_id of the connection we wish to exclude from receiving the event:
client.Trigger("test_channel", "my_event", data, "1234.5678")
##Info From All Channels
channelParams := map[string]string{
"filter_by_prefix": "presence-",
"info": "user_count"}
channels, err := client.Channels(channelParams)
fmt.Printf(channels)
// => &{Channels:map[presence-chatroom:{UserCount:4} private-notifications:{UserCount:31} ]}
##Info From One Channel
channelParams := map[string]string{
"info": "user_count"}
channel, err := client.Channel("presence-chatroom", channelParams)
###Gettings Users From Presence Channel
users, err := client.GetChannelUsers("presence-chatroom")
func pusherAuth(res http.ResponseWriter, req *http.Request) {
params, _ := ioutil.ReadAll(req.Body)
auth := client.AuthenticateChannel(params)
fmt.Fprintf(res, auth)
}
func main() {
http.HandleFunc("/", root)
http.HandleFunc("/pusher/auth", pusherAuth)
http.ListenAndServe(":5000", nil)
}
Like private channels, but one passes in user data to be associated with the member.
params, _ := ioutil.ReadAll(req.Body)
presenceData := pusher.MemberData{
UserId: "1",
UserInfo: map[string]string{"twitter": "jamiepatel"}}
auth := client.AuthenticateChannel(params, presenceData)
fmt.Fprintf(res, auth)
body, _ := ioutil.ReadAll(req.Body)
webhook, err := client.Webhook(req.Header, body)
if err != nil {
fmt.Println("Webhook is invalid :(")
} else {
fmt.Printf("%+v\n", webhook)
}
Feature | Supported |
---|---|
Trigger event on single channel | ✔ |
Trigger event on multiple channels | ✔ |
Limit channels Per trigger to 10 | ✔ |
Limit channel/event name length | ✔ |
Validates channel names | ✔ |
Excluding recipients from events | ✔ |
Authenticating private channels | ✔ |
Authenticating presence channels | ✔ |
Get the list of channels in an application | ✔ |
Get the state of a single channel | ✔ |
Get a list of users in a presence channel | ✔ |
WebHook validation | ✔ |
Can instantiate from URL/ENV | ✔ |
Debugging & Logging | ✔ |
Cluster configuration | ✔ |
Timeouts | ✔ |
HTTPS | ✔ |
HTTP Proxy configuration | ✘ |
HTTP KeepAlive | ✘ |
##TODO:
- Finish feature support
- More thorough error-handling.
- Asynchronous requests(?)
- General refactoring
##Running The Tests
$ go test