Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8ba904341 | ||
|
|
917f69fbce | ||
|
|
6baa7127f9 |
No files matched your search
@@ -1,12 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "webamp",
|
"name": "webamp",
|
||||||
"title": "Webamp",
|
"title": "Webamp",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "A Winamp-style player on every Teahub page, fed by gandora.",
|
"description": "A Winamp-style player on every Teahub page, fed by gandora.",
|
||||||
"slots": {
|
"slots": {
|
||||||
"footer": "templates/custom/footer.tmpl"
|
"footer": "templates/custom/footer.tmpl"
|
||||||
},
|
},
|
||||||
"assets": ["public/assets/plugins/webamp/webamp-mod.js"],
|
"assets": ["public/assets/plugins/webamp/webamp-mod.js"],
|
||||||
|
"vendor": {
|
||||||
|
"public/assets/plugins/webamp/webamp.bundle.min.js": "https://registry.npmjs.org/webamp/-/webamp-1.5.0.tgz#package/built/webamp.bundle.min.js"
|
||||||
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"playlist_url": "https://gandora.yolopreneur.lol/playlist.json"
|
"playlist_url": "https://gandora.yolopreneur.lol/playlist.json"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// teahub plugin: webamp — a Winamp-style player docked on every Teahub page.
|
// teahub plugin: webamp — a Winamp-style player docked on every Teahub page.
|
||||||
// Loads Webamp from the CDN on first click, so pages stay fast for everyone else.
|
// Loads the self-hosted Webamp bundle on first click, so pages stay fast for everyone else.
|
||||||
|
|
||||||
// Module scripts have no document.currentScript, so find our tag by its data attribute.
|
// Module scripts have no document.currentScript, so find our tag by its src.
|
||||||
const script = document.querySelector('script[src*="plugins/webamp/webamp-mod.js"]');
|
const script = document.querySelector('script[src*="plugins/webamp/webamp-mod.js"]');
|
||||||
const PLAYLIST_URL = script?.dataset.playlist;
|
const PLAYLIST_URL = script?.dataset.playlist;
|
||||||
const KEY = 'teahub-webamp-open';
|
const KEY = 'teahub-webamp-open';
|
||||||
@@ -36,18 +36,49 @@ async function loadTracks() {
|
|||||||
|
|
||||||
let webamp = null;
|
let webamp = null;
|
||||||
|
|
||||||
|
// Load the UMD bundle as a classic script. Hide any AMD/CommonJS globals on the page
|
||||||
|
// while it runs, so the bundle always attaches itself to window.Webamp.
|
||||||
|
function loadWebamp() {
|
||||||
|
if (window.Webamp) return Promise.resolve(window.Webamp);
|
||||||
|
return new Promise((ok, fail) => {
|
||||||
|
const saved = { define: window.define, module: window.module, exports: window.exports };
|
||||||
|
window.define = window.module = window.exports = undefined;
|
||||||
|
const restore = () => Object.assign(window, saved);
|
||||||
|
const s = document.createElement('script');
|
||||||
|
s.src = new URL('webamp.bundle.min.js', import.meta.url).href;
|
||||||
|
s.onload = () => {
|
||||||
|
restore();
|
||||||
|
window.Webamp ? ok(window.Webamp) : fail(new Error('Webamp global missing after load'));
|
||||||
|
};
|
||||||
|
s.onerror = () => { restore(); fail(new Error('could not load ' + s.src)); };
|
||||||
|
document.head.appendChild(s);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function open() {
|
async function open() {
|
||||||
if (webamp) return;
|
if (webamp) return;
|
||||||
const { default: Webamp } = await import('https://unpkg.com/webamp@1.5.0/built/webamp.bundle.min.mjs');
|
btn.textContent = '… webamp';
|
||||||
if (!Webamp.browserIsSupported()) return;
|
try {
|
||||||
webamp = new Webamp({ initialTracks: await loadTracks() });
|
const Webamp = await loadWebamp();
|
||||||
webamp.onClose(() => {
|
if (!Webamp.browserIsSupported()) throw new Error('browser not supported');
|
||||||
webamp.dispose();
|
webamp = new Webamp({ initialTracks: await loadTracks() });
|
||||||
|
webamp.onClose(() => {
|
||||||
|
webamp.dispose();
|
||||||
|
webamp = null;
|
||||||
|
try { localStorage.removeItem(KEY); } catch {}
|
||||||
|
});
|
||||||
|
const host = document.createElement('div');
|
||||||
|
host.id = 'teahub-webamp';
|
||||||
|
document.body.appendChild(host);
|
||||||
|
await webamp.renderWhenReady(host);
|
||||||
|
try { localStorage.setItem(KEY, '1'); } catch {}
|
||||||
|
btn.textContent = '▶ webamp';
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[teahub webamp]', err);
|
||||||
webamp = null;
|
webamp = null;
|
||||||
try { localStorage.removeItem(KEY); } catch {}
|
btn.textContent = '✕ webamp';
|
||||||
});
|
btn.title = String(err && err.message || err);
|
||||||
await webamp.renderWhenReady(document.body.appendChild(document.createElement('div')));
|
}
|
||||||
try { localStorage.setItem(KEY, '1'); } catch {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small launcher in the corner: the "sound system" button.
|
// Small launcher in the corner: the "sound system" button.
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
{{/* teahub plugin: webamp */}}
|
{{/* teahub plugin: webamp */}}
|
||||||
<script type="module" nonce="{{ctx.CspScriptNonce}}" src="{{AssetUrlPrefix}}/plugins/webamp/webamp-mod.js?v=010" data-playlist="https://gandora.yolopreneur.lol/playlist.json"></script>
|
<script type="module" nonce="{{ctx.CspScriptNonce}}" src="{{AssetUrlPrefix}}/plugins/webamp/webamp-mod.js?v=012" data-playlist="https://gandora.yolopreneur.lol/playlist.json"></script>
|
||||||
Reference in new issue
Block a user