mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2026-03-12 04:59:15 +00:00
Compare commits
3 Commits
843f7c5e0d
...
55d14b0d07
| Author | SHA1 | Date | |
|---|---|---|---|
| 55d14b0d07 | |||
| b7cd658d7c | |||
| b506265e37 |
@ -1,5 +1,6 @@
|
|||||||

|

|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
# VBAN Sendtext
|
# VBAN Sendtext
|
||||||
|
|
||||||
@ -23,10 +24,10 @@ For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
|
|||||||
|
|
||||||
## Tested against
|
## Tested against
|
||||||
|
|
||||||
- Basic 1.1.1.9
|
- Basic 1.1.2.2
|
||||||
- Banana 2.1.1.9
|
- Banana 2.1.2.2
|
||||||
- Potato 3.1.1.9
|
- Potato 3.1.2.2
|
||||||
- Matrix 1.0.1.2
|
- Matrix 1.0.2.6
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
vbanProtocolTxt = 0x40
|
vbanProtocolTxt = 0x40
|
||||||
|
vbanTxtUtf8 = 0x10
|
||||||
streamNameSz = 16
|
streamNameSz = 16
|
||||||
headerSz = 4 + 1 + 1 + 1 + 1 + 16 + 4
|
headerSz = 4 + 1 + 1 + 1 + 1 + 16 + 4
|
||||||
)
|
)
|
||||||
@ -59,7 +60,7 @@ func newPacket(streamname string) (packet, error) {
|
|||||||
|
|
||||||
// sr defines the samplerate for the request.
|
// sr defines the samplerate for the request.
|
||||||
func (p *packet) sr() byte {
|
func (p *packet) sr() byte {
|
||||||
return byte(vbanProtocolTxt + p.bpsIndex)
|
return byte(p.bpsIndex | vbanProtocolTxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nbc defines the channel of the request.
|
// nbc defines the channel of the request.
|
||||||
@ -74,7 +75,7 @@ func (p *packet) header() []byte {
|
|||||||
p.hbuf.WriteByte(p.sr())
|
p.hbuf.WriteByte(p.sr())
|
||||||
p.hbuf.WriteByte(byte(0))
|
p.hbuf.WriteByte(byte(0))
|
||||||
p.hbuf.WriteByte(p.nbc())
|
p.hbuf.WriteByte(p.nbc())
|
||||||
p.hbuf.WriteByte(byte(0x10))
|
p.hbuf.WriteByte(byte(vbanTxtUtf8))
|
||||||
p.hbuf.Write(p.streamname[:])
|
p.hbuf.Write(p.streamname[:])
|
||||||
|
|
||||||
var frameBytes [4]byte
|
var frameBytes [4]byte
|
||||||
|
|||||||
17
vbantxt.go
17
vbantxt.go
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
||||||
@ -11,6 +13,7 @@ type VbanTxt struct {
|
|||||||
conn io.WriteCloser
|
conn io.WriteCloser
|
||||||
packet packet
|
packet packet
|
||||||
ratelimit time.Duration
|
ratelimit time.Duration
|
||||||
|
lastSend time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
||||||
@ -40,8 +43,18 @@ func New(host string, port int, streamname string, options ...Option) (*VbanTxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send is responsible for firing each VBAN-TXT request.
|
// Send is responsible for firing each VBAN-TXT request.
|
||||||
// It waits for {vt.ratelimit} time before returning.
|
// It enforces rate limiting by waiting only when necessary.
|
||||||
func (vt *VbanTxt) Send(cmd string) error {
|
func (vt *VbanTxt) Send(cmd string) error {
|
||||||
|
if elapsed := time.Since(vt.lastSend); elapsed < vt.ratelimit {
|
||||||
|
log.Debugf(
|
||||||
|
"Rate limit in effect. Waiting for %v before sending next command.",
|
||||||
|
vt.ratelimit-elapsed,
|
||||||
|
)
|
||||||
|
time.Sleep(vt.ratelimit - elapsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
vt.lastSend = time.Now()
|
||||||
|
|
||||||
_, err := vt.conn.Write(append(vt.packet.header(), cmd...))
|
_, err := vt.conn.Write(append(vt.packet.header(), cmd...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
||||||
@ -49,8 +62,6 @@ func (vt *VbanTxt) Send(cmd string) error {
|
|||||||
|
|
||||||
vt.packet.bumpFrameCounter()
|
vt.packet.bumpFrameCounter()
|
||||||
|
|
||||||
time.Sleep(vt.ratelimit)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user