Skip to content

Commit

Permalink
fix: Fix occasional panic if initial connection hangs for too long
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 6, 2023
1 parent 763af6b commit 2441abf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ func (d *Device) tick() error {
func (d *Device) connect(opts ...application.ApplicationOption) error {
if d.app != nil {
_ = d.app.Close(false)
d.app = nil
}
opts = append(
opts,
application.WithSkipadSleep(config.Default.PlayingInterval),
application.WithSkipadRetries(int(time.Minute/config.Default.PlayingInterval)),
)
d.app = application.NewApplication(opts...)
app := application.NewApplication(opts...)
d.app.AddMessageFunc(d.onMessage)

if err := util.Retry(d.ctx, 6, 500*time.Millisecond, func(try uint) error {
Expand All @@ -239,6 +240,8 @@ func (d *Device) connect(opts ...application.ApplicationOption) error {
d.logger.Info("Connected to cast device.")
}

d.app = app

return nil
}

Expand Down

0 comments on commit 2441abf

Please sign in to comment.