Compare commits
21 Commits
5b8e89e9a2
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed8f9a4538 | ||
|
|
1283fdc9c4 | ||
|
|
71017f1e61 | ||
|
|
81d73e9b08 | ||
|
|
36111ff781 | ||
|
|
3a1db4e80c | ||
|
|
7284b9d4b9 | ||
|
|
206f158c8e | ||
|
|
2cd818c331 | ||
|
|
952552302a | ||
|
|
b6224cd2fd | ||
|
|
5ff7affd95 | ||
|
|
6ae4d39b92 | ||
|
|
d7eb34c7d4 | ||
|
|
46fe506585 | ||
|
|
b067dbb7bf | ||
|
|
7f7d62d7d8 | ||
|
|
c81f64d9ca | ||
|
|
c1bb24473e | ||
|
|
3a57f41fc2 | ||
|
|
be5e26486c |
104
.gitea/workflows/build.yml
Normal file
104
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
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
|
||||||
|
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
|
||||||
|
cd dist && zip -r ../tui_windows_x86_64.zip . *
|
||||||
|
|
||||||
|
- name: Upload Artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: tui-windows-zip
|
||||||
|
path: 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
|
||||||
|
go build -o dist/tui_linux_${ARCH} ./cmd/tui
|
||||||
|
|
||||||
|
- name: Upload Artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: tui-linux-binaries
|
||||||
|
path: dist/*
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: [build-windows, build-linux]
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Download Artifacts
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
tui-windows-zip/tui_windows_x86_64.zip
|
||||||
|
tui-linux-binaries/*
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
15
.vscode/settings.json
vendored
Normal file
15
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"go.toolsEnvVars": {
|
||||||
|
"CGO_ENABLED": "1",
|
||||||
|
"PATH": "D:\\esto_al_path\\msys64\\mingw64\\bin;${env:PATH}",
|
||||||
|
"PKG_CONFIG_PATH": "D:\\esto_al_path\\msys64\\mingw64\\lib\\pkgconfig"
|
||||||
|
},
|
||||||
|
"gopls": {
|
||||||
|
"formatting.gofumpt": true,
|
||||||
|
"ui.diagnostic.diagnosticsDelay": "300ms",
|
||||||
|
"build.directoryFilters": [
|
||||||
|
"-vendor"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"go.lintOnSave": "package"
|
||||||
|
}
|
||||||
@@ -56,6 +56,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Silence noise (ALSA/PortAudio) on Linux or if debugFile is set
|
||||||
|
redirectStderr(debugFile)
|
||||||
|
|
||||||
// Create the TUI model
|
// Create the TUI model
|
||||||
m := NewModel(*serverAddr, *nickname)
|
m := NewModel(*serverAddr, *nickname)
|
||||||
|
|
||||||
|
|||||||
204
cmd/tui/model.go
204
cmd/tui/model.go
@@ -22,6 +22,7 @@ const (
|
|||||||
FocusChat
|
FocusChat
|
||||||
FocusInput
|
FocusInput
|
||||||
FocusUserView
|
FocusUserView
|
||||||
|
FocusAbout
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListItem represents an item in the navigation tree (Channel or User)
|
// ListItem represents an item in the navigation tree (Channel or User)
|
||||||
@@ -31,6 +32,14 @@ type ListItem struct {
|
|||||||
User *UserNode
|
User *UserNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l ListItem) IsSpacer() bool {
|
||||||
|
if l.IsUser || l.Channel == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// TeamSpeak spacers usually look like [spacer0], [*spacer1], etc.
|
||||||
|
return strings.Contains(strings.ToLower(l.Channel.Name), "[spacer")
|
||||||
|
}
|
||||||
|
|
||||||
// ChatMessage represents a message in the chat
|
// ChatMessage represents a message in the chat
|
||||||
type ChatMessage struct {
|
type ChatMessage struct {
|
||||||
Time time.Time
|
Time time.Time
|
||||||
@@ -71,6 +80,7 @@ type Model struct {
|
|||||||
|
|
||||||
// UI State
|
// UI State
|
||||||
focus Focus
|
focus Focus
|
||||||
|
lastFocus Focus // To return from About view
|
||||||
width, height int
|
width, height int
|
||||||
channels []ChannelNode
|
channels []ChannelNode
|
||||||
items []ListItem // Flattened list for navigation
|
items []ListItem // Flattened list for navigation
|
||||||
@@ -101,6 +111,7 @@ type Model struct {
|
|||||||
// User View
|
// User View
|
||||||
showUserView bool
|
showUserView bool
|
||||||
viewUser *UserNode
|
viewUser *UserNode
|
||||||
|
pokeID uint16 // Target ID for pending poke
|
||||||
}
|
}
|
||||||
|
|
||||||
// addLog adds a message to the log panel
|
// addLog adds a message to the log panel
|
||||||
@@ -182,6 +193,16 @@ type clientLeftMsg struct {
|
|||||||
clientID uint16
|
clientID uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type clientMovedMsg struct {
|
||||||
|
clientID uint16
|
||||||
|
channelID uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type pokeMsg struct {
|
||||||
|
senderName string
|
||||||
|
message string
|
||||||
|
}
|
||||||
|
|
||||||
type chatMsg struct {
|
type chatMsg struct {
|
||||||
senderID uint16
|
senderID uint16
|
||||||
senderName string
|
senderName string
|
||||||
@@ -239,6 +260,20 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.audioPlayer.PlayPCM(e.SenderID, e.PCM)
|
m.audioPlayer.PlayPCM(e.SenderID, e.PCM)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
m.client.On(ts3client.EventClientMoved, func(e *ts3client.ClientMovedEvent) {
|
||||||
|
m.program.Send(clientMovedMsg{
|
||||||
|
clientID: e.ClientID,
|
||||||
|
channelID: e.ChannelID,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
m.client.On(ts3client.EventPoke, func(e *ts3client.PokeEvent) {
|
||||||
|
m.program.Send(pokeMsg{
|
||||||
|
senderName: e.SenderName,
|
||||||
|
message: e.Message,
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize audio player
|
// Initialize audio player
|
||||||
@@ -348,6 +383,29 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
||||||
|
case clientMovedMsg:
|
||||||
|
if msg.clientID == m.selfID {
|
||||||
|
chName := "Unknown"
|
||||||
|
if ch := m.client.GetChannel(msg.channelID); ch != nil {
|
||||||
|
chName = ch.Name
|
||||||
|
}
|
||||||
|
m.chatMessages = append(m.chatMessages, ChatMessage{
|
||||||
|
Time: time.Now(),
|
||||||
|
Sender: "SYSTEM",
|
||||||
|
Content: fmt.Sprintf("You moved to channel: %s", chName),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case pokeMsg:
|
||||||
|
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)
|
||||||
|
return m, nil
|
||||||
|
|
||||||
case chatMsg:
|
case chatMsg:
|
||||||
m.chatMessages = append(m.chatMessages, ChatMessage{
|
m.chatMessages = append(m.chatMessages, ChatMessage{
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
@@ -455,6 +513,35 @@ func (m *Model) updateChannelList(channels []*ts3client.Channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure selectedIdx is valid (not on a spacer)
|
||||||
|
if len(m.items) > 0 {
|
||||||
|
if m.selectedIdx >= len(m.items) {
|
||||||
|
m.selectedIdx = len(m.items) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// If current is a spacer, find next valid one
|
||||||
|
if m.items[m.selectedIdx].IsSpacer() {
|
||||||
|
found := false
|
||||||
|
// Try going down
|
||||||
|
for i := m.selectedIdx; i < len(m.items); i++ {
|
||||||
|
if !m.items[i].IsSpacer() {
|
||||||
|
m.selectedIdx = i
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If not found, try going up
|
||||||
|
if !found {
|
||||||
|
for i := m.selectedIdx; i >= 0; i-- {
|
||||||
|
if !m.items[i].IsSpacer() {
|
||||||
|
m.selectedIdx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||||
@@ -475,7 +562,16 @@ func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
case "tab":
|
case "tab":
|
||||||
// Cycle focus
|
// Cycle focus
|
||||||
m.focus = (m.focus + 1) % 3
|
m.focus = (m.focus + 1) % 4 // FocusChannels, FocusChat, FocusInput, FocusUserView
|
||||||
|
return m, nil
|
||||||
|
|
||||||
|
case "f1":
|
||||||
|
if m.focus == FocusAbout {
|
||||||
|
m.focus = m.lastFocus
|
||||||
|
} else {
|
||||||
|
m.lastFocus = m.focus
|
||||||
|
m.focus = FocusAbout
|
||||||
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,8 +581,8 @@ func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
return m.handleInputKeys(msg)
|
return m.handleInputKeys(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Global Shortcuts (Only when NOT in Input)
|
// 3. Global Shortcuts (Only when NOT in Input or About)
|
||||||
if m.focus != FocusInput && m.focus != FocusUserView {
|
if m.focus != FocusInput && m.focus != FocusUserView && m.focus != FocusAbout {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "q":
|
case "q":
|
||||||
// Quit (same as ctrl+c)
|
// Quit (same as ctrl+c)
|
||||||
@@ -564,11 +660,20 @@ func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
return m.handleChatKeys(msg)
|
return m.handleChatKeys(msg)
|
||||||
case FocusUserView:
|
case FocusUserView:
|
||||||
return m.handleUserViewKeys(msg)
|
return m.handleUserViewKeys(msg)
|
||||||
|
case FocusAbout:
|
||||||
|
return m.handleAboutViewKeys(msg)
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) handleChatKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
func (m *Model) handleChatKeys(_ tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) handleAboutViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||||
|
if msg.String() == "esc" || msg.String() == "f1" {
|
||||||
|
m.focus = m.lastFocus
|
||||||
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,6 +693,13 @@ func (m *Model) handleUserViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
m.focus = FocusChannels
|
m.focus = FocusChannels
|
||||||
m.showUserView = false
|
m.showUserView = false
|
||||||
|
|
||||||
|
case "1":
|
||||||
|
// Initiate Poke: set target, clear input, and focus it
|
||||||
|
m.pokeID = u.ID
|
||||||
|
m.focus = FocusInput
|
||||||
|
m.inputText = ""
|
||||||
|
m.addLog("Write poke message for %s and press Enter...", u.Nickname)
|
||||||
|
|
||||||
case "2":
|
case "2":
|
||||||
// Toggle mute for this user
|
// Toggle mute for this user
|
||||||
_, muted := m.audioPlayer.GetUserSettings(u.ID)
|
_, muted := m.audioPlayer.GetUserSettings(u.ID)
|
||||||
@@ -618,17 +730,37 @@ func (m *Model) handleUserViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
func (m *Model) handleChannelKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
func (m *Model) handleChannelKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "up", "k":
|
case "up", "k":
|
||||||
if m.selectedIdx > 0 {
|
for m.selectedIdx > 0 {
|
||||||
m.selectedIdx--
|
m.selectedIdx--
|
||||||
|
if !m.items[m.selectedIdx].IsSpacer() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// If we hit the top and it's a spacer, we might need to go down to find the first valid one
|
||||||
|
if m.selectedIdx == 0 && m.items[m.selectedIdx].IsSpacer() {
|
||||||
|
// Search forward for the first valid one
|
||||||
|
for i := 0; i < len(m.items); i++ {
|
||||||
|
if !m.items[i].IsSpacer() {
|
||||||
|
m.selectedIdx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case "down", "j":
|
case "down", "j":
|
||||||
if m.selectedIdx < len(m.items)-1 {
|
for m.selectedIdx < len(m.items)-1 {
|
||||||
m.selectedIdx++
|
m.selectedIdx++
|
||||||
|
if !m.items[m.selectedIdx].IsSpacer() {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case "enter":
|
case "enter":
|
||||||
// Join selected channel OR open user view
|
// Join selected channel OR open user view
|
||||||
if m.selectedIdx < len(m.items) && m.client != nil {
|
if m.selectedIdx < len(m.items) && m.client != nil {
|
||||||
item := m.items[m.selectedIdx]
|
item := m.items[m.selectedIdx]
|
||||||
|
if item.IsSpacer() {
|
||||||
|
return m, nil // Do nothing for spacers
|
||||||
|
}
|
||||||
if !item.IsUser {
|
if !item.IsUser {
|
||||||
// Channel
|
// Channel
|
||||||
ch := item.Channel
|
ch := item.Channel
|
||||||
@@ -656,11 +788,27 @@ func (m *Model) handleInputKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "enter":
|
case "enter":
|
||||||
if m.inputText != "" && m.client != nil {
|
if m.inputText != "" && m.client != nil {
|
||||||
|
if m.pokeID != 0 {
|
||||||
|
err := m.client.Poke(m.pokeID, m.inputText)
|
||||||
|
if err != nil {
|
||||||
|
m.addLog("Error poking client %d: %v", m.pokeID, err)
|
||||||
|
} else {
|
||||||
|
m.addLog("Poke sent!")
|
||||||
|
}
|
||||||
|
m.pokeID = 0
|
||||||
|
m.focus = FocusUserView
|
||||||
|
} else {
|
||||||
m.client.SendChannelMessage(m.inputText)
|
m.client.SendChannelMessage(m.inputText)
|
||||||
|
}
|
||||||
m.inputText = ""
|
m.inputText = ""
|
||||||
}
|
}
|
||||||
case "esc":
|
case "esc":
|
||||||
|
if m.pokeID != 0 {
|
||||||
|
m.pokeID = 0
|
||||||
|
m.focus = FocusUserView
|
||||||
|
} else {
|
||||||
m.focus = FocusChannels
|
m.focus = FocusChannels
|
||||||
|
}
|
||||||
m.inputText = ""
|
m.inputText = ""
|
||||||
case "backspace":
|
case "backspace":
|
||||||
if len(m.inputText) > 0 {
|
if len(m.inputText) > 0 {
|
||||||
@@ -688,6 +836,10 @@ func (m *Model) handleInputKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
// View renders the UI
|
// View renders the UI
|
||||||
func (m *Model) View() string {
|
func (m *Model) View() string {
|
||||||
|
if m.focus == FocusAbout {
|
||||||
|
return m.renderAboutView()
|
||||||
|
}
|
||||||
|
|
||||||
if m.width == 0 {
|
if m.width == 0 {
|
||||||
return "Loading..."
|
return "Loading..."
|
||||||
}
|
}
|
||||||
@@ -794,7 +946,11 @@ func (m *Model) View() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
inputContent := "> " + m.inputText
|
prompt := "> "
|
||||||
|
if m.pokeID != 0 {
|
||||||
|
prompt = "[Poke Message] > "
|
||||||
|
}
|
||||||
|
inputContent := prompt + m.inputText
|
||||||
if m.focus == FocusInput {
|
if m.focus == FocusInput {
|
||||||
inputStyle = inputStyle.BorderForeground(lipgloss.Color("212"))
|
inputStyle = inputStyle.BorderForeground(lipgloss.Color("212"))
|
||||||
inputContent += "█"
|
inputContent += "█"
|
||||||
@@ -1062,7 +1218,7 @@ func (m *Model) renderUserView() string {
|
|||||||
fmt.Sprintf("%s %s", labelStyle.Render("Local Mute:"), muteStr),
|
fmt.Sprintf("%s %s", labelStyle.Render("Local Mute:"), muteStr),
|
||||||
"",
|
"",
|
||||||
"--- Menu ---",
|
"--- Menu ---",
|
||||||
"1. Poke (Not Impl)",
|
"1. Poke",
|
||||||
"2. Toggle Local Mute",
|
"2. Toggle Local Mute",
|
||||||
"+/-: Adjust Volume",
|
"+/-: Adjust Volume",
|
||||||
"",
|
"",
|
||||||
@@ -1071,3 +1227,35 @@ func (m *Model) renderUserView() string {
|
|||||||
|
|
||||||
return lipgloss.JoinVertical(lipgloss.Left, info...)
|
return lipgloss.JoinVertical(lipgloss.Left, info...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) renderAboutView() string {
|
||||||
|
titleStyle := lipgloss.NewStyle().
|
||||||
|
Bold(true).
|
||||||
|
Foreground(lipgloss.Color("205")).
|
||||||
|
MarginBottom(1).
|
||||||
|
Align(lipgloss.Center)
|
||||||
|
|
||||||
|
boxStyle := lipgloss.NewStyle().
|
||||||
|
Border(lipgloss.RoundedBorder()).
|
||||||
|
BorderForeground(lipgloss.Color("62")).
|
||||||
|
Padding(2).
|
||||||
|
Width(60).
|
||||||
|
Align(lipgloss.Center)
|
||||||
|
|
||||||
|
mainContent := lipgloss.JoinVertical(lipgloss.Center,
|
||||||
|
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("Con la ayuda de:"),
|
||||||
|
lipgloss.NewStyle().Foreground(lipgloss.Color("212")).Render("- Gemini 3 Pro"),
|
||||||
|
lipgloss.NewStyle().Foreground(lipgloss.Color("212")).Render("- Claude Opus 4.5"),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
lipgloss.NewStyle().Faint(true).Render("(Presiona ESC o F1 para volver)"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Center everything on screen
|
||||||
|
return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, boxStyle.Render(mainContent))
|
||||||
|
}
|
||||||
|
|||||||
24
cmd/tui/noise_linux.go
Normal file
24
cmd/tui/noise_linux.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func redirectStderr(f *os.File) {
|
||||||
|
if f == nil {
|
||||||
|
// Silence altogether if no debug file
|
||||||
|
null, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
|
||||||
|
if err == nil {
|
||||||
|
_ = unix.Dup2(int(null.Fd()), int(os.Stderr.Fd()))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect fd 2 (stderr) to our debug file
|
||||||
|
// This captures C-level library noise (ALSA, PortAudio) into the log
|
||||||
|
_ = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
|
||||||
|
}
|
||||||
12
cmd/tui/noise_other.go
Normal file
12
cmd/tui/noise_other.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func redirectStderr(f *os.File) {
|
||||||
|
// No-op on other platforms for now
|
||||||
|
// Windows doesn't have the ALSA noise problem
|
||||||
|
}
|
||||||
1
go.mod
1
go.mod
@@ -13,6 +13,7 @@ require (
|
|||||||
github.com/charmbracelet/bubbletea v1.3.10
|
github.com/charmbracelet/bubbletea v1.3.10
|
||||||
github.com/charmbracelet/lipgloss v1.1.0
|
github.com/charmbracelet/lipgloss v1.1.0
|
||||||
github.com/go-ole/go-ole v1.2.6
|
github.com/go-ole/go-ole v1.2.6
|
||||||
|
github.com/gordonklaus/portaudio v0.0.0-20250206071425-98a94950218b
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/moutend/go-wca v0.3.0
|
github.com/moutend/go-wca v0.3.0
|
||||||
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302
|
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -20,6 +20,8 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6
|
|||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
|
github.com/gordonklaus/portaudio v0.0.0-20250206071425-98a94950218b h1:WEuQWBxelOGHA6z9lABqaMLMrfwVyMdN3UgRLT+YUPo=
|
||||||
|
github.com/gordonklaus/portaudio v0.0.0-20250206071425-98a94950218b/go.mod h1:esZFQEUwqC+l76f2R8bIWSwXMaPbp79PppwZ1eJhFco=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
|
|||||||
@@ -134,27 +134,42 @@ func (c *Client) Connect(address string) error {
|
|||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
// Recovery from panics in the main loop
|
||||||
|
func() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
log.Printf("PANIC in Client loop: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-c.done:
|
case <-c.done:
|
||||||
log.Println("Client loop stopped")
|
log.Println("Client loop stopped")
|
||||||
return nil
|
return
|
||||||
case pkt := <-pktChan:
|
case pkt := <-pktChan:
|
||||||
if pkt == nil {
|
if pkt == nil {
|
||||||
// Channel closed
|
// Channel closed
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if err := c.handlePacket(pkt); err != nil {
|
if err := c.handlePacket(pkt); err != nil {
|
||||||
log.Printf("Error handling packet: %v", err)
|
log.Printf("Error handling packet: %v", err)
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if !c.Connected {
|
if !c.Connected {
|
||||||
continue // Don't send pings if not connected yet
|
return // Don't send pings if not connected yet
|
||||||
}
|
}
|
||||||
// Send KeepAlive Ping (Encrypted, No NewProtocol)
|
// Send KeepAlive Ping (Encrypted, No NewProtocol)
|
||||||
if err := c.sendPing(); err != nil {
|
if err := c.sendPing(); err != nil {
|
||||||
log.Printf("Error sending Ping: %v", err)
|
log.Printf("Error sending Ping: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
// Check if we should exit after the inner function
|
||||||
|
select {
|
||||||
|
case <-c.done:
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,8 +226,8 @@ func (c *Client) processCommand(data []byte, pkt *protocol.Packet) error {
|
|||||||
cmdStr := string(data)
|
cmdStr := string(data)
|
||||||
|
|
||||||
// Debug: Log packet flags and raw command preview (sanitized)
|
// Debug: Log packet flags and raw command preview (sanitized)
|
||||||
log.Printf("Debug Packet: Compressed=%v, Fragmented=%v, RawLen=%d, Preview=%q",
|
log.Printf("Debug Packet: PID=%d, Compressed=%v, Fragmented=%v, RawLen=%d, Preview=%q",
|
||||||
pkt.Header.FlagCompressed(), pkt.Header.FlagFragmented(), len(data),
|
pkt.Header.PacketID, pkt.Header.FlagCompressed(), pkt.Header.FlagFragmented(), len(data),
|
||||||
func() string {
|
func() string {
|
||||||
preview := cmdStr
|
preview := cmdStr
|
||||||
if len(preview) > 100 {
|
if len(preview) > 100 {
|
||||||
@@ -544,6 +544,28 @@ func (c *Client) processCommand(data []byte, pkt *protocol.Packet) error {
|
|||||||
"message": msg,
|
"message": msg,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
case "notifyclientpoke":
|
||||||
|
msg := ""
|
||||||
|
invoker := "Unknown"
|
||||||
|
var invokerID uint16
|
||||||
|
if m, ok := args["msg"]; ok {
|
||||||
|
msg = protocol.Unescape(m)
|
||||||
|
}
|
||||||
|
if name, ok := args["invokername"]; ok {
|
||||||
|
invoker = protocol.Unescape(name)
|
||||||
|
}
|
||||||
|
if iid, ok := args["invokerid"]; ok {
|
||||||
|
var id uint64
|
||||||
|
fmt.Sscanf(iid, "%d", &id)
|
||||||
|
invokerID = uint16(id)
|
||||||
|
}
|
||||||
|
log.Printf("[Poke] %s: %s", invoker, msg)
|
||||||
|
c.emitEvent("client_poke", map[string]any{
|
||||||
|
"senderID": invokerID,
|
||||||
|
"senderName": invoker,
|
||||||
|
"message": msg,
|
||||||
|
})
|
||||||
|
|
||||||
case "notifyservergrouplist", "notifychannelgrouplist", "notifyclientneededpermissions":
|
case "notifyservergrouplist", "notifychannelgrouplist", "notifyclientneededpermissions":
|
||||||
// Ignore verbose noisy setup commands
|
// Ignore verbose noisy setup commands
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
package audio
|
package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -11,8 +13,6 @@ import (
|
|||||||
"github.com/moutend/go-wca/pkg/wca"
|
"github.com/moutend/go-wca/pkg/wca"
|
||||||
)
|
)
|
||||||
|
|
||||||
const captureFrameSamples = 960 // 20ms at 48kHz
|
|
||||||
|
|
||||||
// Capturer handles WASAPI audio capture from microphone
|
// Capturer handles WASAPI audio capture from microphone
|
||||||
type Capturer struct {
|
type Capturer struct {
|
||||||
client *wca.IAudioClient
|
client *wca.IAudioClient
|
||||||
|
|||||||
112
pkg/audio/capture_linux.go
Normal file
112
pkg/audio/capture_linux.go
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package audio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/gordonklaus/portaudio"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Capturer handles audio capture using PortAudio
|
||||||
|
type Capturer struct {
|
||||||
|
stream *portaudio.Stream
|
||||||
|
running bool
|
||||||
|
mu sync.Mutex
|
||||||
|
onAudio func(samples []int16)
|
||||||
|
currentLevel int
|
||||||
|
levelMu sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCapturer() (*Capturer, error) {
|
||||||
|
if err := initPortAudio(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Capturer{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) SetCallback(fn func(samples []int16)) {
|
||||||
|
c.mu.Lock()
|
||||||
|
c.onAudio = fn
|
||||||
|
c.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) Start() error {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
if c.running {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
c.stream, err = portaudio.OpenDefaultStream(1, 0, 48000, frameSamples, c.processCapture)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open portaudio capture stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.stream.Start(); err != nil {
|
||||||
|
c.stream.Close()
|
||||||
|
return fmt.Errorf("failed to start portaudio capture stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.running = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) Stop() {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
if !c.running {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.running = false
|
||||||
|
if c.stream != nil {
|
||||||
|
c.stream.Abort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) Close() {
|
||||||
|
c.Stop()
|
||||||
|
c.mu.Lock()
|
||||||
|
if c.stream != nil {
|
||||||
|
c.stream.Close()
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
terminatePortAudio()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) processCapture(in []int16) {
|
||||||
|
c.mu.Lock()
|
||||||
|
callback := c.onAudio
|
||||||
|
running := c.running
|
||||||
|
c.mu.Unlock()
|
||||||
|
|
||||||
|
if !running || callback == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate level
|
||||||
|
level := CalculateRMSLevel(in)
|
||||||
|
c.levelMu.Lock()
|
||||||
|
c.currentLevel = level
|
||||||
|
c.levelMu.Unlock()
|
||||||
|
|
||||||
|
// Clone buffer and send to callback
|
||||||
|
samples := make([]int16, len(in))
|
||||||
|
copy(samples, in)
|
||||||
|
callback(samples)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) GetLevel() int {
|
||||||
|
c.levelMu.RLock()
|
||||||
|
defer c.levelMu.RUnlock()
|
||||||
|
return c.currentLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Capturer) IsRunning() bool {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
return c.running
|
||||||
|
}
|
||||||
13
pkg/audio/common.go
Normal file
13
pkg/audio/common.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package audio
|
||||||
|
|
||||||
|
// Shared constants
|
||||||
|
const (
|
||||||
|
frameSamples = 960 // 20ms at 48kHz
|
||||||
|
captureFrameSamples = 960 // 20ms at 48kHz
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserSettings represents per-user audio configuration
|
||||||
|
type UserSettings struct {
|
||||||
|
Volume float32 // 0.0 - 1.0 (or higher for boost)
|
||||||
|
Muted bool
|
||||||
|
}
|
||||||
45
pkg/audio/global_linux.go
Normal file
45
pkg/audio/global_linux.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package audio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/gordonklaus/portaudio"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
paMu sync.Mutex
|
||||||
|
paRefCount int
|
||||||
|
)
|
||||||
|
|
||||||
|
func initPortAudio() error {
|
||||||
|
paMu.Lock()
|
||||||
|
defer paMu.Unlock()
|
||||||
|
|
||||||
|
if paRefCount == 0 {
|
||||||
|
if err := portaudio.Initialize(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
devices, err := portaudio.Devices()
|
||||||
|
if err == nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "[Audio] Linux/PortAudio initialized globally. Devices found: %d\n", len(devices))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paRefCount++
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func terminatePortAudio() {
|
||||||
|
paMu.Lock()
|
||||||
|
defer paMu.Unlock()
|
||||||
|
|
||||||
|
paRefCount--
|
||||||
|
if paRefCount == 0 {
|
||||||
|
fmt.Fprintf(os.Stderr, "[Audio] Linux/PortAudio terminating globally...\n")
|
||||||
|
portaudio.Terminate()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
package audio
|
package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@@ -32,19 +35,11 @@ type Player struct {
|
|||||||
bufferMu sync.Mutex
|
bufferMu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserSettings struct {
|
|
||||||
Volume float32 // 0.0 - 1.0 (or higher for boost)
|
|
||||||
Muted bool
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
frameSamples = 960 // 20ms at 48kHz
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewPlayer creates a new WASAPI audio player
|
// NewPlayer creates a new WASAPI audio player
|
||||||
func NewPlayer() (*Player, error) {
|
func NewPlayer() (*Player, error) {
|
||||||
// Initialize COM
|
// Initialize COM
|
||||||
ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED)
|
ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED)
|
||||||
|
log.Printf("[Audio] Windows/WASAPI initializing...")
|
||||||
|
|
||||||
var deviceEnumerator *wca.IMMDeviceEnumerator
|
var deviceEnumerator *wca.IMMDeviceEnumerator
|
||||||
if err := wca.CoCreateInstance(
|
if err := wca.CoCreateInstance(
|
||||||
@@ -255,7 +250,7 @@ func (p *Player) GetUserSettings(clientID uint16) (float32, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) playbackLoop() {
|
func (p *Player) playbackLoop() {
|
||||||
ticker := time.NewTicker(20 * time.Millisecond)
|
ticker := time.NewTicker(10 * time.Millisecond)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -269,6 +264,7 @@ func (p *Player) playbackLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) writeFrame() {
|
func (p *Player) writeFrame() {
|
||||||
|
for {
|
||||||
var padding uint32
|
var padding uint32
|
||||||
if err := p.client.GetCurrentPadding(&padding); err != nil {
|
if err := p.client.GetCurrentPadding(&padding); err != nil {
|
||||||
return
|
return
|
||||||
@@ -284,9 +280,11 @@ func (p *Player) writeFrame() {
|
|||||||
// Mix audio from all active user buffers
|
// Mix audio from all active user buffers
|
||||||
mixed := make([]int32, frameSamples)
|
mixed := make([]int32, frameSamples)
|
||||||
activeUsers := 0
|
activeUsers := 0
|
||||||
|
hasAnyAudio := false
|
||||||
|
|
||||||
for id, buf := range p.userBuffers {
|
for id, buf := range p.userBuffers {
|
||||||
if len(buf) > 0 {
|
if len(buf) > 0 {
|
||||||
|
hasAnyAudio = true
|
||||||
activeUsers++
|
activeUsers++
|
||||||
// Take up to frameSamples from this user
|
// Take up to frameSamples from this user
|
||||||
toTake := frameSamples
|
toTake := frameSamples
|
||||||
@@ -316,6 +314,11 @@ func (p *Player) writeFrame() {
|
|||||||
|
|
||||||
p.bufferMu.Unlock()
|
p.bufferMu.Unlock()
|
||||||
|
|
||||||
|
// If no audio is playing, don't write anything (keep buffer empty for lower latency when audio starts)
|
||||||
|
if !hasAnyAudio {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get WASAPI buffer
|
// Get WASAPI buffer
|
||||||
var buffer *byte
|
var buffer *byte
|
||||||
if err := p.renderClient.GetBuffer(uint32(frameSamples), &buffer); err != nil {
|
if err := p.renderClient.GetBuffer(uint32(frameSamples), &buffer); err != nil {
|
||||||
@@ -331,7 +334,7 @@ func (p *Player) writeFrame() {
|
|||||||
for i := 0; i < int(frameSamples); i++ {
|
for i := 0; i < int(frameSamples); i++ {
|
||||||
val := mixed[i]
|
val := mixed[i]
|
||||||
|
|
||||||
// Apply volume
|
// Apply master volume
|
||||||
val = int32(float32(val) * vol)
|
val = int32(float32(val) * vol)
|
||||||
|
|
||||||
// Hard clipping
|
// Hard clipping
|
||||||
@@ -345,3 +348,4 @@ func (p *Player) writeFrame() {
|
|||||||
|
|
||||||
p.renderClient.ReleaseBuffer(uint32(frameSamples), 0)
|
p.renderClient.ReleaseBuffer(uint32(frameSamples), 0)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
201
pkg/audio/playback_linux.go
Normal file
201
pkg/audio/playback_linux.go
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package audio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/gordonklaus/portaudio"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Player handles audio playback using PortAudio
|
||||||
|
type Player struct {
|
||||||
|
stream *portaudio.Stream
|
||||||
|
volume float32
|
||||||
|
muted bool
|
||||||
|
mu sync.Mutex
|
||||||
|
running bool
|
||||||
|
stopChan chan struct{}
|
||||||
|
|
||||||
|
// User buffers for mixing
|
||||||
|
userBuffers map[uint16][]int16
|
||||||
|
// User settings
|
||||||
|
userSettings map[uint16]*UserSettings
|
||||||
|
bufferMu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPlayer() (*Player, error) {
|
||||||
|
if err := initPortAudio(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := &Player{
|
||||||
|
volume: 1.0,
|
||||||
|
muted: false,
|
||||||
|
stopChan: make(chan struct{}),
|
||||||
|
userBuffers: make(map[uint16][]int16),
|
||||||
|
userSettings: make(map[uint16]*UserSettings),
|
||||||
|
}
|
||||||
|
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) Start() error {
|
||||||
|
p.mu.Lock()
|
||||||
|
if p.running {
|
||||||
|
p.mu.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create stream (Mono, 48kHz, 16-bit)
|
||||||
|
// We'll use a callback-based stream for lower latency
|
||||||
|
var err error
|
||||||
|
p.stream, err = portaudio.OpenDefaultStream(0, 1, 48000, frameSamples, p.processAudio)
|
||||||
|
if err != nil {
|
||||||
|
p.mu.Unlock()
|
||||||
|
return fmt.Errorf("failed to open portaudio stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := p.stream.Start(); err != nil {
|
||||||
|
p.stream.Close()
|
||||||
|
p.mu.Unlock()
|
||||||
|
return fmt.Errorf("failed to start portaudio stream: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
p.running = true
|
||||||
|
p.mu.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) Stop() {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
if !p.running {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.running = false
|
||||||
|
if p.stream != nil {
|
||||||
|
p.stream.Abort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) Close() {
|
||||||
|
p.Stop()
|
||||||
|
p.mu.Lock()
|
||||||
|
if p.stream != nil {
|
||||||
|
p.stream.Close()
|
||||||
|
}
|
||||||
|
p.mu.Unlock()
|
||||||
|
terminatePortAudio()
|
||||||
|
}
|
||||||
|
|
||||||
|
// processAudio is the PortAudio callback
|
||||||
|
func (p *Player) processAudio(out []int16) {
|
||||||
|
p.bufferMu.Lock()
|
||||||
|
defer p.bufferMu.Unlock()
|
||||||
|
|
||||||
|
// Initial silence
|
||||||
|
for i := range out {
|
||||||
|
out[i] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.muted {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.mu.Lock()
|
||||||
|
vol := p.volume
|
||||||
|
p.mu.Unlock()
|
||||||
|
|
||||||
|
mixed := make([]int32, len(out))
|
||||||
|
|
||||||
|
for id, buf := range p.userBuffers {
|
||||||
|
if len(buf) > 0 {
|
||||||
|
toTake := len(out)
|
||||||
|
if len(buf) < toTake {
|
||||||
|
toTake = len(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < toTake; i++ {
|
||||||
|
sample := int32(buf[i])
|
||||||
|
if settings, ok := p.userSettings[id]; ok {
|
||||||
|
sample = int32(float32(sample) * settings.Volume)
|
||||||
|
}
|
||||||
|
mixed[i] += sample
|
||||||
|
}
|
||||||
|
|
||||||
|
// Advance buffer
|
||||||
|
if len(buf) <= len(out) {
|
||||||
|
delete(p.userBuffers, id)
|
||||||
|
} else {
|
||||||
|
p.userBuffers[id] = buf[len(out):]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply master volume and clip
|
||||||
|
for i := 0; i < len(out); i++ {
|
||||||
|
val := int32(float32(mixed[i]) * vol)
|
||||||
|
if val > 32767 {
|
||||||
|
val = 32767
|
||||||
|
} else if val < -32768 {
|
||||||
|
val = -32768
|
||||||
|
}
|
||||||
|
out[i] = int16(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) PlayPCM(senderID uint16, samples []int16) {
|
||||||
|
p.bufferMu.Lock()
|
||||||
|
defer p.bufferMu.Unlock()
|
||||||
|
|
||||||
|
if settings, ok := p.userSettings[senderID]; ok && settings.Muted {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.userBuffers[senderID] = append(p.userBuffers[senderID], samples...)
|
||||||
|
if len(p.userBuffers[senderID]) > 48000*2 {
|
||||||
|
drop := len(p.userBuffers[senderID]) - 48000
|
||||||
|
p.userBuffers[senderID] = p.userBuffers[senderID][drop:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) SetVolume(vol float32) {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
p.volume = vol
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) SetMuted(muted bool) {
|
||||||
|
p.mu.Lock()
|
||||||
|
defer p.mu.Unlock()
|
||||||
|
p.muted = muted
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) SetUserVolume(clientID uint16, vol float32) {
|
||||||
|
p.bufferMu.Lock()
|
||||||
|
defer p.bufferMu.Unlock()
|
||||||
|
if _, ok := p.userSettings[clientID]; !ok {
|
||||||
|
p.userSettings[clientID] = &UserSettings{Volume: 1.0, Muted: false}
|
||||||
|
}
|
||||||
|
p.userSettings[clientID].Volume = vol
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) SetUserMuted(clientID uint16, muted bool) {
|
||||||
|
p.bufferMu.Lock()
|
||||||
|
defer p.bufferMu.Unlock()
|
||||||
|
if _, ok := p.userSettings[clientID]; !ok {
|
||||||
|
p.userSettings[clientID] = &UserSettings{Volume: 1.0, Muted: false}
|
||||||
|
}
|
||||||
|
p.userSettings[clientID].Muted = muted
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) GetUserSettings(clientID uint16) (float32, bool) {
|
||||||
|
p.bufferMu.Lock()
|
||||||
|
defer p.bufferMu.Unlock()
|
||||||
|
if settings, ok := p.userSettings[clientID]; ok {
|
||||||
|
return settings.Volume, settings.Muted
|
||||||
|
}
|
||||||
|
return 1.0, false
|
||||||
|
}
|
||||||
@@ -124,6 +124,10 @@ func (c *Client) emit(event EventType, data any) {
|
|||||||
if fn, ok := h.(func(*TalkingStatusEvent)); ok {
|
if fn, ok := h.(func(*TalkingStatusEvent)); ok {
|
||||||
fn(data.(*TalkingStatusEvent))
|
fn(data.(*TalkingStatusEvent))
|
||||||
}
|
}
|
||||||
|
case EventPoke:
|
||||||
|
if fn, ok := h.(func(*PokeEvent)); ok {
|
||||||
|
fn(data.(*PokeEvent))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,6 +409,13 @@ func (c *Client) handleInternalEvent(eventType string, data map[string]any) {
|
|||||||
Channels: getInt(data, "channels"),
|
Channels: getInt(data, "channels"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
case "client_poke":
|
||||||
|
c.emit(EventPoke, &PokeEvent{
|
||||||
|
SenderID: getUint16(data, "senderID"),
|
||||||
|
SenderName: getString(data, "senderName"),
|
||||||
|
Message: getString(data, "message"),
|
||||||
|
})
|
||||||
|
|
||||||
case "error":
|
case "error":
|
||||||
c.emit(EventError, &ErrorEvent{
|
c.emit(EventError, &ErrorEvent{
|
||||||
ID: getString(data, "id"),
|
ID: getString(data, "id"),
|
||||||
|
|||||||
@@ -235,6 +235,19 @@ func (c *Client) KickFromServer(clientID uint16, reason string) error {
|
|||||||
return c.internal.SendCommand(cmd)
|
return c.internal.SendCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Poke sends a poke message to a specific client
|
||||||
|
func (c *Client) Poke(clientID uint16, message string) error {
|
||||||
|
if c.internal == nil {
|
||||||
|
return fmt.Errorf("not connected")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := protocol.NewCommand("clientpoke")
|
||||||
|
cmd.AddParam("clid", fmt.Sprintf("%d", clientID))
|
||||||
|
cmd.AddParam("msg", message)
|
||||||
|
|
||||||
|
return c.internal.SendCommand(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Info Methods
|
// Info Methods
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|||||||
@@ -25,8 +25,18 @@ const (
|
|||||||
|
|
||||||
// Error events
|
// Error events
|
||||||
EventError EventType = "error"
|
EventError EventType = "error"
|
||||||
|
|
||||||
|
// Poke events
|
||||||
|
EventPoke EventType = "poke"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PokeEvent is emitted when a poke message is received
|
||||||
|
type PokeEvent struct {
|
||||||
|
SenderID uint16
|
||||||
|
SenderName string
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
// ConnectedEvent is emitted when the client successfully connects
|
// ConnectedEvent is emitted when the client successfully connects
|
||||||
type ConnectedEvent struct {
|
type ConnectedEvent struct {
|
||||||
ClientID uint16
|
ClientID uint16
|
||||||
|
|||||||
116
readme.md
Normal file
116
readme.md
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
# TeamSpeak TUI Client
|
||||||
|
|
||||||
|
A modern, fast, and lightweight TeamSpeak 3 client built in Go with a beautiful Terminal User Interface (TUI).
|
||||||
|
|
||||||
|
## 🚀 Features
|
||||||
|
- **Low Latency Audio**: Optimized for both Windows (WASAPI) and Linux (PortAudio).
|
||||||
|
- **Responsive UI**: Built with Bubble Tea for a smooth terminal experience.
|
||||||
|
- **Cross-Platform**: Full support for Windows and Linux (including WSL2).
|
||||||
|
- **Audio Controls**: Per-user volume and mute indicators.
|
||||||
|
|
||||||
|
## 🛠️ Linux Dependencies
|
||||||
|
|
||||||
|
To build the project on Linux (including Ubuntu/WSL2), you need to install the following system libraries:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
libportaudio2 \
|
||||||
|
portaudio19-dev \
|
||||||
|
libopus-dev \
|
||||||
|
libpulse-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔊 WSL2 Audio Setup
|
||||||
|
|
||||||
|
WSL2 does not have direct access to your Windows audio hardware. To enable audio, we recommend using a PulseAudio network bridge:
|
||||||
|
|
||||||
|
1. **Install PulseAudio on Windows** (e.g., via [portable binaries](https://www.freedesktop.org/wiki/Software/PulseAudio/Ports/Windows/)).
|
||||||
|
2. **Enable TCP**: Edit `default.pa` in PulseAudio and add:
|
||||||
|
`load-module module-native-protocol-tcp auth-anonymous=1 listen=0.0.0.0`
|
||||||
|
3. **Environment Variable**: Set the `PULSE_SERVER` in your WSL2 shell:
|
||||||
|
```bash
|
||||||
|
export PULSE_SERVER=tcp:$(grep nameserver /etc/resolv.conf | awk '{print $2}'):4713
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🏗️ Building
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# General build
|
||||||
|
go build -o ts-tui ./cmd/tui
|
||||||
|
|
||||||
|
# Run with debug logging (highly recommended for audio setup)
|
||||||
|
go run ./cmd/tui --server your-ip:9987 --debug
|
||||||
|
```
|
||||||
|
|
||||||
|
## ⌨️ Common Keys
|
||||||
|
- `q`: Quit cleanly.
|
||||||
|
- `Arrows / hjkl`: Navigate channels and users.
|
||||||
|
- `Enter`: Join channel.
|
||||||
|
- `1`: Poke user (in User View).
|
||||||
|
- `m`: Mute/Unmute audio.
|
||||||
|
## 💻 Development with VS Code
|
||||||
|
|
||||||
|
This project uses Go **build tags** to support multiple platforms from the same codebase. This can sometimes cause "redeclared" errors or "undefined" symbols in VS Code if not configured correctly.
|
||||||
|
|
||||||
|
### Recommended Setup
|
||||||
|
|
||||||
|
1. **Windows + MSYS2**: If you are developing on Windows and have Opus/PortAudio installed via MSYS2, your `.vscode/settings.json` should include the paths to your MinGW64 environment:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"go.toolsEnvVars": {
|
||||||
|
"CGO_ENABLED": "1",
|
||||||
|
"PATH": "C:\\msys64\\mingw64\\bin;${env:PATH}",
|
||||||
|
"PKG_CONFIG_PATH": "C:\\msys64\\mingw64\\lib\\pkgconfig"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. **Build Tags**: Do **not** force both tags simultaneously (e.g., `-tags=linux,windows`) as this will cause "redeclared" errors for types defined in both systems (like `Player` or `Capturer`).
|
||||||
|
3. **Switching OS Analysis**: If you are on Windows but want to check for errors in the Linux files, update your settings to:
|
||||||
|
```json
|
||||||
|
"go.toolsEnvVars": { "GOOS": "linux" }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pro Tip: VS Code Remote - WSL
|
||||||
|
For the best experience when working on Linux features from Windows, use the **WSL extension**. Open VS Code inside your WSL environment (`code .` from the WSL terminal). This allows `gopls` to run directly in Linux, where all system headers and libraries are natively available.
|
||||||
|
|
||||||
|
## 🤖 Gitea Actions (CI/CD)
|
||||||
|
|
||||||
|
El archivo `.gitea/workflows/build-windows.yml` automatiza la compilación en cada push.
|
||||||
|
|
||||||
|
### Cómo usar tu propio Windows como Runner
|
||||||
|
|
||||||
|
Si tu Gitea no tiene runners públicos, puedes convertir tu propia máquina Windows en uno:
|
||||||
|
|
||||||
|
1. **Descarga `act_runner`**: Descarga el binario oficial de [Gitea Actions Runner](https://gitea.com/gitea/act_runner/releases).
|
||||||
|
2. **Registro**:
|
||||||
|
- Ve a tu instancia de Gitea -> Administración del Sitio -> Actions -> Runners.
|
||||||
|
- Copia el **Registration Token**.
|
||||||
|
- Ejecuta: `./act_runner register`
|
||||||
|
- Introduce la URL de tu Gitea y el token.
|
||||||
|
- En **labels**, asegúrate de poner `windows-latest:host`.
|
||||||
|
3. **Ejecución**:
|
||||||
|
- Lanza el runner: `./act_runner daemon`.
|
||||||
|
- Ahora, cualquier push lanzará la build en tu PC de forma automática.
|
||||||
|
|
||||||
|
> [!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-linux.yml`, cambia `runs-on: ubuntu-latest` por `runs-on: linux-x86_64`.
|
||||||
|
|
||||||
|
> [!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.
|
||||||
@@ -3,4 +3,5 @@ $env:PKG_CONFIG_PATH = "D:\esto_al_path\msys64\mingw64\lib\pkgconfig"
|
|||||||
|
|
||||||
Write-Host "Starting TeamSpeak Client (Windows Native)..." -ForegroundColor Cyan
|
Write-Host "Starting TeamSpeak Client (Windows Native)..." -ForegroundColor Cyan
|
||||||
# go run ./cmd/client/main.go --server localhost:9987
|
# go run ./cmd/client/main.go --server localhost:9987
|
||||||
go run ./cmd/example --server localhost:9987
|
# go run ./cmd/example --server localhost:9987
|
||||||
|
go run ./cmd/tui --server ts.vlazaro.es:9987 --nickname Adam --debug
|
||||||
11
timestamp.go
11
timestamp.go
@@ -1,11 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
t, _ := time.Parse("2006-01-02 15:04:05", "2023-07-24 10:06:33")
|
|
||||||
fmt.Println(t.Unix())
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user