mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2026-04-07 01:33:30 +00:00
rename client struct to udpConn
This commit is contained in:
10
vbantxt.go
10
vbantxt.go
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
||||
type VbanTxt struct {
|
||||
client io.WriteCloser
|
||||
udpConn io.WriteCloser
|
||||
packet packet
|
||||
ratelimit time.Duration
|
||||
}
|
||||
@@ -16,13 +16,13 @@ type VbanTxt struct {
|
||||
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
||||
// It sets default values for it's fields and then runs the option functions.
|
||||
func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) {
|
||||
client, err := newClient(host, port)
|
||||
udpConn, err := newUDPConn(host, port)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err)
|
||||
}
|
||||
|
||||
vt := &VbanTxt{
|
||||
client: client,
|
||||
udpConn: udpConn,
|
||||
packet: newPacket(streamname),
|
||||
ratelimit: time.Duration(20) * time.Millisecond,
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func New(host string, port int, streamname string, options ...Option) (*VbanTxt,
|
||||
// Send is resonsible for firing each VBAN-TXT request.
|
||||
// It waits for {vt.ratelimit} time before returning.
|
||||
func (vt VbanTxt) Send(cmd string) error {
|
||||
_, err := vt.client.Write(append(vt.packet.header(), []byte(cmd)...))
|
||||
_, err := vt.udpConn.Write(append(vt.packet.header(), []byte(cmd)...))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (vt VbanTxt) Send(cmd string) error {
|
||||
|
||||
// Close is responsible for closing the UDP Client connection
|
||||
func (vt VbanTxt) Close() error {
|
||||
err := vt.client.Close()
|
||||
err := vt.udpConn.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error attempting to close UDP Client: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user