UNPKG

lunify.js

Version:

A basic api wrapper for the spotify api covering the oauth routes.

70 lines 2.73 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlayerDeviceManager = void 0; const Device_1 = require("./Device"); class PlayerDeviceManager { 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(); * ``` */ fetch() { return __awaiter(this, void 0, void 0, function* () { const res = yield this.client.rest.get('/me/player/devices', { headers: { Authorization: yield this.player.user.oauth.getAuthorization() } }); const devices = []; for (const apiDevice of res.devices) devices.push(new Device_1.PlayerDevice(this.client, this.player.user, apiDevice)); return devices; }); } /** * 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); * ``` */ transferPlaybackTo(device) { return __awaiter(this, void 0, void 0, function* () { const finalDevices = []; if (typeof device !== 'string') { for (const d of device) finalDevices.push(d); } else { finalDevices.push(device); } yield this.client.rest.put('/me/player', { headers: { Authorization: yield this.player.user.oauth.getAuthorization() }, body: { device_ids: finalDevices } }); return true; }); } } exports.PlayerDeviceManager = PlayerDeviceManager; //# sourceMappingURL=DeviceManager.js.map