@nent/core
Version:
90 lines (87 loc) • 2.56 kB
JavaScript
/*!
* NENT 2022
*/
import { r as registerInstance, h, a as getElement, H as Host } from './index-916ca544.js';
import { a as actionBus } from './index-f7016b94.js';
import { a as AUDIO_TOPIC, L as LoadStrategy, D as DiscardStrategy, c as AudioType } from './interfaces-13ff7aec.js';
import { s as state, o as onChange } from './state-627a24e0.js';
import { f as debugIf } from './logging-5a93c8af.js';
import './index-4bfabbbd.js';
const AudioMusicLoad = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.sent = false;
/**
* This is the loading strategy that determines
* what it should do after the file is retrieved.
*/
this.mode = 'queue';
/**
* The discard strategy the player should use for this file.
*/
this.discard = 'route';
/**
* Set this to true to have the audio file loop.
*/
this.loop = false;
/**
* If set, disables auto-rendering of this instance.
* To fetch the contents change to false or remove
* attribute.
*/
this.deferLoad = false;
}
/**
* Get the underlying actionEvent instance.
*/
async getAction() {
return {
topic: AUDIO_TOPIC,
command: this.mode || LoadStrategy.load,
data: {
trackId: this.trackId || this.src,
src: this.src,
discard: this.discard || DiscardStrategy.route,
loop: this.loop,
type: AudioType.music,
mode: this.mode || LoadStrategy.load,
},
};
}
/**
* Send this action to the the action messaging system.
*/
async sendAction(data) {
const action = await this.getAction();
if (data)
Object.assign(action.data, data);
if (state.hasAudioComponent) {
actionBus.emit(action.topic, action);
}
else {
this.dispose = onChange('hasAudioComponent', async (loaded) => {
var _a;
if (loaded) {
actionBus.emit(action.topic, action);
debugIf(state.debug, `n-audio-action-music-load: load-action sent for ${this.trackId}`);
this.sent = true;
}
(_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this);
});
}
}
async componentWillRender() {
if (this.deferLoad || this.sent)
return;
await this.sendAction();
}
render() {
return h(Host, null);
}
disconnectedCallback() {
var _a;
(_a = this.dispose) === null || _a === void 0 ? void 0 : _a.call(this);
}
get el() { return getElement(this); }
};
export { AudioMusicLoad as n_audio_action_music_load };