UNPKG

@jellybrick/mpris-service

Version:

Node.js implementation for the MPRIS D-Bus Interface Specification to create a mediaplayer service

85 lines (68 loc) 1.96 kB
// TODO proper import const MprisInterface = require('./mpris-interface'); const dbus = require('@jellybrick/dbus-next'); const types = require('./types'); const { property, method, signal, ACCESS_READ } = dbus.interface; class PlaylistsInterface extends MprisInterface { constructor(player) { super('org.mpris.MediaPlayer2.Playlists', player); } _ActivePlaylist = [ false, types.emptyPlaylist ]; _PlaylistCount = 0; @property({signature: 'u', access: ACCESS_READ}) get PlaylistCount() { return this._PlaylistCount; } @property({signature: 'as', access: ACCESS_READ}) get Orderings() { return ['Alphabetical', 'UserDefined']; } @property({signature: '(b(oss))', access: ACCESS_READ}) get ActivePlaylist() { return this._ActivePlaylist; } setActivePlaylistId(playlistId) { let i = this.player.getPlaylistIndex(playlistId); this.setProperty('ActivePlaylist', this.player.playlists[i] || null); } @method({inSignature: 'o'}) ActivatePlaylist(playlistId) { this.player.emit('activatePlaylist', playlistId); } @method({inSignature: 'uusb', outSignature: 'a(oss)'}) GetPlaylists(index, maxCount, order, reverseOrder) { if (!this.player.playlists) { return []; } let result = this.player.playlists.sort(function(a, b) { let ret = 1; switch (order) { case 'Alphabetical': ret = (a.Name > b.Name) ? 1 : -1; break; //case 'CreationDate': //case 'ModifiedDate': //case 'LastPlayDate': case 'UserDefined': break; } return ret; }) .slice(index, maxCount + index) .map(types.playlistToDbus); if (reverseOrder) { result.reverse(); } return result; } @signal({signature: '(oss)'}) PlaylistChanged(playlist) { return types.playlistToDbus(playlist); } } module.exports = PlaylistsInterface;