A music player that connects to your cloud/distributed storage.

fix: couple audio engine improvements + broadcasting

+13 -4
+2 -2
src/common/element.js
··· 283 283 * @template {{ [K in keyof ActionsWithStrategy]: ActionsWithStrategy[K]["fn"] }} Actions 284 284 * @param {string} channelName 285 285 * @param {ActionsWithStrategy} actionsWithStrategy 286 - * @param {typeof this.#broadcastingOptions} [options] 286 + * @param {{ assumeLeadership?: boolean }} [options] 287 287 */ 288 288 broadcast(channelName, actionsWithStrategy, options) { 289 289 if (this.broadcasted) return; ··· 407 407 if (assumeLeadership === undefined || assumeLeadership === true) { 408 408 navigator.locks.request( 409 409 `${this.channelName}/lock`, 410 - { ifAvailable: true }, 410 + assumeLeadership === true ? { steal: true } : { ifAvailable: true }, 411 411 (lock) => { 412 412 this.#status.resolve( 413 413 lock ? { leader: true, initialLeader: true } : { leader: false },
+11 -2
src/components/engine/audio/element.js
··· 162 162 audio.volume = volume ?? this.volume(); 163 163 audio.muted = false; 164 164 165 - if (audio.readyState === 0) audio.load(); 165 + // TODO: Might need this for `data-initial-progress` 166 + // Does seem to cause trouble when broadcasting 167 + // (open multiple sessions and play the next audio) 168 + // if (audio.readyState === 0) audio.load(); 166 169 if (!audio.isConnected) return; 167 170 168 171 const promise = audio.play() || Promise.resolve(); ··· 217 220 * @type {Actions["supply"]} 218 221 */ 219 222 supply(args) { 220 - this.#items.value = args.audio; 223 + const existingSet = new Set(this.#items.value.map((a) => a.id)); 224 + const newSet = new Set(args.audio.map((a) => a.id)); 225 + 226 + if (newSet.difference(existingSet).size !== 0) { 227 + this.#items.value = args.audio; 228 + } 229 + 221 230 if (args.play) this.play(args.play); 222 231 } 223 232