Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ap/ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func (ap *Accesspoint) init(ctx context.Context) (err error) {
return fmt.Errorf("failed initializing diffiehellman: %w", err)
}

// close previous connection if any
if ap.conn != nil {
_ = ap.conn.Close()
ap.conn = nil
}

// open connection to accesspoint
attempts := 0
for {
Expand Down Expand Up @@ -182,7 +188,14 @@ func (ap *Accesspoint) Connect(ctx context.Context, creds *pb.LoginCredentials)
ap.connMu.Lock()
defer ap.connMu.Unlock()

return ap.connect(ctx, creds)
return backoff.Retry(func() error {
err := ap.connect(ctx, creds)
if err != nil {
ap.log.WithError(err).Warnf("failed connecting to accesspoint, retrying")
}

return err
}, backoff.WithContext(backoff.WithMaxRetries(backoff.NewConstantBackOff(500*time.Millisecond), 5), ctx))
}

func (ap *Accesspoint) connect(ctx context.Context, creds *pb.LoginCredentials) error {
Expand Down
8 changes: 3 additions & 5 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"encoding/hex"
"fmt"
"net/http"
"time"

"github.com/devgianlu/go-librespot/events"
"github.com/devgianlu/go-librespot/mercury"
"github.com/devgianlu/go-librespot/player"
"net/http"
"time"

librespot "github.com/devgianlu/go-librespot"
"github.com/devgianlu/go-librespot/ap"
Expand Down Expand Up @@ -93,9 +94,6 @@ func NewSessionFromOptions(ctx context.Context, opts *Options) (*Session, error)
return nil, fmt.Errorf("failed getting accesspoint from resolver: %w", err)
}
s.ap = ap.NewAccesspoint(opts.Log, apAddr, s.deviceId)
if err != nil {
return nil, fmt.Errorf("failed initializing accesspoint: %w", err)
}

// authenticate with the accesspoint using the proper credentials
switch creds := opts.Credentials.(type) {
Expand Down