Added util method IsClientEvent
This commit is contained in:
+1
-2
@@ -7,7 +7,6 @@ package ipe
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -215,7 +214,7 @@ func (c *channel) Publish(a *app, event rawEvent, ignore string) error {
|
|||||||
subs.Connection.Publish(newResponseEvent(event.Event, event.Channel, v))
|
subs.Connection.Publish(newResponseEvent(event.Event, event.Channel, v))
|
||||||
} else {
|
} else {
|
||||||
// Webhook
|
// Webhook
|
||||||
if strings.HasPrefix(event.Event, "client-") {
|
if utils.IsClientEvent(event.Event) {
|
||||||
a.TriggerClientEventHook(c, subs, event.Event, v)
|
a.TriggerClientEventHook(c, subs, event.Event, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@ func onMessage(conn *websocket.Conn, w http.ResponseWriter, r *http.Request, ses
|
|||||||
}
|
}
|
||||||
default: // CLient Events ??
|
default: // CLient Events ??
|
||||||
// see http://pusher.com/docs/client_api_guide/client_events#trigger-events
|
// see http://pusher.com/docs/client_api_guide/client_events#trigger-events
|
||||||
if strings.HasPrefix(event.Event, "client-") {
|
if utils.IsClientEvent(event.Event) {
|
||||||
if !app.UserEvents {
|
if !app.UserEvents {
|
||||||
emitWSError(newGenericError("To send client events, you must enable this feature in the Settings."), conn)
|
emitWSError(newGenericError("To send client events, you must enable this feature in the Settings."), conn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,10 +40,17 @@ func IsChannelNameValid(channelName string) bool {
|
|||||||
return validChannelName.Match([]byte(channelName))
|
return validChannelName.Match([]byte(channelName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPrivateChannel Verify if the channel name represents a private channel
|
||||||
func IsPrivateChannel(channelName string) bool {
|
func IsPrivateChannel(channelName string) bool {
|
||||||
return strings.HasPrefix(channelName, "private-")
|
return strings.HasPrefix(channelName, "private-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPresenceChannel Verify if the channel name represents a presence channel
|
||||||
func IsPresenceChannel(channelName string) bool {
|
func IsPresenceChannel(channelName string) bool {
|
||||||
return strings.HasPrefix(channelName, "presence-")
|
return strings.HasPrefix(channelName, "presence-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsClientEvent Verify if the event name represents a client event type
|
||||||
|
func IsClientEvent(event string) bool {
|
||||||
|
return strings.HasPrefix(event, "client-")
|
||||||
|
}
|
||||||
|
|||||||
@@ -95,6 +95,24 @@ func TestIsPresenceChannel_invalid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsClientEvent_valid(t *testing.T) {
|
||||||
|
name := "client-hello"
|
||||||
|
ok := IsClientEvent(name)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("IsClientEvent(%s) == %t, wants %t", name, ok, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsClientEvent_invalid(t *testing.T) {
|
||||||
|
name := "hello"
|
||||||
|
ok := IsClientEvent(name)
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
t.Errorf("IsClientEvent(%s) == %t, wants %t", name, ok, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestHashMAC(t *testing.T) {
|
func TestHashMAC(t *testing.T) {
|
||||||
message := []byte("hello world")
|
message := []byte("hello world")
|
||||||
key := []byte("my super secret key")
|
key := []byte("my super secret key")
|
||||||
|
|||||||
Reference in New Issue
Block a user