Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Event support #4

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
15 changes: 14 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Client struct {
stateMutex sync.RWMutex

timeRequests chan chan models.Timecode

events map[string]func(SwitcherState)
}

func NewClient(log logrus.FieldLogger, host string) *Client {
Expand All @@ -53,6 +55,10 @@ func NewClientWithPort(log logrus.FieldLogger, host string, port int) *Client {
}
}

func (c *Client) SetEvents(events map[string]func(SwitcherState)) {
c.events = events
}

func (c *Client) State() SwitcherState {
c.stateMutex.RLock()
state := c.state
Expand Down Expand Up @@ -227,7 +233,7 @@ func (c *Client) processCommands(log logrus.FieldLogger, msg packet.Message) (in
defer c.stateMutex.Unlock()
for _, cmd := range msg.Commands {
log.WithField("slug", cmd.Slug()).Debug("Starting to process command")

funcName := ""
switch t := cmd.(type) {
case *cmds.UnknownCommand:
log.WithField("slug", t.Slug()).Debug("Got unknown command")
Expand All @@ -253,6 +259,7 @@ func (c *Client) processCommands(log logrus.FieldLogger, msg packet.Message) (in
c.state.Config.SuperSources = int(*t)
case *cmds.TlcCmd:
c.state.Config.TallyChannels = int(*t)
funcName = "onTallyChannels"
case *cmds.MacCmd:
c.state.Config.MacroBanks = int(*t)
case *cmds.PowrCmd:
Expand Down Expand Up @@ -284,8 +291,10 @@ func (c *Client) processCommands(log logrus.FieldLogger, msg packet.Message) (in
}
case cmds.TlinCmd:
c.state.TallyByIndex = t
funcName = "onTallyByIndex"
case cmds.TlsrCmd:
c.state.TallyBySource = t
funcName = "onTallyBySource"
case *cmds.TimeCmd:
tc := models.Timecode(*t)
done := false
Expand All @@ -306,6 +315,10 @@ func (c *Client) processCommands(log logrus.FieldLogger, msg packet.Message) (in
default:
log.Debug("Unhandled packet type")
}
callback, ok := c.events[funcName]
if ok {
callback(c.state)
}
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mraerino/atem-go
module github.com/everycastlabs/atem-go

go 1.13

Expand Down