Files
RTSP-Streamer/internal/player/player_test.go
Levi Woodard ed9814ab4e Reconnect streams in-process; fix for_window IPC rules
Root cause of the periodic drops (found via the new logs): mpv was
exiting cleanly (err=nil, exit 0) with its status line at 100% — i.e.
end-of-stream. UniFi Protect closes some cameras' RTSP connections every
20-40s; with --keep-open=no --idle=no mpv treated that as the file
ending, exited, and the supervisor relaunched it ~3s later (the visible
drop).

- Add --loop-file=inf so mpv reopens the stream the instant it EOFs,
  in the same process and window: sub-second recovery, no teardown,
  no supervisor bounce. The supervisor now only fires for real crashes.
- Clean up the logged exit "reason": strip ANSI escapes and skip mpv's
  transient A/V status prints, so a genuine error surfaces instead of
  "\x1b[KV: 00:00:35 / 00:00:35 (100%)". Tests cover the parsing.

Also fold in the for_window IPC fix: sway's IPC parser splits comma-
joined command lists at the top level and does not fold the continuation
into for_window (unlike the config-file parser), so the map-time
placement rules errored with "Only views can have borders" and never
installed. Register each command separately; drop the redundant
border none (the kiosk config already sets default_border none).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 12:54:02 -05:00

32 lines
884 B
Go

package player
import (
"fmt"
"testing"
"github.com/lwoodard/rtsp-streamer/internal/logbuf"
)
func TestLastLinePrefersRealMessageOverStatus(t *testing.T) {
w := logbuf.New(20)
fmt.Fprintln(w, "Failed to open rtsps://host/x: Connection refused")
fmt.Fprint(w, "\x1b[KV: 00:00:35 / 00:00:35 (100%)\n") // ANSI-wrapped status
if got := lastLine(w); got != "Failed to open rtsps://host/x: Connection refused" {
t.Errorf("lastLine = %q, want the error line", got)
}
}
func TestLastLineFallsBackToStatusWhenOnlyStatus(t *testing.T) {
w := logbuf.New(20)
fmt.Fprint(w, "\x1b[KV: 00:00:20 / 00:00:20 (100%)\n")
if got := lastLine(w); got != "V: 00:00:20 / 00:00:20 (100%)" {
t.Errorf("lastLine = %q, want the stripped status line", got)
}
}
func TestLastLineNil(t *testing.T) {
if got := lastLine(nil); got != "" {
t.Errorf("lastLine(nil) = %q, want empty", got)
}
}