Compare commits
13 Commits
81d73e9b08
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0010bc6cf7 | ||
|
|
a14d068ada | ||
|
|
b66e0737d0 | ||
|
|
2860102627 | ||
|
|
ebe2b26ae9 | ||
|
|
356b492629 | ||
|
|
99f26c4485 | ||
|
|
9ed1d4f60e | ||
|
|
a639558ce4 | ||
|
|
3dc4942942 | ||
|
|
ed8f9a4538 | ||
|
|
1283fdc9c4 | ||
|
|
71017f1e61 |
@@ -1,38 +0,0 @@
|
||||
name: Build Linux
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
cache: false
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
libportaudio2 \
|
||||
portaudio19-dev \
|
||||
libopus-dev \
|
||||
libopusfile-dev \
|
||||
libpulse-dev \
|
||||
pkg-config \
|
||||
gcc
|
||||
|
||||
- name: Build TUI
|
||||
run: |
|
||||
export CGO_ENABLED=1
|
||||
go build -o dist/tui_linux ./cmd/tui
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: tui-linux-binary
|
||||
path: dist/tui_linux
|
||||
@@ -1,48 +0,0 @@
|
||||
name: Build Windows
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
cache: false
|
||||
|
||||
- name: Setup MSYS2
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: MINGW64
|
||||
path-type: inherit
|
||||
update: true
|
||||
install: >-
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-opus
|
||||
mingw-w64-x86_64-opusfile
|
||||
mingw-w64-x86_64-portaudio
|
||||
mingw-w64-x86_64-pkgconf
|
||||
|
||||
- name: Build TUI
|
||||
run: |
|
||||
# Ensure Go can find the C libraries via pkg-config
|
||||
export CGO_ENABLED=1
|
||||
go build -o dist/tui_windows.exe ./cmd/tui
|
||||
# Copy necessary DLLs for portability
|
||||
cp /mingw64/bin/libogg-0.dll dist/
|
||||
cp /mingw64/bin/libopus-0.dll dist/
|
||||
cp /mingw64/bin/libopusfile-0.dll dist/
|
||||
cp /mingw64/bin/libportaudio-2.dll dist/ || true
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: tui-windows-binary
|
||||
path: dist/
|
||||
117
.gitea/workflows/build.yml
Normal file
117
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,117 @@
|
||||
name: Build and Release
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
tags: ['v*']
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.24'
|
||||
cache: false
|
||||
|
||||
- name: Setup MSYS2
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: MINGW64
|
||||
path-type: inherit
|
||||
update: true
|
||||
install: >-
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-opus
|
||||
mingw-w64-x86_64-opusfile
|
||||
mingw-w64-x86_64-portaudio
|
||||
mingw-w64-x86_64-pkgconf
|
||||
zip
|
||||
|
||||
- name: Build TUI
|
||||
run: |
|
||||
export CGO_ENABLED=1
|
||||
mkdir -p dist
|
||||
# More descriptive name: ts3-tui
|
||||
go build -o dist/ts3-tui.exe ./cmd/tui
|
||||
# Copy DLLs
|
||||
cp /mingw64/bin/libogg-0.dll dist/
|
||||
cp /mingw64/bin/libopus-0.dll dist/
|
||||
cp /mingw64/bin/libopusfile-0.dll dist/
|
||||
cp /mingw64/bin/libportaudio-2.dll dist/ || true
|
||||
# Create ZIP with architecture name
|
||||
cd dist && zip -r ../ts3-tui-windows-x86_64.zip . *
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ts3-tui-windows-zip
|
||||
path: ts3-tui-windows-x86_64.zip
|
||||
|
||||
build-linux:
|
||||
runs-on: linux-x86_64
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.24'
|
||||
cache: false
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
libportaudio2 portaudio19-dev \
|
||||
libopus-dev libopusfile-dev \
|
||||
libpulse-dev pkg-config gcc
|
||||
|
||||
- name: Build TUI
|
||||
run: |
|
||||
export CGO_ENABLED=1
|
||||
export ARCH=$(uname -m)
|
||||
mkdir -p dist
|
||||
# More descriptive name: ts3-tui-linux-ARCH
|
||||
go build -o dist/ts3-tui-linux-${ARCH} ./cmd/tui
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ts3-tui-linux-binaries
|
||||
path: dist/*
|
||||
|
||||
release:
|
||||
needs: [build-windows, build-linux]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Generate Changelog
|
||||
run: |
|
||||
# Get commits since the last tag (or since the beginning)
|
||||
git log --oneline $(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)..HEAD > changelog.txt
|
||||
|
||||
- name: Download Artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
body_path: changelog.txt
|
||||
files: |
|
||||
ts3-tui-windows-zip/ts3-tui-windows-x86_64.zip
|
||||
ts3-tui-linux-binaries/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
247
cmd/tui/model.go
247
cmd/tui/model.go
@@ -102,7 +102,15 @@ type Model struct {
|
||||
playbackVol int // 0-100
|
||||
micLevel int // 0-100 (current input level)
|
||||
isMuted bool // Mic muted
|
||||
isPTT bool // Push-to-talk active
|
||||
isPTT bool // Push-to-talk active (Manual TX)
|
||||
vadEnabled bool // Voice Activation Detection active
|
||||
vadThreshold int // 0-100 threshold for VAD
|
||||
vadLastTriggered time.Time // Last time VAD threshold was exceeded
|
||||
|
||||
// Popup State
|
||||
showPokePopup bool
|
||||
pokePopupSender string
|
||||
pokePopupMessage string
|
||||
|
||||
// Program reference for sending messages from event handlers
|
||||
program *tea.Program
|
||||
@@ -135,6 +143,8 @@ func NewModel(serverAddr, nickname string) *Model {
|
||||
logMessages: []string{"Starting..."},
|
||||
talkingClients: make(map[uint16]bool),
|
||||
playbackVol: 80, // Default 80% volume
|
||||
vadEnabled: true,
|
||||
vadThreshold: 50,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,16 +304,53 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
} else {
|
||||
m.audioCapturer = capturer
|
||||
// Set callback to send audio to server when PTT is active
|
||||
// Set callback to send audio to server when PTT is active
|
||||
m.audioCapturer.SetCallback(func(samples []int16) {
|
||||
if m.isPTT && m.client != nil && !m.isMuted {
|
||||
// Calculate level of this frame for VAD decision
|
||||
// Note: GetLevel() is smoothed, we might want instant frame level for VAD trigger?
|
||||
// But pkg/audio/level.go is efficient. Let's re-calculate for precision.
|
||||
level := audio.CalculateRMSLevel(samples)
|
||||
|
||||
// Determine if we should transmit
|
||||
shouldTransmit := false
|
||||
|
||||
// Manual PTT (Locked on with 'v')
|
||||
if m.isPTT {
|
||||
shouldTransmit = true
|
||||
}
|
||||
|
||||
// VAD Logic
|
||||
if m.vadEnabled && !m.isMuted {
|
||||
if level > m.vadThreshold {
|
||||
shouldTransmit = true
|
||||
m.vadLastTriggered = time.Now()
|
||||
} else if !m.vadLastTriggered.IsZero() && time.Since(m.vadLastTriggered) < 1*time.Second {
|
||||
// Hold VAD open for 1 second (decay)
|
||||
shouldTransmit = true
|
||||
}
|
||||
}
|
||||
|
||||
// Allow transmission if forced or VAD triggered
|
||||
if shouldTransmit && m.client != nil && !m.isMuted {
|
||||
m.client.SendAudio(samples)
|
||||
}
|
||||
// Update mic level for display
|
||||
|
||||
// Update mic level for display (use the calculated level)
|
||||
if m.program != nil {
|
||||
m.program.Send(micLevelMsg(m.audioCapturer.GetLevel()))
|
||||
// Use goroutine to prevent blocking the capture loop if the UI is busy (e.g. shutting down)
|
||||
go m.program.Send(micLevelMsg(level))
|
||||
}
|
||||
})
|
||||
m.addLog("Audio capturer initialized")
|
||||
|
||||
// Start capture immediately if VAD is enabled or PTT is active
|
||||
if m.vadEnabled || m.isPTT {
|
||||
if err := m.audioCapturer.Start(); err != nil {
|
||||
m.addLog("Error starting audio capture: %v", err)
|
||||
} else {
|
||||
m.addLog("Audio capture started (VAD/PTT active)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Connect asynchronously
|
||||
@@ -343,16 +390,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
// Update mic level when PTT is active (multiply for better visibility)
|
||||
if m.isPTT && m.audioCapturer != nil {
|
||||
level := m.audioCapturer.GetLevel() * 4 // Boost for visibility
|
||||
if level > 100 {
|
||||
level = 100
|
||||
}
|
||||
m.micLevel = level
|
||||
} else {
|
||||
m.micLevel = 0 // Reset when not transmitting
|
||||
}
|
||||
// Legacy mic level handling removed to support VAD event-driven updates
|
||||
|
||||
// Continue ticking (100ms for responsive mic level)
|
||||
return m, tea.Tick(100*time.Millisecond, func(t time.Time) tea.Msg {
|
||||
@@ -398,12 +436,19 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
|
||||
case pokeMsg:
|
||||
// Append to chat as well
|
||||
m.chatMessages = append(m.chatMessages, ChatMessage{
|
||||
Time: time.Now(),
|
||||
Sender: "POKE",
|
||||
Content: fmt.Sprintf("[%s]: %s", msg.senderName, msg.message),
|
||||
})
|
||||
m.addLog("Received poke from %s: %s", msg.senderName, msg.message)
|
||||
|
||||
// Trigger Popup
|
||||
m.showPokePopup = true
|
||||
m.pokePopupSender = msg.senderName
|
||||
m.pokePopupMessage = msg.message
|
||||
|
||||
return m, nil
|
||||
|
||||
case chatMsg:
|
||||
@@ -545,8 +590,18 @@ func (m *Model) updateChannelList(channels []*ts3client.Channel) {
|
||||
}
|
||||
|
||||
func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
key := msg.String()
|
||||
|
||||
// Global Key Handling for Popup
|
||||
if m.showPokePopup {
|
||||
if key == "esc" || key == "enter" || key == "q" {
|
||||
m.showPokePopup = false
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// 1. Absolute Globals (Always active)
|
||||
switch msg.String() {
|
||||
switch key {
|
||||
case "ctrl+c":
|
||||
if m.client != nil {
|
||||
m.client.Disconnect()
|
||||
@@ -627,16 +682,58 @@ func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, nil
|
||||
|
||||
case "ctrl+up", "ctrl+right":
|
||||
// Increase VAD threshold
|
||||
m.vadThreshold += 5
|
||||
if m.vadThreshold > 100 {
|
||||
m.vadThreshold = 100
|
||||
}
|
||||
m.addLog("VAD Threshold: %d", m.vadThreshold)
|
||||
return m, nil
|
||||
|
||||
case "ctrl+down", "ctrl+left":
|
||||
// Decrease VAD threshold
|
||||
m.vadThreshold -= 5
|
||||
if m.vadThreshold < 0 {
|
||||
m.vadThreshold = 0
|
||||
}
|
||||
m.addLog("VAD Threshold: %d", m.vadThreshold)
|
||||
return m, nil
|
||||
|
||||
case "g", "G":
|
||||
// Toggle VAD (Gate)
|
||||
m.vadEnabled = !m.vadEnabled
|
||||
state := "OFF"
|
||||
if m.vadEnabled {
|
||||
state = "ON"
|
||||
// Ensure capturer is running if VAD is on
|
||||
if m.audioCapturer != nil && !m.audioCapturer.IsRunning() {
|
||||
if err := m.audioCapturer.Start(); err != nil {
|
||||
m.addLog("Error starting VAD capture: %v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Stop if PTT is also off
|
||||
if !m.isPTT && m.audioCapturer != nil && m.audioCapturer.IsRunning() {
|
||||
m.audioCapturer.Stop()
|
||||
}
|
||||
}
|
||||
m.addLog("Voice Activation (Gate): %s", state)
|
||||
return m, nil
|
||||
|
||||
case "v", "V":
|
||||
// Toggle voice (PTT)
|
||||
m.isPTT = !m.isPTT
|
||||
if m.isPTT {
|
||||
if m.audioCapturer != nil {
|
||||
m.audioCapturer.Start()
|
||||
if m.audioCapturer != nil && !m.audioCapturer.IsRunning() {
|
||||
if err := m.audioCapturer.Start(); err != nil {
|
||||
m.addLog("Audio capture error: %v", err)
|
||||
}
|
||||
}
|
||||
m.addLog("🎤 Transmitting...")
|
||||
} else {
|
||||
if m.audioCapturer != nil {
|
||||
// Stop only if VAD is also off
|
||||
if !m.vadEnabled && m.audioCapturer != nil && m.audioCapturer.IsRunning() {
|
||||
m.audioCapturer.Stop()
|
||||
}
|
||||
m.addLog("🎤 Stopped transmitting")
|
||||
@@ -836,6 +933,32 @@ func (m *Model) handleInputKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
|
||||
// View renders the UI
|
||||
func (m *Model) View() string {
|
||||
if m.showPokePopup {
|
||||
boxStyle := lipgloss.NewStyle().
|
||||
Border(lipgloss.DoubleBorder()).
|
||||
BorderForeground(lipgloss.Color("196")). // Red for Poke
|
||||
Padding(1, 2).
|
||||
Width(50).
|
||||
Align(lipgloss.Center)
|
||||
|
||||
titleStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("226")).MarginBottom(1)
|
||||
senderStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("208")).Bold(true)
|
||||
msgStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("255")).Italic(true)
|
||||
helpStyle := lipgloss.NewStyle().Faint(true).MarginTop(2)
|
||||
|
||||
content := lipgloss.JoinVertical(lipgloss.Center,
|
||||
titleStyle.Render("YOU WERE POKED!"),
|
||||
"",
|
||||
fmt.Sprintf("From: %s", senderStyle.Render(m.pokePopupSender)),
|
||||
"",
|
||||
msgStyle.Render(fmt.Sprintf("%q", m.pokePopupMessage)),
|
||||
"",
|
||||
helpStyle.Render("(Press Esc/Enter to close)"),
|
||||
)
|
||||
|
||||
return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, boxStyle.Render(content))
|
||||
}
|
||||
|
||||
if m.focus == FocusAbout {
|
||||
return m.renderAboutView()
|
||||
}
|
||||
@@ -962,7 +1085,7 @@ func (m *Model) View() string {
|
||||
if m.showLog {
|
||||
logHelp = "L chat"
|
||||
}
|
||||
help := lipgloss.NewStyle().Faint(true).Render(fmt.Sprintf("↑↓ navigate │ Enter join │ Tab switch │ %s │ V talk │ M mute │ +/- vol │ q quit", logHelp))
|
||||
help := lipgloss.NewStyle().Faint(true).Render(fmt.Sprintf("↑↓ nav │ Ent join │ Tab switch │ %s │ V PTT │ G VAD │ ^↕↔ thresh │ M mute │ +/- vol │ q quit", logHelp))
|
||||
|
||||
// Combine panels
|
||||
panels := lipgloss.JoinHorizontal(lipgloss.Top, channelPanel, rightPanel)
|
||||
@@ -1005,12 +1128,85 @@ func (m *Model) renderStatusBar() string {
|
||||
}
|
||||
volPart := fmt.Sprintf("%s:%s%d%%", muteIcon, volBar, m.playbackVol)
|
||||
|
||||
micBar := audio.LevelToBar(m.micLevel, 6)
|
||||
pttIcon := "MIC"
|
||||
if m.isPTT {
|
||||
pttIcon = "*TX*"
|
||||
// Custom Mic Bar with VAD Threshold
|
||||
micBarWidth := 8
|
||||
var micBar string
|
||||
|
||||
if m.vadEnabled {
|
||||
// Calculate threshold position
|
||||
threshPos := m.vadThreshold * micBarWidth / 100
|
||||
if threshPos >= micBarWidth {
|
||||
threshPos = micBarWidth - 1
|
||||
}
|
||||
micPart := fmt.Sprintf("%s:%s", pttIcon, micBar)
|
||||
|
||||
// Calculate filled position based on current level
|
||||
filled := m.micLevel * micBarWidth / 100
|
||||
|
||||
// Build bar
|
||||
var sb strings.Builder
|
||||
for i := 0; i < micBarWidth; i++ {
|
||||
char := "░"
|
||||
if i < filled {
|
||||
char = "█"
|
||||
}
|
||||
|
||||
// Overlay threshold marker
|
||||
if i == threshPos {
|
||||
if i < filled {
|
||||
// Threshold is met
|
||||
char = "▓"
|
||||
} else {
|
||||
// Threshold not met
|
||||
char = "│"
|
||||
}
|
||||
}
|
||||
sb.WriteString(char)
|
||||
}
|
||||
micBar = sb.String()
|
||||
} else {
|
||||
micBar = audio.LevelToBar(m.micLevel, micBarWidth)
|
||||
}
|
||||
|
||||
pttStyle := lipgloss.NewStyle()
|
||||
pttIcon := "MIC"
|
||||
|
||||
if m.isPTT {
|
||||
pttIcon = " ON" // Manual ON
|
||||
pttStyle = pttStyle.Foreground(lipgloss.Color("196")).Bold(true) // Red
|
||||
} else if m.vadEnabled {
|
||||
pttIcon = "VAD"
|
||||
// Check if actively transmitting (using logic with decay)
|
||||
isTransmitting := false
|
||||
if !m.isMuted {
|
||||
if m.micLevel > m.vadThreshold {
|
||||
isTransmitting = true
|
||||
} else if !m.vadLastTriggered.IsZero() && time.Since(m.vadLastTriggered) < 1*time.Second {
|
||||
isTransmitting = true
|
||||
}
|
||||
}
|
||||
|
||||
if isTransmitting {
|
||||
// Transmitting via VAD: Red/Bold
|
||||
pttStyle = pttStyle.Foreground(lipgloss.Color("196")).Bold(true)
|
||||
} else {
|
||||
// Idle VAD: Gray/Faint
|
||||
pttStyle = pttStyle.Foreground(lipgloss.Color("240")).Faint(true)
|
||||
}
|
||||
} else {
|
||||
// Standard Mic (PTT mode but off)
|
||||
pttStyle = pttStyle.Foreground(lipgloss.Color("255")) // White
|
||||
}
|
||||
|
||||
// Apply status bar background color to prevent cutting
|
||||
pttStyle = pttStyle.Background(lipgloss.Color("57")) // Matches Top Bar Background
|
||||
|
||||
// Style for the bar itself to maintain background continuity
|
||||
barStyle := lipgloss.NewStyle().Background(lipgloss.Color("57")).Foreground(lipgloss.Color("255"))
|
||||
|
||||
micPart := fmt.Sprintf("%s%s%s",
|
||||
pttStyle.Render(pttIcon),
|
||||
barStyle.Render(":"),
|
||||
barStyle.Render(micBar))
|
||||
|
||||
rightPart := fmt.Sprintf("%s | %s ", volPart, micPart)
|
||||
|
||||
@@ -1246,7 +1442,8 @@ func (m *Model) renderAboutView() string {
|
||||
titleStyle.Render("TS3 TUI CLIENT"),
|
||||
lipgloss.NewStyle().Foreground(lipgloss.Color("250")).Render("Una terminal potente para tus comunidades."),
|
||||
"",
|
||||
lipgloss.NewStyle().Bold(true).Render("Hecho en Antigravity"),
|
||||
lipgloss.NewStyle().Bold(true).Render("Realizado por JosLeDeta"),
|
||||
lipgloss.NewStyle().Italic(true).Faint(true).Render("Hecho en Antigravity"),
|
||||
"",
|
||||
lipgloss.NewStyle().Bold(true).Render("Con la ayuda de:"),
|
||||
lipgloss.NewStyle().Foreground(lipgloss.Color("212")).Render("- Gemini 3 Pro"),
|
||||
|
||||
@@ -36,6 +36,7 @@ type Client struct {
|
||||
PingPacketID uint16 // Type 0x04
|
||||
PongPacketID uint16 // Type 0x05
|
||||
AckPacketID uint16 // Type 0x06
|
||||
AckLowPacketID uint16 // Type 0x07
|
||||
|
||||
// Ping RTT tracking
|
||||
PingSentTimes map[uint16]time.Time // Map PingPacketID -> Time sent
|
||||
@@ -48,10 +49,14 @@ type Client struct {
|
||||
ServerName string
|
||||
|
||||
// Fragment reassembly (packet queue like ts3j)
|
||||
CommandQueue map[uint16]*protocol.Packet // Packets waiting for reassembly
|
||||
ExpectedCommandPID uint16 // Next expected packet ID
|
||||
CommandQueue map[uint16]*protocol.Packet // Packets waiting for reassembly (Type 0x02)
|
||||
ExpectedCommandPID uint16 // Next expected packet ID (Type 0x02)
|
||||
FragmentState bool // Toggle: true = collecting, false = ready
|
||||
|
||||
CommandLowQueue map[uint16]*protocol.Packet // Packets waiting for reassembly (Type 0x03)
|
||||
ExpectedCommandLowPID uint16 // Next expected packet ID (Type 0x03)
|
||||
FragmentStateLow bool // Toggle: true = collecting, false = ready
|
||||
|
||||
// Server Data
|
||||
Channels map[uint64]*Channel
|
||||
|
||||
@@ -71,11 +76,14 @@ func NewClient(nickname string) *Client {
|
||||
return &Client{
|
||||
Nickname: nickname,
|
||||
PacketIDCounterC2S: 1,
|
||||
AckLowPacketID: 1,
|
||||
VoicePacketID: 1,
|
||||
Channels: make(map[uint64]*Channel),
|
||||
VoiceDecoders: make(map[uint16]*opus.Decoder),
|
||||
CommandQueue: make(map[uint16]*protocol.Packet),
|
||||
ExpectedCommandPID: 0,
|
||||
CommandLowQueue: make(map[uint16]*protocol.Packet),
|
||||
ExpectedCommandLowPID: 0,
|
||||
PingSentTimes: make(map[uint16]time.Time),
|
||||
PingRTT: 0,
|
||||
PingDeviation: 0,
|
||||
|
||||
@@ -35,6 +35,21 @@ func sanitizeForLog(s string) string {
|
||||
}
|
||||
|
||||
func (c *Client) handleCommand(pkt *protocol.Packet) error {
|
||||
// Select the correct queue and counters based on PacketType
|
||||
var queue map[uint16]*protocol.Packet
|
||||
var expectedPID *uint16
|
||||
var fragmentState *bool
|
||||
|
||||
if pkt.Header.PacketType() == protocol.PacketTypeCommandLow {
|
||||
queue = c.CommandLowQueue
|
||||
expectedPID = &c.ExpectedCommandLowPID
|
||||
fragmentState = &c.FragmentStateLow
|
||||
} else {
|
||||
queue = c.CommandQueue
|
||||
expectedPID = &c.ExpectedCommandPID
|
||||
fragmentState = &c.FragmentState
|
||||
}
|
||||
|
||||
// Check if Encrypted
|
||||
// PacketTypeCommand is usually encrypted.
|
||||
// Flag check? The flag is in the Header (e.g. Unencrypted flag).
|
||||
@@ -100,14 +115,14 @@ func (c *Client) handleCommand(pkt *protocol.Packet) error {
|
||||
|
||||
// Queue-based fragment reassembly (like ts3j)
|
||||
// Store packet in queue
|
||||
c.CommandQueue[pkt.Header.PacketID] = &protocol.Packet{
|
||||
queue[pkt.Header.PacketID] = &protocol.Packet{
|
||||
Header: pkt.Header,
|
||||
Data: append([]byte{}, data...), // Clone data (already decrypted)
|
||||
}
|
||||
|
||||
// Try to process packets in order
|
||||
for {
|
||||
nextPkt, ok := c.CommandQueue[c.ExpectedCommandPID]
|
||||
nextPkt, ok := queue[*expectedPID]
|
||||
if !ok {
|
||||
// Missing packet, wait for it
|
||||
break
|
||||
@@ -117,16 +132,16 @@ func (c *Client) handleCommand(pkt *protocol.Packet) error {
|
||||
|
||||
if isFragmented {
|
||||
// Toggle fragment state
|
||||
c.FragmentState = !c.FragmentState
|
||||
*fragmentState = !*fragmentState
|
||||
|
||||
if c.FragmentState {
|
||||
if *fragmentState {
|
||||
// Starting a new fragment sequence
|
||||
// Don't process yet, wait for more
|
||||
c.ExpectedCommandPID++
|
||||
*expectedPID++
|
||||
continue
|
||||
} else {
|
||||
// Ending fragment sequence - reassemble all
|
||||
reassembled, compressed := c.reassembleFragments()
|
||||
reassembled, compressed := c.reassembleFragmentsCustom(queue, *expectedPID)
|
||||
if reassembled == nil {
|
||||
log.Printf("Fragment reassembly failed")
|
||||
break
|
||||
@@ -144,9 +159,9 @@ func (c *Client) handleCommand(pkt *protocol.Packet) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if c.FragmentState {
|
||||
} else if *fragmentState {
|
||||
// Middle fragment - keep collecting
|
||||
c.ExpectedCommandPID++
|
||||
*expectedPID++
|
||||
continue
|
||||
} else {
|
||||
// Non-fragmented packet - process normally
|
||||
@@ -165,10 +180,11 @@ func (c *Client) handleCommand(pkt *protocol.Packet) error {
|
||||
}
|
||||
|
||||
// Remove processed packet from queue
|
||||
delete(c.CommandQueue, c.ExpectedCommandPID)
|
||||
c.ExpectedCommandPID++
|
||||
delete(queue, *expectedPID)
|
||||
*expectedPID++
|
||||
|
||||
// Process the command
|
||||
// Fix: processCommand should probably handle execution
|
||||
if err := c.processCommand(data, nextPkt); err != nil {
|
||||
log.Printf("Error processing command: %v", err)
|
||||
}
|
||||
@@ -177,16 +193,17 @@ func (c *Client) handleCommand(pkt *protocol.Packet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// reassembleFragments collects all buffered fragments in order and returns reassembled data
|
||||
func (c *Client) reassembleFragments() ([]byte, bool) {
|
||||
// reassembleFragmentsCustom collects all buffered fragments in order from the given queue
|
||||
// ending at currentPID.
|
||||
func (c *Client) reassembleFragmentsCustom(queue map[uint16]*protocol.Packet, currentPID uint16) ([]byte, bool) {
|
||||
var result []byte
|
||||
compressed := false
|
||||
|
||||
// Find the start of the fragment sequence (scan backwards from current)
|
||||
startPID := c.ExpectedCommandPID
|
||||
startPID := currentPID
|
||||
for {
|
||||
prevPID := startPID - 1
|
||||
pkt, ok := c.CommandQueue[prevPID]
|
||||
pkt, ok := queue[prevPID]
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
@@ -198,9 +215,9 @@ func (c *Client) reassembleFragments() ([]byte, bool) {
|
||||
startPID = prevPID
|
||||
}
|
||||
|
||||
// Now collect from startPID to ExpectedCommandPID (inclusive)
|
||||
for pid := startPID; pid <= c.ExpectedCommandPID; pid++ {
|
||||
pkt, ok := c.CommandQueue[pid]
|
||||
// Now collect from startPID to currentPID (inclusive)
|
||||
for pid := startPID; pid <= currentPID; pid++ {
|
||||
pkt, ok := queue[pid]
|
||||
if !ok {
|
||||
log.Printf("Missing fragment PID=%d during reassembly", pid)
|
||||
return nil, false
|
||||
@@ -212,11 +229,11 @@ func (c *Client) reassembleFragments() ([]byte, bool) {
|
||||
}
|
||||
|
||||
result = append(result, pkt.Data...)
|
||||
delete(c.CommandQueue, pid)
|
||||
delete(queue, pid)
|
||||
}
|
||||
|
||||
log.Printf("Reassembled fragments PID %d-%d, total %d bytes, compressed=%v",
|
||||
startPID, c.ExpectedCommandPID, len(result), compressed)
|
||||
startPID, currentPID, len(result), compressed)
|
||||
|
||||
return result, compressed
|
||||
}
|
||||
|
||||
@@ -55,6 +55,46 @@ func (c *Client) handlePacket(pkt *protocol.Packet) error {
|
||||
|
||||
c.Conn.SendPacket(ack)
|
||||
|
||||
return c.handleCommand(pkt)
|
||||
case protocol.PacketTypeCommandLow:
|
||||
// Send ACK Low
|
||||
ackData := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(ackData, pkt.Header.PacketID)
|
||||
|
||||
ack := protocol.NewPacket(protocol.PacketTypeAckLow, ackData)
|
||||
// Spec/ts3j: AckLow has its own counter
|
||||
c.AckLowPacketID++
|
||||
ack.Header.PacketID = c.AckLowPacketID
|
||||
ack.Header.ClientID = c.ClientID
|
||||
// ACKs usually don't have NewProtocol flag set in Header byte
|
||||
ack.Header.Type &= ^uint8(protocol.PacketFlagNewProtocol)
|
||||
|
||||
// ACKs for Command packets after handshake must be encrypted
|
||||
key := protocol.HandshakeKey
|
||||
nonce := protocol.HandshakeNonce
|
||||
|
||||
if c.Handshake != nil && c.Handshake.Step >= 6 && len(c.Handshake.SharedIV) > 0 {
|
||||
crypto := &protocol.CryptoState{
|
||||
SharedIV: c.Handshake.SharedIV,
|
||||
SharedMac: c.Handshake.SharedMac,
|
||||
GenerationID: 0,
|
||||
}
|
||||
key, nonce = crypto.GenerateKeyNonce(&ack.Header, true) // Client->Server=true
|
||||
}
|
||||
|
||||
// Meta for Client->Server: PID(2) + CID(2) + PT(1) = 5 bytes
|
||||
meta := make([]byte, 5)
|
||||
binary.BigEndian.PutUint16(meta[0:2], ack.Header.PacketID)
|
||||
binary.BigEndian.PutUint16(meta[2:4], ack.Header.ClientID)
|
||||
meta[4] = ack.Header.Type
|
||||
|
||||
encData, mac, _ := protocol.EncryptEAX(key, nonce, meta, ack.Data)
|
||||
ack.Data = encData
|
||||
copy(ack.Header.MAC[:], mac)
|
||||
// log.Printf("Sending ACK Low for server CommandLow PID=%d", pkt.Header.PacketID)
|
||||
|
||||
c.Conn.SendPacket(ack)
|
||||
|
||||
return c.handleCommand(pkt)
|
||||
case protocol.PacketTypeVoice:
|
||||
c.handleVoice(pkt)
|
||||
|
||||
@@ -22,6 +22,7 @@ type Capturer struct {
|
||||
running bool
|
||||
mu sync.Mutex
|
||||
stopChan chan struct{}
|
||||
wg sync.WaitGroup
|
||||
|
||||
// Callback for captured audio (called with 960-sample frames)
|
||||
onAudio func(samples []int16)
|
||||
@@ -136,6 +137,7 @@ func (c *Capturer) Start() error {
|
||||
return fmt.Errorf("failed to start audio client: %w", err)
|
||||
}
|
||||
|
||||
c.wg.Add(1)
|
||||
go c.captureLoop()
|
||||
return nil
|
||||
}
|
||||
@@ -151,6 +153,7 @@ func (c *Capturer) Stop() {
|
||||
c.mu.Unlock()
|
||||
|
||||
close(c.stopChan)
|
||||
c.wg.Wait() // Wait for capture loop to finish before proceeding
|
||||
c.client.Stop()
|
||||
}
|
||||
|
||||
@@ -180,6 +183,7 @@ func (c *Capturer) IsRunning() bool {
|
||||
}
|
||||
|
||||
func (c *Capturer) captureLoop() {
|
||||
defer c.wg.Done()
|
||||
ticker := time.NewTicker(10 * time.Millisecond) // Check more often than 20ms
|
||||
defer ticker.Stop()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// CalculateRMSLevel calculates the RMS level of PCM samples and returns 0-100
|
||||
// CalculateRMSLevel calculates the RMS level of PCM samples and returns 0-100 (Logarithmic/dB)
|
||||
func CalculateRMSLevel(samples []int16) int {
|
||||
if len(samples) == 0 {
|
||||
return 0
|
||||
@@ -16,15 +16,33 @@ func CalculateRMSLevel(samples []int16) int {
|
||||
}
|
||||
|
||||
rms := math.Sqrt(sum / float64(len(samples)))
|
||||
// Normalize to 0-100 (max int16 is 32767)
|
||||
level := int(rms / 32767.0 * 100.0)
|
||||
|
||||
// Normalize to 0.0 - 1.0
|
||||
val := rms / 32768.0
|
||||
if val < 0.000001 { // Avoid log(0)
|
||||
return 0
|
||||
}
|
||||
|
||||
// Convert to dB
|
||||
db := 20 * math.Log10(val)
|
||||
|
||||
// Map -50dB (silence floor) to 0dB (max) to 0-100
|
||||
const minDB = -50.0
|
||||
|
||||
if db < minDB {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Scale
|
||||
level := int((db - minDB) * (100.0 / (0 - minDB)))
|
||||
|
||||
if level > 100 {
|
||||
level = 100
|
||||
}
|
||||
return level
|
||||
}
|
||||
|
||||
// CalculatePeakLevel returns the peak level of PCM samples as 0-100
|
||||
// CalculatePeakLevel returns the peak level of PCM samples as 0-100 (Logarithmic/dB)
|
||||
func CalculatePeakLevel(samples []int16) int {
|
||||
if len(samples) == 0 {
|
||||
return 0
|
||||
@@ -40,7 +58,26 @@ func CalculatePeakLevel(samples []int16) int {
|
||||
}
|
||||
}
|
||||
|
||||
return int(float64(peak) / 32767.0 * 100.0)
|
||||
// Normalize
|
||||
val := float64(peak) / 32768.0
|
||||
if val < 0.000001 {
|
||||
return 0
|
||||
}
|
||||
|
||||
db := 20 * math.Log10(val)
|
||||
const minDB = -50.0
|
||||
|
||||
if db < minDB {
|
||||
// Linear falloff for very low signals to avoid clutter
|
||||
return 0
|
||||
}
|
||||
|
||||
level := int((db - minDB) * (100.0 / (0 - minDB)))
|
||||
if level > 100 {
|
||||
level = 100
|
||||
}
|
||||
|
||||
return level
|
||||
}
|
||||
|
||||
// LevelToBar converts a 0-100 level to a visual bar string
|
||||
|
||||
27
readme.md
27
readme.md
@@ -76,7 +76,13 @@ For the best experience when working on Linux features from Windows, use the **W
|
||||
|
||||
## 🤖 Gitea Actions (CI/CD)
|
||||
|
||||
El archivo `.gitea/workflows/build-windows.yml` automatiza la compilación en cada push.
|
||||
El archivo `.gitea/workflows/build.yml` automatiza la compilación y la creación de Releases.
|
||||
|
||||
1. **Builds automáticas**: Cada `push` a `master` genera artefactos descargables.
|
||||
2. **Releases automáticas**: Al subir un tag (`git tag v*`), se crea una Release con:
|
||||
- `ts3-tui-windows-x86_64.zip` (Portable: exe + dlls).
|
||||
- `ts3-tui-linux-x86_64` (Para PC/WSL2).
|
||||
- `ts3-tui-linux-aarch64` (Para ARM/Raspberry Pi).
|
||||
|
||||
### Cómo usar tu propio Windows como Runner
|
||||
|
||||
@@ -95,3 +101,22 @@ Si tu Gitea no tiene runners públicos, puedes convertir tu propia máquina Wind
|
||||
|
||||
> [!TIP]
|
||||
> El workflow usa **MSYS2** automáticamente para instalar `opus` y `portaudio` en el entorno temporal de la build, así que no necesitas configurar nada extra en el sistema del runner.
|
||||
|
||||
### Cómo añadir un Runner en WSL2 (para x86_64)
|
||||
|
||||
Si tu runner principal es ARM (como una Raspberry Pi) y quieres compilar para tu PC (x86_64), lo mejor es poner un runner dentro de WSL2:
|
||||
|
||||
1. **Entra en WSL2**: Ejecuta `wsl` en tu terminal.
|
||||
2. **Descarga `act_runner`**:
|
||||
```bash
|
||||
curl -L https://gitea.com/gitea/act_runner/releases/download/v0.2.13/act_runner-0.2.13-linux-amd64 -o act_runner
|
||||
chmod +x act_runner
|
||||
```
|
||||
3. **Registro**:
|
||||
- Igual que en Windows, usa `./act_runner register` con el token de tu Gitea.
|
||||
- En **labels**, pon algo como `linux-x86_64:host`.
|
||||
4. **Actualiza el workflow**:
|
||||
- En `.gitea/workflows/build.yml`, cambia `runs-on: ubuntu-latest` por `runs-on: linux-x86_64` en el job `build-linux`.
|
||||
|
||||
> [!NOTE]
|
||||
> Al usar el label `:host`, el runner usará las herramientas instaladas en tu Linux de WSL2 sin necesidad de Docker, lo que lo hace mucho más rápido.
|
||||
|
||||
@@ -4,4 +4,4 @@ $env:PKG_CONFIG_PATH = "D:\esto_al_path\msys64\mingw64\lib\pkgconfig"
|
||||
Write-Host "Starting TeamSpeak Client (Windows Native)..." -ForegroundColor Cyan
|
||||
# go run ./cmd/client/main.go --server localhost:9987
|
||||
# go run ./cmd/example --server localhost:9987
|
||||
go run ./cmd/tui --server ts.vlazaro.es:9987 --nickname Adam --debug
|
||||
go run ./cmd/tui --server 127.0.0.1:9987 --nickname Adam --debug
|
||||
|
||||
Reference in New Issue
Block a user