From 77e84e8972d9a5d69a27b86dea90f85d9d69ed0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Z=C3=B6rner?= Date: Sat, 15 Jan 2022 10:32:02 +0100 Subject: [PATCH 1/4] modified internal imports --- action.go | 2 +- client.go | 2 +- event.go | 2 +- go.mod | 5 +++++ go.sum | 2 ++ 5 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/action.go b/action.go index 5b7e2a7..b81300e 100644 --- a/action.go +++ b/action.go @@ -3,7 +3,7 @@ package streamdeck import ( "context" - sdcontext "github.com/samwho/streamdeck/context" + sdcontext "github.com/StefanZoerner/streamdeck/context" ) type Action struct { diff --git a/client.go b/client.go index 94a1aa0..4d3be14 100644 --- a/client.go +++ b/client.go @@ -13,7 +13,7 @@ import ( "time" "github.com/gorilla/websocket" - sdcontext "github.com/samwho/streamdeck/context" + sdcontext "github.com/StefanZoerner/streamdeck/context" ) var ( diff --git a/event.go b/event.go index 23a77ec..d4891a5 100644 --- a/event.go +++ b/event.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - sdcontext "github.com/samwho/streamdeck/context" + sdcontext "github.com/StefanZoerner/streamdeck/context" ) type Event struct { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3f5b409 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/StefanZoerner/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= From 7661d465431d202c918272eb6aac187354d3d930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Z=C3=B6rner?= Date: Sun, 16 Jan 2022 09:19:20 +0100 Subject: [PATCH 2/4] Revert "modified internal imports" This reverts commit 77e84e8972d9a5d69a27b86dea90f85d9d69ed0a. --- action.go | 2 +- client.go | 2 +- event.go | 2 +- go.mod | 5 ----- go.sum | 2 -- 5 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 go.mod delete mode 100644 go.sum diff --git a/action.go b/action.go index b81300e..5b7e2a7 100644 --- a/action.go +++ b/action.go @@ -3,7 +3,7 @@ package streamdeck import ( "context" - sdcontext "github.com/StefanZoerner/streamdeck/context" + sdcontext "github.com/samwho/streamdeck/context" ) type Action struct { diff --git a/client.go b/client.go index 4d3be14..94a1aa0 100644 --- a/client.go +++ b/client.go @@ -13,7 +13,7 @@ import ( "time" "github.com/gorilla/websocket" - sdcontext "github.com/StefanZoerner/streamdeck/context" + sdcontext "github.com/samwho/streamdeck/context" ) var ( diff --git a/event.go b/event.go index d4891a5..23a77ec 100644 --- a/event.go +++ b/event.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - sdcontext "github.com/StefanZoerner/streamdeck/context" + sdcontext "github.com/samwho/streamdeck/context" ) type Event struct { diff --git a/go.mod b/go.mod deleted file mode 100644 index 3f5b409..0000000 --- a/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/StefanZoerner/streamdeck - -go 1.15 - -require github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum deleted file mode 100644 index 85efffd..0000000 --- a/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= -github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= From d0a90addfdcfb15e483da2bb9073240e7a73be0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Z=C3=B6rner?= Date: Sun, 16 Jan 2022 09:26:29 +0100 Subject: [PATCH 3/4] go.mod file added for Go modules system --- go.mod | 5 +++++ go.sum | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 go.mod create mode 100644 go.sum 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= From f07e669c0f148559f1d0d0f543e2ef4f5cc9a3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Z=C3=B6rner?= Date: Sun, 16 Jan 2022 09:49:10 +0100 Subject: [PATCH 4/4] added a funtion to add a global (plugin) handler add a function for registering "global" (plugin) handlers. --- client.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 {