diff --git a/client.go b/client.go index fa07e8a..613e3e7 100644 --- a/client.go +++ b/client.go @@ -29,6 +29,7 @@ type Client struct { OnChannelCreateFunctions []func(channel *Channel) OnChannelUpdateFunctions []func(channel_id, clear string, payload map[string]interface{}) OnChannelDeleteFunctions []func(channel_id string) + OnUnknownEventFunctions []func(message string) } // Client cache struct. @@ -83,6 +84,11 @@ func (c *Client) OnChannelDelete(fn func(channel_id string)) { c.OnChannelDeleteFunctions = append(c.OnChannelDeleteFunctions, fn) } +// On unknown event will run when client gets a unknown event. +func (c *Client) OnUnknownEvent(fn func(message string)) { + c.OnUnknownEventFunctions = append(c.OnUnknownEventFunctions, fn) +} + // Fetch a channel by Id. func (c *Client) FetchChannel(id string) (*Channel, error) { channel := &Channel{} diff --git a/websocket.go b/websocket.go index 86ccffa..3b97efe 100644 --- a/websocket.go +++ b/websocket.go @@ -179,6 +179,13 @@ func (c *Client) handleEvents(rawData *struct { for _, i := range c.OnChannelDeleteFunctions { i(data.ChannelId) } + } else { + // Unknown Event + if c.OnUnknownEventFunctions != nil { + for _, i := range c.OnUnknownEventFunctions { + i(message) + } + } } }