Synchronize connection and transmission state

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-10 00:45:22 -04:00
committed by Brandon McGinty
parent 3efbd019ce
commit 55772fa459
4 changed files with 64 additions and 23 deletions
+13 -13
View File
@@ -236,7 +236,7 @@ func (b *Barnard) CommandPlayFile(ui *uiterm.Ui, cmd string) {
}
}
if !b.Connected {
if !b.isConnected() {
b.AddOutputLine("Not connected to server")
return
}
@@ -267,7 +267,7 @@ func (b *Barnard) CommandPlayFile(ui *uiterm.Ui, cmd string) {
b.Client.EnableStereoEncoder()
// Auto-start transmission if not already transmitting
if !b.Tx && b.Stream != nil {
if !b.isTransmitting() && b.Stream != nil {
err := b.Stream.StartSource(b.UserConfig.GetInputDevice())
if err != nil {
b.AddOutputLine(fmt.Sprintf("Error starting transmission: %s", err.Error()))
@@ -275,7 +275,7 @@ func (b *Barnard) CommandPlayFile(ui *uiterm.Ui, cmd string) {
b.Client.DisableStereoEncoder()
return
}
b.Tx = true
b.setTransmitting(true)
b.UpdateGeneralStatus(" File ", true)
}
@@ -312,15 +312,15 @@ func (b *Barnard) CommandStopFile(ui *uiterm.Ui, cmd string) {
}
func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) {
if b.Tx && val == 1 {
if b.isTransmitting() && val == 1 {
return
}
if b.Tx == false && val == 0 {
if !b.isTransmitting() && val == 0 {
return
}
if b.Tx {
if b.isTransmitting() {
b.Notify("micdown", "me", "")
b.Tx = false
b.setTransmitting(false)
b.UpdateGeneralStatus(" Idle ", false)
if b.ToneTest {
if b.toneTestStop != nil {
@@ -330,17 +330,17 @@ func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) {
} else if b.Stream != nil {
b.Stream.StopSource()
}
} else if b.Connected == false {
} else if !b.isConnected() {
b.Notify("error", "me", "no tx while disconnected")
b.Tx = false
b.setTransmitting(false)
b.UpdateGeneralStatus("no tx while disconnected", true)
} else if b.isChannelMuted(b.Client.Self.Channel.ID) {
// Check if current channel is muted
b.Notify("error", "me", "cannot transmit in muted channel")
b.Tx = false
b.setTransmitting(false)
b.UpdateGeneralStatus("cannot transmit in muted channel", true)
} else {
b.Tx = true
b.setTransmitting(true)
if b.ToneTest {
b.toneTestStop = make(chan struct{})
go StartToneGenerator(b.Client, b.toneTestStop)
@@ -349,7 +349,7 @@ func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) {
} else {
err := b.Stream.StartSource(b.UserConfig.GetInputDevice())
if err != nil {
b.Tx = false
b.setTransmitting(false)
if fatalAudioOpenError(err) {
// A missing capture device cannot recover through normal
// transmission controls; exit so option 1 reports it on stderr.
@@ -405,7 +405,7 @@ func (b *Barnard) CommandExit(ui *uiterm.Ui, cmd string) {
}
func (b *Barnard) CommandStatus(ui *uiterm.Ui, cmd string) {
if b.Tx {
if b.isTransmitting() {
b.Notify("status", "me", "transmitting")
} else {
b.Notify("status", "me", "not transmitting")