Skip to content

Commit

Permalink
Eheh
Browse files Browse the repository at this point in the history
  • Loading branch information
Namaneo committed Aug 11, 2023
1 parent 561ae5a commit 8feb875
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ui/sources/services/audio.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Reworked from: https://github.com/chrisd1100/libmatoya/blob/main/src/unix/web/matoya.js

export default class Audio {
static #context = new AudioContext();
static #context = null;

static #state = {
/** @type {boolean} */
Expand Down Expand Up @@ -43,12 +43,6 @@ export default class Audio {
static unlock() {
window.addEventListener('blur', () => this.#context = null);

window.addEventListener('focus', () => {
this.#context = new AudioContext();
this.#state.sample_rate = 0;
this.#state.channels = 0;
});

const unlock = () => this.#context.state == 'suspended' && this.#context.resume();
window.addEventListener('keydown', unlock);
window.addEventListener('mousedown', unlock);
Expand All @@ -63,6 +57,9 @@ export default class Audio {
static #update(sampleRate, channels) {
const state = this.#state;

if (!this.#context)
this.#context = new AudioContext();

if (state.sample_rate == sampleRate && state.channels == channels)
return;

Expand Down

0 comments on commit 8feb875

Please sign in to comment.