Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/samwho/streamdeck

go 1.15

require github.com/gorilla/websocket v1.4.2
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=