lunify.js
Version:
A basic api wrapper for the spotify api covering the oauth routes.
50 lines • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlayerDeviceManager = void 0;
const __1 = require("../..");
class PlayerDeviceManager {
client;
player;
constructor(client, player) {
this.client = client;
this.player = player;
}
/**
* Fetch all available devices for the user and current playback
* @example ```ts
* await player.devices.fetch();
* ```
*/
async fetch() {
const res = await this.client.rest.get("/me/player/devices", {
headers: {
Authorization: await this.player.user.oauth.getAuthorization()
}
});
return res.devices.map((device) => new __1.PlayerDevice(this.client, this.player, device));
}
/**
* Transfer the current playback to provided device
* @param {string | string[]} device - id of the playback device
* @example ```ts
* const devices = await player.devices.fetch();
* const deviceId = devices[0].id;
* player.devices.transferPlaybackTo(deviceId);
* ```
*/
async transferPlaybackTo(deviceId) {
await this.client.rest.put("/me/player", {
headers: {
Authorization: await this.player.user.oauth.getAuthorization()
},
body: {
device_ids: typeof deviceId === "string"
? [deviceId]
: deviceId
}
});
return true;
}
}
exports.PlayerDeviceManager = PlayerDeviceManager;
//# sourceMappingURL=index.js.map