we no longer need to pass in the kind

remove option function WithKind
This commit is contained in:
2026-02-07 13:58:37 +00:00
parent 8a452c83b9
commit 3c47d12719
7 changed files with 47 additions and 56 deletions

View File

@@ -14,7 +14,7 @@ type parser interface {
}
type engine struct {
Kind MixerKind
Kind mixerKind
timeout time.Duration
conn *net.UDPConn
mixerAddr *net.UDPAddr
@@ -26,6 +26,42 @@ type engine struct {
respChan chan *osc.Message
}
func newEngine(mixerIP string, mixerPort int, kind mixerKind, opts ...Option) (*engine, error) {
localAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", 0))
if err != nil {
return nil, fmt.Errorf("failed to resolve local address: %v", err)
}
conn, err := net.ListenUDP("udp", localAddr)
if err != nil {
return nil, fmt.Errorf("failed to create UDP connection: %v", err)
}
mixerAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", mixerIP, mixerPort))
if err != nil {
conn.Close()
return nil, fmt.Errorf("failed to resolve mixer address: %v", err)
}
log.Debugf("Local UDP connection: %s ", conn.LocalAddr().String())
e := &engine{
timeout: 100 * time.Millisecond,
conn: conn,
mixerAddr: mixerAddr,
parser: newParser(),
addressMap: addressMapFromMixerKind(kind),
done: make(chan bool),
respChan: make(chan *osc.Message, 100),
}
for _, opt := range opts {
opt(e)
}
return e, nil
}
// receiveLoop handles incoming OSC messages
func (e *engine) receiveLoop() {
buffer := make([]byte, 4096)