1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

[HTML5] Run eslint --fix.

Should I write a poem about this whole new world? ;)
This commit is contained in:
Fabio Alessandrelli
2020-11-23 13:27:13 +01:00
parent 0813008b8a
commit f316a1719d
13 changed files with 518 additions and 510 deletions

View File

@@ -36,32 +36,32 @@ const GodotAudio = {
driver: null,
interval: 0,
init: function(mix_rate, latency, onstatechange, onlatencyupdate) {
init: function (mix_rate, latency, onstatechange, onlatencyupdate) {
const ctx = new (window.AudioContext || window.webkitAudioContext)({
sampleRate: mix_rate,
// latencyHint: latency / 1000 // Do not specify, leave 'interactive' for good performance.
});
GodotAudio.ctx = ctx;
ctx.onstatechange = function() {
ctx.onstatechange = function () {
let state = 0;
switch (ctx.state) {
case 'suspended':
state = 0;
break;
case 'running':
state = 1;
break;
case 'closed':
state = 2;
break;
case 'suspended':
state = 0;
break;
case 'running':
state = 1;
break;
case 'closed':
state = 2;
break;
// no default
}
onstatechange(state);
}
};
ctx.onstatechange(); // Immeditately notify state.
// Update computed latency
GodotAudio.interval = setInterval(function() {
GodotAudio.interval = setInterval(function () {
let computed_latency = 0;
if (ctx.baseLatency) {
computed_latency += GodotAudio.ctx.baseLatency;
@@ -75,29 +75,33 @@ const GodotAudio = {
return ctx.destination.channelCount;
},
create_input: function(callback) {
create_input: function (callback) {
if (GodotAudio.input) {
return; // Already started.
}
function gotMediaInput(stream) {
GodotAudio.input = GodotAudio.ctx.createMediaStreamSource(stream);
callback(GodotAudio.input)
callback(GodotAudio.input);
}
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
"audio": true
}).then(gotMediaInput, function(e) { GodotRuntime.print(e) });
'audio': true,
}).then(gotMediaInput, function (e) {
GodotRuntime.print(e);
});
} else {
if (!navigator.getUserMedia) {
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
}
navigator.getUserMedia({
"audio": true
}, gotMediaInput, function(e) { GodotRuntime.print(e) });
'audio': true,
}, gotMediaInput, function (e) {
GodotRuntime.print(e);
});
}
},
close_async: function(resolve, reject) {
close_async: function (resolve, reject) {
const ctx = GodotAudio.ctx;
GodotAudio.ctx = null;
// Audio was not initialized.
@@ -120,14 +124,14 @@ const GodotAudio = {
if (GodotAudio.driver) {
closed = GodotAudio.driver.close();
}
closed.then(function() {
closed.then(function () {
return ctx.close();
}).then(function() {
}).then(function () {
ctx.onstatechange = null;
resolve();
}).catch(function(e) {
}).catch(function (e) {
ctx.onstatechange = null;
GodotRuntime.error("Error closing AudioContext", e);
GodotRuntime.error('Error closing AudioContext', e);
resolve();
});
},
@@ -141,30 +145,30 @@ const GodotAudio = {
return 1;
},
godot_audio_init: function(p_mix_rate, p_latency, p_state_change, p_latency_update) {
godot_audio_init: function (p_mix_rate, p_latency, p_state_change, p_latency_update) {
const statechange = GodotRuntime.get_func(p_state_change);
const latencyupdate = GodotRuntime.get_func(p_latency_update);
return GodotAudio.init(p_mix_rate, p_latency, statechange, latencyupdate);
},
godot_audio_resume: function() {
godot_audio_resume: function () {
if (GodotAudio.ctx && GodotAudio.ctx.state !== 'running') {
GodotAudio.ctx.resume();
}
},
godot_audio_capture_start__proxy: 'sync',
godot_audio_capture_start: function() {
godot_audio_capture_start: function () {
if (GodotAudio.input) {
return; // Already started.
}
GodotAudio.create_input(function(input) {
GodotAudio.create_input(function (input) {
input.connect(GodotAudio.driver.get_node());
});
},
godot_audio_capture_stop__proxy: 'sync',
godot_audio_capture_stop: function() {
godot_audio_capture_stop: function () {
if (GodotAudio.input) {
const tracks = GodotAudio.input['mediaStream']['getTracks']();
for (let i = 0; i < tracks.length; i++) {
@@ -176,7 +180,7 @@ const GodotAudio = {
},
};
autoAddDeps(GodotAudio, "$GodotAudio");
autoAddDeps(GodotAudio, '$GodotAudio');
mergeInto(LibraryManager.library, GodotAudio);
/**
@@ -188,42 +192,42 @@ const GodotAudioWorklet = {
promise: null,
worklet: null,
create: function(channels) {
create: function (channels) {
const path = GodotConfig.locate_file('godot.audio.worklet.js');
GodotAudioWorklet.promise = GodotAudio.ctx.audioWorklet.addModule(path).then(function() {
GodotAudioWorklet.promise = GodotAudio.ctx.audioWorklet.addModule(path).then(function () {
GodotAudioWorklet.worklet = new AudioWorkletNode(
GodotAudio.ctx,
'godot-processor',
{
'outputChannelCount': [channels]
}
'outputChannelCount': [channels],
},
);
return Promise.resolve();
});
GodotAudio.driver = GodotAudioWorklet;
},
start: function(in_buf, out_buf, state) {
GodotAudioWorklet.promise.then(function() {
start: function (in_buf, out_buf, state) {
GodotAudioWorklet.promise.then(function () {
const node = GodotAudioWorklet.worklet;
node.connect(GodotAudio.ctx.destination);
node.port.postMessage({
'cmd': 'start',
'data': [state, in_buf, out_buf],
});
node.port.onmessage = function(event) {
node.port.onmessage = function (event) {
GodotRuntime.error(event.data);
};
});
},
get_node: function() {
get_node: function () {
return GodotAudioWorklet.worklet;
},
close: function() {
return new Promise(function(resolve, reject) {
GodotAudioWorklet.promise.then(function() {
close: function () {
return new Promise(function (resolve, reject) {
GodotAudioWorklet.promise.then(function () {
GodotAudioWorklet.worklet.port.postMessage({
'cmd': 'stop',
'data': null,
@@ -237,32 +241,32 @@ const GodotAudioWorklet = {
},
},
godot_audio_worklet_create: function(channels) {
godot_audio_worklet_create: function (channels) {
GodotAudioWorklet.create(channels);
},
godot_audio_worklet_start: function(p_in_buf, p_in_size, p_out_buf, p_out_size, p_state) {
godot_audio_worklet_start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, p_state) {
const out_buffer = GodotRuntime.heapSub(HEAPF32, p_out_buf, p_out_size);
const in_buffer = GodotRuntime.heapSub(HEAPF32, p_in_buf, p_in_size);
const state = GodotRuntime.heapSub(HEAP32, p_state, 4);
GodotAudioWorklet.start(in_buffer, out_buffer, state);
},
godot_audio_worklet_state_wait: function(p_state, p_idx, p_expected, p_timeout) {
godot_audio_worklet_state_wait: function (p_state, p_idx, p_expected, p_timeout) {
Atomics.wait(HEAP32, (p_state >> 2) + p_idx, p_expected, p_timeout);
return Atomics.load(HEAP32, (p_state >> 2) + p_idx);
},
godot_audio_worklet_state_add: function(p_state, p_idx, p_value) {
godot_audio_worklet_state_add: function (p_state, p_idx, p_value) {
return Atomics.add(HEAP32, (p_state >> 2) + p_idx, p_value);
},
godot_audio_worklet_state_get: function(p_state, p_idx) {
godot_audio_worklet_state_get: function (p_state, p_idx) {
return Atomics.load(HEAP32, (p_state >> 2) + p_idx);
},
};
autoAddDeps(GodotAudioWorklet, "$GodotAudioWorklet");
autoAddDeps(GodotAudioWorklet, '$GodotAudioWorklet');
mergeInto(LibraryManager.library, GodotAudioWorklet);
/*
@@ -273,14 +277,14 @@ const GodotAudioScript = {
$GodotAudioScript: {
script: null,
create: function(buffer_length, channel_count) {
create: function (buffer_length, channel_count) {
GodotAudioScript.script = GodotAudio.ctx.createScriptProcessor(buffer_length, 2, channel_count);
GodotAudio.driver = GodotAudioScript;
return GodotAudioScript.script.bufferSize;
},
start: function(p_in_buf, p_in_size, p_out_buf, p_out_size, onprocess) {
GodotAudioScript.script.onaudioprocess = function(event) {
start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, onprocess) {
GodotAudioScript.script.onaudioprocess = function (event) {
// Read input
const inb = GodotRuntime.heapSub(HEAPF32, p_in_buf, p_in_size);
const input = event.inputBuffer;
@@ -312,12 +316,12 @@ const GodotAudioScript = {
GodotAudioScript.script.connect(GodotAudio.ctx.destination);
},
get_node: function() {
get_node: function () {
return GodotAudioScript.script;
},
close: function() {
return new Promise(function(resolve, reject) {
close: function () {
return new Promise(function (resolve, reject) {
GodotAudioScript.script.disconnect();
GodotAudioScript.script.onaudioprocess = null;
GodotAudioScript.script = null;
@@ -326,15 +330,15 @@ const GodotAudioScript = {
},
},
godot_audio_script_create: function(buffer_length, channel_count) {
godot_audio_script_create: function (buffer_length, channel_count) {
return GodotAudioScript.create(buffer_length, channel_count);
},
godot_audio_script_start: function(p_in_buf, p_in_size, p_out_buf, p_out_size, p_cb) {
godot_audio_script_start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, p_cb) {
const onprocess = GodotRuntime.get_func(p_cb);
GodotAudioScript.start(p_in_buf, p_in_size, p_out_buf, p_out_size, onprocess);
},
};
autoAddDeps(GodotAudioScript, "$GodotAudioScript");
autoAddDeps(GodotAudioScript, '$GodotAudioScript');
mergeInto(LibraryManager.library, GodotAudioScript);