Files
Iris/src/js/services/mopidy/actions.js

573 lines
9.2 KiB
JavaScript
Raw Normal View History

import { createRange } from '../../util/arrays';
import { generateGuid } from '../../util/helpers';
2019-09-05 15:36:11 +12:00
export function set(data) {
return {
type: 'MOPIDY_SET',
data,
};
}
export function updateServer(server) {
return {
type: 'MOPIDY_UPDATE_SERVER',
server,
};
}
export function updateServers(servers) {
return {
type: 'MOPIDY_UPDATE_SERVERS',
servers,
};
}
export function addServer() {
return {
type: 'MOPIDY_UPDATE_SERVER',
server: {
id: generateGuid(),
name: 'New server',
host: window.location.hostname,
port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
2020-04-30 15:45:55 +12:00
ssl: window.location.protocol === 'https:',
},
};
}
export function setCurrentServer(server) {
return {
type: 'MOPIDY_SET_CURRENT_SERVER',
server,
};
}
export function removeServer(id) {
return {
type: 'MOPIDY_REMOVE_SERVER',
id,
};
}
2019-11-05 16:05:49 +13:00
export function setConnection(data) {
return {
type: 'MOPIDY_SET_CONNECTION',
data,
};
}
2019-09-05 15:36:11 +12:00
export function request(method, params = {}, response_callback = null, error_callback = null) {
return {
type: 'MOPIDY_REQUEST',
method,
params,
response_callback,
error_callback,
};
2018-09-24 16:10:42 +12:00
}
2019-09-05 15:36:11 +12:00
export function connect() {
return {
type: 'MOPIDY_CONNECT',
};
}
2019-09-05 15:36:11 +12:00
export function connecting() {
return {
type: 'MOPIDY_CONNECTING',
};
}
2019-09-05 15:36:11 +12:00
export function disconnect() {
return {
type: 'MOPIDY_DISCONNECT',
};
}
2019-09-05 15:36:11 +12:00
export function debug(call, value) {
return {
type: 'MOPIDY_DEBUG',
call,
value,
};
}
2019-09-05 15:36:11 +12:00
export function restartStarted() {
return {
type: 'MOPIDY_RESTART_STARTED',
};
2016-10-18 08:56:53 +13:00
}
2019-09-05 15:36:11 +12:00
export function restartFinished() {
return {
type: 'MOPIDY_RESTART_FINISHED',
};
2018-11-02 16:10:38 +13:00
}
2019-09-05 15:36:11 +12:00
export function upgradeStarted() {
return {
type: 'MOPIDY_UPGRADE_STARTED',
};
2018-11-02 16:10:38 +13:00
}
2019-09-05 15:36:11 +12:00
export function upgradeFinished() {
return {
type: 'MOPIDY_UPGRADE_FINISHED',
};
2018-11-02 16:10:38 +13:00
}
2019-09-05 15:36:11 +12:00
export function localScanStarted() {
return {
type: 'MOPIDY_LOCAL_SCAN_STARTED',
};
2018-11-02 16:10:38 +13:00
}
2019-09-05 15:36:11 +12:00
export function localScanFinished() {
return {
type: 'MOPIDY_LOCAL_SCAN_FINISHED',
};
}
/**
* Core play actions
2019-09-05 15:36:11 +12:00
* */
2019-09-05 15:36:11 +12:00
export function getPlayState() {
return {
type: 'MOPIDY_GET_PLAY_STATE',
};
}
2019-09-05 15:36:11 +12:00
export function play() {
return {
type: 'MOPIDY_PLAY',
};
}
2019-09-05 15:36:11 +12:00
export function pause() {
return {
type: 'MOPIDY_PAUSE',
};
}
2019-09-05 15:36:11 +12:00
export function stop() {
return {
type: 'MOPIDY_STOP',
};
}
2019-09-05 15:36:11 +12:00
export function next() {
return {
type: 'MOPIDY_NEXT',
};
}
2019-09-05 15:36:11 +12:00
export function previous() {
return {
type: 'MOPIDY_PREVIOUS',
};
}
2019-09-05 15:36:11 +12:00
export function getMute() {
return {
type: 'MOPIDY_GET_MUTE',
};
}
2019-09-05 15:36:11 +12:00
export function setMute(mute) {
return {
type: 'MOPIDY_SET_MUTE',
mute,
};
}
2019-09-05 15:36:11 +12:00
export function getVolume() {
return {
type: 'MOPIDY_GET_VOLUME',
};
}
2019-09-05 15:36:11 +12:00
export function setVolume(volume) {
return {
type: 'MOPIDY_SET_VOLUME',
volume,
};
}
2019-09-05 15:36:11 +12:00
export function getConsume() {
return {
type: 'MOPIDY_GET_CONSUME',
};
}
2019-09-05 15:36:11 +12:00
export function setConsume(consume) {
return {
type: 'MOPIDY_SET_CONSUME',
consume,
};
}
2019-09-05 15:36:11 +12:00
export function getRepeat() {
return {
type: 'MOPIDY_GET_REPEAT',
};
}
2019-09-05 15:36:11 +12:00
export function setRepeat(repeat) {
return {
type: 'MOPIDY_SET_REPEAT',
repeat,
};
}
2019-09-05 15:36:11 +12:00
export function getRandom() {
return {
type: 'MOPIDY_GET_RANDOM',
};
}
2019-09-05 15:36:11 +12:00
export function setRandom(random) {
return {
type: 'MOPIDY_SET_RANDOM',
random,
};
}
2019-09-05 15:36:11 +12:00
export function getTimePosition() {
return {
type: 'MOPIDY_GET_TIME_POSITION',
};
}
2019-09-05 15:36:11 +12:00
export function setTimePosition(time_position) {
return {
type: 'MOPIDY_SET_TIME_POSITION',
time_position: parseInt(time_position),
};
}
2019-09-05 15:36:11 +12:00
export function timePosition(time_position) {
return {
type: 'MOPIDY_TIME_POSITION',
time_position: parseInt(time_position),
};
}
2019-09-05 15:36:11 +12:00
export function getUriSchemes() {
return {
type: 'MOPIDY_GET_URI_SCHEMES',
};
}
/**
* Advanced playback actions
2019-09-05 15:36:11 +12:00
* */
2019-09-05 15:36:11 +12:00
export function getCurrentTrack() {
return {
type: 'MOPIDY_GET_CURRENT_TRACK',
};
}
2019-09-05 15:36:11 +12:00
export function currentTrackLoaded(tl_track) {
return {
type: 'MOPIDY_CURRENT_TRACK_LOADED',
tl_track,
};
}
2019-09-05 15:36:11 +12:00
export function getNextTrack() {
return {
type: 'MOPIDY_GET_NEXT_TRACK',
};
}
2019-09-05 15:36:11 +12:00
export function clearCurrentTrack() {
return {
type: 'CLEAR_CURRENT_TRACK',
};
}
2019-09-05 15:36:11 +12:00
export function getQueue() {
return {
type: 'MOPIDY_GET_QUEUE',
};
}
2019-09-05 15:36:11 +12:00
export function changeTrack(tlid) {
return {
type: 'MOPIDY_CHANGE_TRACK',
tlid,
};
}
2019-03-18 16:26:16 +13:00
/**
* Playing assets
2019-09-05 15:36:11 +12:00
* */
2019-03-18 16:26:16 +13:00
2019-09-05 15:36:11 +12:00
export function playURIs(uris = [], from_uri = null, shuffle = false) {
return {
type: 'MOPIDY_PLAY_URIS',
uris,
from_uri,
shuffle,
2019-09-05 15:36:11 +12:00
};
}
2019-09-05 15:36:11 +12:00
export function playAlbum(uri) {
return {
type: 'MOPIDY_PLAY_ALBUM',
uri,
};
2019-03-18 16:26:16 +13:00
}
2019-09-05 15:36:11 +12:00
export function playPlaylist(uri, shuffle = false) {
return {
type: 'MOPIDY_PLAY_PLAYLIST',
uri,
shuffle,
};
2019-03-18 16:26:16 +13:00
}
2019-09-05 15:36:11 +12:00
export function enqueueURIs(uris = [], from_uri = null, play_next = false, at_position = null, offset = 0) {
return {
type: 'MOPIDY_ENQUEUE_URIS',
uris,
from_uri,
at_position,
play_next,
offset,
};
2016-10-19 14:09:34 +13:00
}
2019-09-05 15:36:11 +12:00
export function enqueueAlbum(uri, next = false, at_position = null) {
return {
type: 'MOPIDY_ENQUEUE_ALBUM',
uri,
next,
at_position,
};
2017-05-05 03:56:55 +12:00
}
2019-09-05 15:36:11 +12:00
export function enqueuePlaylist(uri, play_next = false, at_position = null) {
return {
type: 'MOPIDY_ENQUEUE_PLAYLIST',
uri,
play_next,
at_position,
};
}
2019-09-05 15:36:11 +12:00
export function enqueueURIsBatchDone() {
return {
type: 'MOPIDY_ENQUEUE_URIS_BATCH_DONE',
};
2019-03-18 16:26:16 +13:00
}
/**
* Playlist maniopulation
2019-09-05 15:36:11 +12:00
* */
2019-03-18 16:26:16 +13:00
2019-09-05 15:36:11 +12:00
export function removeTracks(tlids) {
return {
type: 'MOPIDY_REMOVE_TRACKS',
tlids,
};
}
2019-09-05 15:36:11 +12:00
export function reorderTracklist(indexes, insert_before) {
const range = createRange(indexes);
2019-09-05 15:36:11 +12:00
if (insert_before > range.start) insert_before -= range.length;
return {
type: 'MOPIDY_REORDER_TRACKLIST',
range_start: range.start,
range_length: range.length,
insert_before,
};
}
2019-09-05 15:36:11 +12:00
export function clearTracklist() {
return {
type: 'MOPIDY_CLEAR_TRACKLIST',
};
2017-01-22 12:54:20 +13:00
}
export function shuffleTracklist() {
return {
type: 'MOPIDY_SHUFFLE_TRACKLIST',
};
}
/**
* Asset-oriented actions
2019-09-05 15:36:11 +12:00
* */
2019-09-05 15:36:11 +12:00
export function getImages(context, uris) {
return {
type: 'MOPIDY_GET_IMAGES',
context,
uris,
};
}
2019-09-05 15:36:11 +12:00
export function createPlaylist(name, scheme) {
return {
type: 'MOPIDY_CREATE_PLAYLIST',
name,
scheme,
};
2017-08-22 20:44:36 +12:00
}
2019-09-05 15:36:11 +12:00
export function deletePlaylist(uri) {
return {
type: 'MOPIDY_DELETE_PLAYLIST',
uri,
};
2016-11-14 11:20:02 +13:00
}
2019-09-05 15:36:11 +12:00
export function getLibraryPlaylists() {
return { type: 'MOPIDY_GET_LIBRARY_PLAYLISTS' };
}
2019-09-05 15:36:11 +12:00
export function getPlaylist(uri) {
return {
type: 'MOPIDY_GET_PLAYLIST',
data: { uri },
};
2016-11-01 07:37:18 +13:00
}
2019-09-05 15:36:11 +12:00
export function getPlaylists(uris, processor = null) {
return {
type: 'MOPIDY_GET_PLAYLISTS',
uris,
processor,
};
2017-08-13 21:42:19 +12:00
}
2019-09-05 15:36:11 +12:00
export function getDirectory(uri) {
return {
type: 'MOPIDY_GET_DIRECTORY',
2020-01-22 21:21:49 +13:00
uri,
2019-09-05 15:36:11 +12:00
};
2016-11-01 11:49:04 +13:00
}
2020-08-03 20:42:17 +12:00
export function getTracks(uris, get_images) {
2019-09-05 15:36:11 +12:00
return {
2020-08-03 20:42:17 +12:00
type: 'MOPIDY_GET_TRACKS',
uris,
get_images,
2019-09-05 15:36:11 +12:00
};
}
2020-08-03 20:42:17 +12:00
export function getTrack(uri) {
return getTracks([uri], true);
}
2019-09-05 15:36:11 +12:00
export function getLibraryArtists(uri = null) {
return {
type: 'MOPIDY_GET_LIBRARY_ARTISTS',
uri,
};
2017-08-13 21:42:19 +12:00
}
2019-09-05 15:36:11 +12:00
export function clearLibraryArtists() {
return {
type: 'MOPIDY_CLEAR_LIBRARY_ARTISTS',
};
}
2019-09-05 15:36:11 +12:00
export function getArtist(uri) {
return {
type: 'MOPIDY_GET_ARTIST',
uri,
2019-09-05 15:36:11 +12:00
};
2016-11-01 16:41:04 +13:00
}
2019-09-05 15:36:11 +12:00
export function getArtists(uris, processor = null) {
return {
type: 'MOPIDY_GET_ARTISTS',
uris,
processor,
};
2016-11-01 19:27:59 +13:00
}
2019-09-05 15:36:11 +12:00
export function getAlbum(uri) {
return {
type: 'MOPIDY_GET_ALBUM',
2020-01-22 21:21:49 +13:00
uri,
2019-09-05 15:36:11 +12:00
};
2017-01-15 21:06:24 +13:00
}
2019-09-05 15:36:11 +12:00
export function getAlbums(uris, processor = null) {
return {
type: 'MOPIDY_GET_ALBUMS',
uris,
processor,
};
}
2019-09-05 15:36:11 +12:00
export function getLibraryAlbums(uri = null) {
return {
type: 'MOPIDY_GET_LIBRARY_ALBUMS',
uri,
};
}
2019-09-05 15:36:11 +12:00
export function clearLibraryAlbums() {
return {
type: 'MOPIDY_CLEAR_LIBRARY_ALBUMS',
};
}
2019-09-05 15:36:11 +12:00
export function runProcessor(processor) {
return {
type: processor,
};
}
2019-09-05 15:36:11 +12:00
export function cancelProcessor(processor) {
return {
type: `${processor}_CANCEL`,
};
}
2020-08-03 20:42:17 +12:00
export function view_getRandomTracks(limit = 100) {
return {
2020-08-03 20:42:17 +12:00
type: 'VIEW__GET_RANDOM_TRACKS',
limit,
};
}
2016-11-06 18:29:49 +13:00
/**
2017-03-24 23:05:43 +13:00
* Searching
2019-09-05 15:36:11 +12:00
* */
2016-11-06 18:29:49 +13:00
2019-09-05 15:36:11 +12:00
export function clearSearchResults() {
return {
type: 'MOPIDY_CLEAR_SEARCH_RESULTS',
};
2017-09-05 08:26:04 +12:00
}
export function getSearchResults(type, term, limit = 100) {
2019-09-05 15:36:11 +12:00
return {
type: 'MOPIDY_GET_SEARCH_RESULTS',
query: { type, term },
2019-09-05 15:36:11 +12:00
limit,
};
2017-03-24 23:05:43 +13:00
}
/**
* Other general actions
2019-09-05 15:36:11 +12:00
* */
2017-03-24 23:05:43 +13:00
2019-09-05 15:36:11 +12:00
export function getQueueHistory() {
return {
type: 'MOPIDY_GET_QUEUE_HISTORY',
};
2017-02-10 09:06:41 +13:00
}