cjam / cjam/react-native-spotify-remote

Authorize Succeeds then connect fails with: Connection attempt failed. Ensure the Spotify app is installed, and try to reconnect. Stream error. Reconnect the transport to the Spotify app. The operation couldn’t be completed. Connection refused

Open
#128 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Objective-C
Stars
283
Forks
110
PR merge metrics
No merged PRs in 30d

Description

Hello @cjam,

Thank you kindly for the great library.

I'm having some trouble at the moment and cannot for the life of me find a solution to our this issue. A lot of our testers are reporting that their Spotify authorisation succeeds and then the connection to Spotify fails with this error: **Connection attempt failed. Ensure the Spotify app is installed, and try to reconnect. Stream error. Reconnect the transport to the Spotify app. The operation couldn’t be completed. Connection refused.**

I'm not able to reliably replicate this error, our logs tell us that approx 50% of our testers are experiencing this issue. Sometimes a user is able to retry the auth flow and it succeeds immediately, and sometimes it will only succeed the next day.

Because nobody has raised this issue, it's possible that it's my code that's causing this error. My connect to Spotify method where this error is thrown looks like this:
```typescript
export const connectToSpotify = async () => {
const isConnected = await SpotifyRemote.isConnectedAsync();
if (isConnected) {
return;
}

const spotifyConfig: ApiConfig = {
clientID: '',
redirectURL: '',
tokenRefreshURL: `/api/spotify/refresh`,
tokenSwapURL: `/api/spotify/swap`,
scopes: [
ApiScope.AppRemoteControlScope,
ApiScope.UserFollowReadScope,
ApiScope.PlaylistReadPrivateScope,
ApiScope.UserReadPlaybackStateScope,
ApiScope.UserReadPrivateScope,
ApiScope.UserReadEmailScope,
],
showDialog: false,
playURI: '',
};

const existingSession = await SpotifyAuth.getSession();

if (existingSession && existingSession.accessToken) {
try {
await SpotifyRemote.connect(existingSession.accessToken);
} catch (e) {
// Reauth if connection has been dropped
await SpotifyRemote.disconnect();
await SpotifyAuth.endSession();
const freshSession = await SpotifyAuth.authorize(spotifyConfig);
await SpotifyRemote.connect(freshSession.accessToken);
}
} else {
// No existing session was found so connect for the first time
const firstTimeSession = await SpotifyAuth.authorize(spotifyConfig);
// The line below throws the error
await SpotifyRemote.connect(firstTimeSession.accessToken);
}
};
```

We are also using the latest version of this library. In all test cases the users had Spotify installed on their devices and approved the requested scoped.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.