diff --git a/client.go b/client.go index 94a1aa0..2ad2cb8 100644 --- a/client.go +++ b/client.go @@ -38,10 +38,11 @@ type Client struct { func NewClient(ctx context.Context, params RegistrationParams) *Client { return &Client{ - ctx: ctx, - params: params, - actions: make(map[string]*Action), - done: make(chan struct{}), + ctx: ctx, + params: params, + actions: make(map[string]*Action), + handlers: make(map[string][]EventHandler), + done: make(chan struct{}), } } func (client *Client) Action(uuid string) *Action { @@ -204,6 +205,10 @@ func (client *Client) SendToPlugin(ctx context.Context, payload interface{}) err return client.send(NewEvent(ctx, SendToPlugin, payload)) } +func (client *Client) RegisterHandler(eventName string, handler EventHandler) { + client.handlers[eventName] = append(client.handlers[eventName], handler) +} + func (client *Client) Close() error { err := client.c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) if err != nil { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3e913e3 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/samwho/streamdeck + +go 1.15 + +require github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..85efffd --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=