Compare commits

...

3 Commits

Author SHA1 Message Date
55d14b0d07 upd tested against
add macOS badge
2026-03-07 01:07:37 +00:00
b7cd658d7c add vbanTxtUtf8 to give the magic value meaning
OR the bpsIndex with the mask value.
2026-03-07 00:53:35 +00:00
b506265e37 make the ratelimiting more accurate. 2026-03-07 00:52:58 +00:00
3 changed files with 22 additions and 9 deletions

View File

@ -1,5 +1,6 @@
![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white) ![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)
![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black) ![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)
![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0)
# 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
--- ---

View File

@ -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

View File

@ -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
} }