Skip to content

Commit

Permalink
fix: Fix panic if initial connection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 6, 2023
1 parent 763af6b commit ba1d690
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,15 @@ 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...)
d.app.AddMessageFunc(d.onMessage)
app := application.NewApplication(opts...)
app.AddMessageFunc(d.onMessage)

if err := util.Retry(d.ctx, 6, 500*time.Millisecond, func(try uint) error {
if err := d.app.Start(d.entry.GetAddr(), d.entry.GetPort()); err != nil {
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 ba1d690

Please sign in to comment.