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 {