UNPKG

@42techpacks/expo-spotify-sdk

Version:
139 lines 4.26 kB
import { EventEmitter } from "expo-modules-core"; import ExpoSpotifySDKModule from "./ExpoSpotifySDKModule"; function isAvailable() { return ExpoSpotifySDKModule.isAvailable(); } function authenticateAsync(config) { if (!config.scopes || config.scopes?.length === 0) { throw new Error("scopes are required"); } return ExpoSpotifySDKModule.authenticateAsync(config); } /** * Authorizes with Spotify and immediately starts playback of the provided URI * @param uri The Spotify URI to play * @returns Promise that resolves with a success boolean */ function authorizeAndPlayURIAsync(uri) { return ExpoSpotifySDKModule.authorizeAndPlayURIAsync({ uri, }); } function isAppRemoteConnected() { return ExpoSpotifySDKModule.isAppRemoteConnected(); } function connectAppRemoteAsync(config) { if (!config.accessToken) { throw new Error("accessToken is required"); } return ExpoSpotifySDKModule.connectAppRemoteAsync(config); } function disconnectAppRemoteAsync() { return ExpoSpotifySDKModule.disconnectAppRemoteAsync(); } /** * Starts or resumes playback on the active device * @returns Promise that resolves with a success boolean */ function playAsync() { return ExpoSpotifySDKModule.playAsync(); } /** * Plays a specific track by URI * @param uri The Spotify URI of the track to play * @returns Promise that resolves with a success boolean */ function playTrackAsync(uri) { return ExpoSpotifySDKModule.playTrackAsync({ uri }); } /** * Pauses playback on the active device * @returns Promise that resolves with a success boolean */ function pauseAsync() { return ExpoSpotifySDKModule.pauseAsync(); } /** * Gets the current player state * @returns Promise that resolves with the current player state */ function getPlayerStateAsync() { return ExpoSpotifySDKModule.getPlayerStateAsync(); } /** * Subscribes to player state changes * @returns Promise that resolves with a success boolean */ function subscribeToPlayerStateAsync() { return ExpoSpotifySDKModule.subscribeToPlayerStateAsync(); } /** * Unsubscribes from player state changes * @returns Promise that resolves with a success boolean */ function unsubscribeFromPlayerStateAsync() { return ExpoSpotifySDKModule.unsubscribeFromPlayerStateAsync(); } /** * Skips to the next track in the current context * @returns Promise that resolves with a success boolean */ function skipToNextAsync() { return ExpoSpotifySDKModule.skipToNextAsync(); } /** * Skips to the previous track in the current context * @returns Promise that resolves with a success boolean */ function skipToPreviousAsync() { return ExpoSpotifySDKModule.skipToPreviousAsync(); } /** * Adds a track to the playback queue * @param config Object containing the Spotify URI to add to the queue * @returns Promise that resolves with a success boolean */ function addToQueueAsync(config) { if (!config.uri) { throw new Error("uri is required"); } return ExpoSpotifySDKModule.addToQueueAsync(config); } // Event listeners const emitter = new EventEmitter(ExpoSpotifySDKModule); function addAppRemoteConnectedListener(listener) { return emitter.addListener("onAppRemoteConnected", listener); } function addAppRemoteConnectionFailureListener(listener) { return emitter.addListener("onAppRemoteConnectionFailure", listener); } function addAppRemoteDisconnectedListener(listener) { return emitter.addListener("onAppRemoteDisconnected", listener); } function addPlayerStateChangedListener(listener) { return emitter.addListener("onPlayerStateChanged", listener); } const Authenticate = { authenticateAsync, }; const AppRemote = { authorizeAndPlayURIAsync, isAppRemoteConnected, playAsync, playTrackAsync, pauseAsync, skipToNextAsync, skipToPreviousAsync, addToQueueAsync, connectAppRemoteAsync, disconnectAppRemoteAsync, addAppRemoteConnectedListener, addAppRemoteConnectionFailureListener, addAppRemoteDisconnectedListener, getPlayerStateAsync, subscribeToPlayerStateAsync, unsubscribeFromPlayerStateAsync, addPlayerStateChangedListener, }; export { isAvailable, Authenticate, AppRemote }; //# sourceMappingURL=index.js.map