A music player that connects to your cloud/distributed storage.
1import { DiffuseElement } from "~/common/element.js";
2import { hostsFromTracks } from "./common.js";
3import { SCHEME } from "./constants.js";
4
5/**
6 * @import {InputActions, InputSchemeProvider} from "~/components/input/types.d.ts"
7 * @import {ProxiedActions} from "~/common/worker.d.ts"
8 * @import {Track} from "~/definitions/types.d.ts"
9 */
10
11////////////////////////////////////////////
12// ELEMENT
13////////////////////////////////////////////
14
15/**
16 * @implements {ProxiedActions<InputActions>}
17 * @implements {InputSchemeProvider}
18 */
19class IcecastInput extends DiffuseElement {
20 static NAME = "diffuse/input/icecast";
21 static WORKER_URL = "components/input/icecast/worker.js";
22
23 SCHEME = SCHEME;
24
25 constructor() {
26 super();
27
28 /** @type {ProxiedActions<InputActions>} */
29 this.proxy = this.workerProxy();
30
31 this.consult = this.proxy.consult;
32 this.detach = this.proxy.detach;
33 this.groupConsult = this.proxy.groupConsult;
34 this.list = this.proxy.list;
35 this.resolve = this.proxy.resolve;
36 }
37
38 // 🛠️
39
40 /** @param {Track[]} tracks */
41 sources(tracks) {
42 const hosts = Object.values(hostsFromTracks(tracks));
43
44 return hosts.map((host) => ({
45 label: host,
46 uri: `${SCHEME}://${host}`,
47 }));
48 }
49}
50
51export default IcecastInput;
52
53////////////////////////////////////////////
54// REGISTER
55////////////////////////////////////////////
56
57export const CLASS = IcecastInput;
58export const NAME = "di-icecast";
59
60customElements.define(NAME, CLASS);