@wwdrew/expo-spotify-sdk
Version:
Expo module wrapping the native Spotify iOS (v5) and Android (v4) SDKs for OAuth authentication and App Remote playback control
88 lines • 3.77 kB
TypeScript
import type { EventSubscription } from "expo-modules-core";
import { type AppRemoteErrorCode } from "./error";
export type { AppRemoteErrorCode } from "./error";
export { AppRemoteError } from "./error";
/** Current state of the IPC connection to the Spotify app. */
export type ConnectionState = "disconnected" | "connecting" | "connected";
/** Payload of the `connectionStateChange` event. */
export interface ConnectionStateChangeEvent {
state: ConnectionState;
}
/** Payload of the `connectionError` event. */
export interface ConnectionErrorEvent {
code: AppRemoteErrorCode;
message: string;
}
/**
* Spotify App Remote namespace. Manages the IPC connection to the running
* Spotify app. All `Player`, `User`, `Content`, and `Images` calls require an
* active connection established via `AppRemote.connect()`.
*
* @example
* ```ts
* import { AppRemote } from "@wwdrew/expo-spotify-sdk";
*
* // Connect using the access token from Auth.authenticate()
* await AppRemote.connect(session.accessToken);
*
* const sub = AppRemote.addListener("connectionStateChange", ({ state }) => {
* console.log("connection state:", state);
* });
*
* // later:
* await AppRemote.disconnect();
* sub.remove();
* ```
*/
export declare const AppRemote: {
/**
* Opens a connection to the running Spotify app using the provided access
* token. Resolves when the connection is established; rejects with an
* {@link AppRemoteError} if the connection fails.
*
* **Android note:** The access token is accepted for API parity with iOS but
* the Android App Remote SDK does not accept it directly — it uses the
* session cached in the Spotify app from your earlier `Auth.authenticate()`
* call. Ensure `Auth.authenticate()` has succeeded before calling `connect()`.
*
* Calling `connect()` while already connected is a no-op.
*/
readonly connect: (accessToken: string) => Promise<void>;
/**
* Wakes Spotify (launching if suspended), starts or resumes playback, and
* connects. Use when {@link connect} may fail because Spotify is not running.
* Always foregrounds Spotify and starts audio — see package api-reference.
*
* @param accessToken Access token from `Auth.authenticate()`.
* @param uri Spotify URI to play, or empty (default) to resume last/contextual track.
*/
readonly authorizeAndPlay: (accessToken: string, uri?: string) => Promise<void>;
/**
* Disconnects from the Spotify app. Safe to call when already disconnected.
* Resolves once the disconnection is complete.
*/
readonly disconnect: () => Promise<void>;
/**
* Returns `true` if currently connected to the Spotify app.
* This is a synchronous snapshot — subscribe to `"connectionStateChange"`
* for reactive updates.
*/
readonly isConnected: () => boolean;
/**
* Returns the current {@link ConnectionState} synchronously.
* Subscribe to `"connectionStateChange"` for reactive updates.
*/
readonly getConnectionState: () => Promise<ConnectionState>;
/**
* Subscribes to connection lifecycle events.
*
* | Event | Payload | When |
* |---|---|---|
* | `"connectionStateChange"` | `{ state: ConnectionState }` | State transitions |
* | `"connectionError"` | `{ code, message }` | Connection failures and drops |
*
* Returns a `Subscription` — call `.remove()` to unsubscribe.
*/
readonly addListener: <E extends "connectionStateChange" | "connectionError">(event: E, listener: E extends "connectionStateChange" ? (event: ConnectionStateChangeEvent) => void : (event: ConnectionErrorEvent) => void) => EventSubscription;
};
//# sourceMappingURL=index.d.ts.map