UNPKG

munar-adapter-uwave

Version:

üWave adapter for Munar

80 lines (64 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeMedia = normalizeMedia; exports.default = void 0; function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function normalizeMedia(media) { // Rename the `artist` property to `author` for consistency with other // adapters with DJ Booth support. const result = _objectSpread({}, media.media, media, { author: media.artist }); delete result.artist; return result; } class DJBooth { constructor(uw) { this.booth = null; this.uw = uw; uw.socketEvents.on('advance', booth => { const previous = this.getMedia(); this.booth = booth; uw.receive('djBooth:advance', { previous, next: this.getMedia() }); }); } getEntry() { if (!this.booth) { return null; } return { id: this.booth.historyID, media: this.getMedia(), user: this.getDJ(), playedAt: new Date(this.booth.playedAt) }; } getMedia() { if (!this.booth) { return null; } return normalizeMedia(this.booth.media); } getDJ() { if (!this.booth) { return null; } return this.uw.getUser(this.booth.userID); } async skip() { if (!this.booth) { return; } await this.uw.request('post', 'booth/skip', { userID: this.booth.userID, reason: '' }); } } exports.default = DJBooth;