This commit is contained in:
Ondrej Zara 2020-03-08 18:06:54 +01:00
parent ac85940394
commit 7a418c4e8a
No known key found for this signature in database
GPG key ID: B0A5751E616840C5
5 changed files with 103 additions and 2 deletions

View file

@ -65,3 +65,9 @@ async function init() {
init(); init();
class App extends HTMLElement {
get mpd() { return mpd; }
}
customElements.define("cyp-app", App);

3
app/js/component.js Normal file
View file

@ -0,0 +1,3 @@
export default class Component extends HTMLElement {
get _app() { return this.closest("cyp-app"); }
}

83
app/js/lib/mpd-mock.js Normal file
View file

@ -0,0 +1,83 @@
import * as mpd from "./mpd.js";
export const escape = mpd.escape;
export function command(cmd) {
console.warn(`MOCK does not know "${cmd}"`);
}
export function commandAndStatus(cmd) {
command(cmd);
return status();
}
export function status() {
return {
volume: 50,
elapsed: 10,
duration: 70,
file: "name.mp3",
Title: "Title of song",
Artist: "Artist of song",
Album: "Album of song",
Track: 6,
state: "play",
Id: 2
}
}
export function listQueue() {
return [
{id:1, Track:5, Title:"Title 1", Artist:"AAA", Album:"BBB", duration:30},
status(),
{id:3, Track:7, Title:"Title 3", Artist:"CCC", Album:"DDD", duration:230},
];
}
export async function listPlaylists() {
let lines = await command("listplaylists");
let parsed = parser.linesToStruct(lines);
let list = parsed["playlist"];
if (!list) { return []; }
return (list instanceof Array ? list : [list]);
}
export async function enqueueByFilter(filter, sort = null) {
let tokens = ["findadd"];
tokens.push(serializeFilter(filter));
// sort && tokens.push("sort", sort); FIXME not implemented in MPD
return command(tokens.join(" "));
}
export async function listPath(path) {
let lines = await command(`lsinfo "${escape(path)}"`);
return parser.pathContents(lines);
}
export async function listTags(tag, filter = null) {
let tokens = ["list", tag];
if (filter) {
tokens.push(serializeFilter(filter));
let fakeGroup = Object.keys(filter)[0]; // FIXME hack for MPD < 0.21.6
tokens.push("group", fakeGroup);
}
let lines = await command(tokens.join(" "));
let parsed = parser.linesToStruct(lines);
return [].concat(tag in parsed ? parsed[tag] : []);
}
export async function listSongs(filter, window = null) {
let tokens = ["find"];
tokens.push(serializeFilter(filter));
if (window) { tokens.push("window", window.join(":")); }
let lines = await command(tokens.join(" "));
return parser.songList(lines);
}
export async function albumArt(songUrl) {
return null;
}
export function init() {}

View file

@ -1,8 +1,10 @@
import * as mpd from "./lib/mpd.js"; //import * as mpd from "./lib/mpd.js";
import * as mpd from "./lib/mpd-mock.js";
import * as art from "./lib/art.js"; import * as art from "./lib/art.js";
import * as html from "./lib/html.js"; import * as html from "./lib/html.js";
import * as format from "./lib/format.js"; import * as format from "./lib/format.js";
import * as pubsub from "./lib/pubsub.js"; import * as pubsub from "./lib/pubsub.js";
import Component from "./component.js";
const DELAY = 1000; const DELAY = 1000;
const DOM = {}; const DOM = {};
@ -130,3 +132,9 @@ export function init(n) {
update(); update();
} }
class Player extends Component {
}
customElements.define("cyp-player", Player);

View file

@ -1,4 +1,5 @@
import * as mpd from "./lib/mpd.js"; // import * as mpd from "./lib/mpd.js";
import * as mpd from "./lib/mpd-mock.js";
import * as html from "./lib/html.js"; import * as html from "./lib/html.js";
import * as pubsub from "./lib/pubsub.js"; import * as pubsub from "./lib/pubsub.js";
import * as ui from "./lib/ui.js"; import * as ui from "./lib/ui.js";