summaryrefslogtreecommitdiff
path: root/platform/web/js
diff options
context:
space:
mode:
Diffstat (limited to 'platform/web/js')
-rw-r--r--platform/web/js/engine/config.js3
-rw-r--r--platform/web/js/engine/engine.js25
-rw-r--r--platform/web/js/engine/features.js96
-rw-r--r--platform/web/js/libs/audio.worklet.js2
-rw-r--r--platform/web/js/libs/library_godot_audio.js9
-rw-r--r--platform/web/js/libs/library_godot_display.js6
-rw-r--r--platform/web/js/libs/library_godot_javascript_singleton.js4
-rw-r--r--platform/web/js/libs/library_godot_os.js14
8 files changed, 130 insertions, 29 deletions
diff --git a/platform/web/js/engine/config.js b/platform/web/js/engine/config.js
index 9c4b6c2012..41be7b2512 100644
--- a/platform/web/js/engine/config.js
+++ b/platform/web/js/engine/config.js
@@ -317,7 +317,8 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
if (!(this.canvas instanceof HTMLCanvasElement)) {
const nodes = document.getElementsByTagName('canvas');
if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
- this.canvas = nodes[0];
+ const first = nodes[0];
+ this.canvas = /** @type {!HTMLCanvasElement} */ (first);
}
if (!this.canvas) {
throw new Error('No canvas found in page');
diff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.js
index 6f0d51b2be..9227aa1f05 100644
--- a/platform/web/js/engine/engine.js
+++ b/platform/web/js/engine/engine.js
@@ -61,20 +61,6 @@ const Engine = (function () {
};
/**
- * Check whether WebGL is available. Optionally, specify a particular version of WebGL to check for.
- *
- * @param {number=} [majorVersion=1] The major WebGL version to check for.
- * @returns {boolean} If the given major version of WebGL is available.
- * @function Engine.isWebGLAvailable
- */
- Engine.isWebGLAvailable = function (majorVersion = 1) {
- try {
- return !!document.createElement('canvas').getContext(['webgl', 'webgl2'][majorVersion - 1]);
- } catch (e) { /* Not available */ }
- return false;
- };
-
- /**
* Safe Engine constructor, creates a new prototype for every new instance to avoid prototype pollution.
* @ignore
* @constructor
@@ -265,14 +251,21 @@ const Engine = (function () {
// Also expose static methods as instance methods
Engine.prototype['load'] = Engine.load;
Engine.prototype['unload'] = Engine.unload;
- Engine.prototype['isWebGLAvailable'] = Engine.isWebGLAvailable;
return new Engine(initConfig);
}
// Closure compiler exported static methods.
SafeEngine['load'] = Engine.load;
SafeEngine['unload'] = Engine.unload;
- SafeEngine['isWebGLAvailable'] = Engine.isWebGLAvailable;
+
+ // Feature-detection utilities.
+ SafeEngine['isWebGLAvailable'] = Features.isWebGLAvailable;
+ SafeEngine['isFetchAvailable'] = Features.isFetchAvailable;
+ SafeEngine['isSecureContext'] = Features.isSecureContext;
+ SafeEngine['isCrossOriginIsolated'] = Features.isCrossOriginIsolated;
+ SafeEngine['isSharedArrayBufferAvailable'] = Features.isSharedArrayBufferAvailable;
+ SafeEngine['isAudioWorkletAvailable'] = Features.isAudioWorkletAvailable;
+ SafeEngine['getMissingFeatures'] = Features.getMissingFeatures;
return SafeEngine;
}());
diff --git a/platform/web/js/engine/features.js b/platform/web/js/engine/features.js
new file mode 100644
index 0000000000..f91a4eff81
--- /dev/null
+++ b/platform/web/js/engine/features.js
@@ -0,0 +1,96 @@
+const Features = { // eslint-disable-line no-unused-vars
+ /**
+ * Check whether WebGL is available. Optionally, specify a particular version of WebGL to check for.
+ *
+ * @param {number=} [majorVersion=1] The major WebGL version to check for.
+ * @returns {boolean} If the given major version of WebGL is available.
+ * @function Engine.isWebGLAvailable
+ */
+ isWebGLAvailable: function (majorVersion = 1) {
+ try {
+ return !!document.createElement('canvas').getContext(['webgl', 'webgl2'][majorVersion - 1]);
+ } catch (e) { /* Not available */ }
+ return false;
+ },
+
+ /**
+ * Check whether the Fetch API available and supports streaming responses.
+ *
+ * @returns {boolean} If the Fetch API is available and supports streaming responses.
+ * @function Engine.isFetchAvailable
+ */
+ isFetchAvailable: function () {
+ return 'fetch' in window && 'Response' in window && 'body' in window.Response.prototype;
+ },
+
+ /**
+ * Check whether the engine is running in a Secure Context.
+ *
+ * @returns {boolean} If the engine is running in a Secure Context.
+ * @function Engine.isSecureContext
+ */
+ isSecureContext: function () {
+ return window['isSecureContext'] === true;
+ },
+
+ /**
+ * Check whether the engine is cross origin isolated.
+ * This value is dependent on Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers sent by the server.
+ *
+ * @returns {boolean} If the engine is running in a Secure Context.
+ * @function Engine.isSecureContext
+ */
+ isCrossOriginIsolated: function () {
+ return window['crossOriginIsolated'] === true;
+ },
+
+ /**
+ * Check whether SharedBufferArray is available.
+ *
+ * Most browsers require the page to be running in a secure context, and the
+ * the server to provide specific CORS headers for SharedArrayBuffer to be available.
+ *
+ * @returns {boolean} If SharedArrayBuffer is available.
+ * @function Engine.isSharedArrayBufferAvailable
+ */
+ isSharedArrayBufferAvailable: function () {
+ return 'SharedArrayBuffer' in window;
+ },
+
+ /**
+ * Check whether the AudioContext supports AudioWorkletNodes.
+ *
+ * @returns {boolean} If AudioWorkletNode is available.
+ * @function Engine.isAudioWorkletAvailable
+ */
+ isAudioWorkletAvailable: function () {
+ return 'AudioContext' in window && 'audioWorklet' in AudioContext.prototype;
+ },
+
+ /**
+ * Return an array of missing required features (as string).
+ *
+ * @returns {Array<string>} A list of human-readable missing features.
+ * @function Engine.getMissingFeatures
+ */
+ getMissingFeatures: function () {
+ const missing = [];
+ if (!Features.isWebGLAvailable(2)) {
+ missing.push('WebGL2');
+ }
+ if (!Features.isFetchAvailable()) {
+ missing.push('Fetch');
+ }
+ if (!Features.isSecureContext()) {
+ missing.push('Secure Context');
+ }
+ if (!Features.isCrossOriginIsolated()) {
+ missing.push('Cross Origin Isolation');
+ }
+ if (!Features.isSharedArrayBufferAvailable()) {
+ missing.push('SharedArrayBuffer');
+ }
+ // Audio is normally optional since we have a dummy fallback.
+ return missing;
+ },
+};
diff --git a/platform/web/js/libs/audio.worklet.js b/platform/web/js/libs/audio.worklet.js
index ea4d8cb221..daf5c9ef12 100644
--- a/platform/web/js/libs/audio.worklet.js
+++ b/platform/web/js/libs/audio.worklet.js
@@ -133,6 +133,8 @@ class GodotProcessor extends AudioWorkletProcessor {
this.running = false;
this.output = null;
this.input = null;
+ this.lock = null;
+ this.notifier = null;
} else if (p_cmd === 'start_nothreads') {
this.output = new RingBuffer(p_data[0], p_data[0].length, false);
} else if (p_cmd === 'chunk') {
diff --git a/platform/web/js/libs/library_godot_audio.js b/platform/web/js/libs/library_godot_audio.js
index 756c1ac595..68e100cca0 100644
--- a/platform/web/js/libs/library_godot_audio.js
+++ b/platform/web/js/libs/library_godot_audio.js
@@ -339,16 +339,21 @@ const GodotAudioWorklet = {
if (GodotAudioWorklet.promise === null) {
return;
}
- GodotAudioWorklet.promise.then(function () {
+ const p = GodotAudioWorklet.promise;
+ p.then(function () {
GodotAudioWorklet.worklet.port.postMessage({
'cmd': 'stop',
'data': null,
});
GodotAudioWorklet.worklet.disconnect();
+ GodotAudioWorklet.worklet.port.onmessage = null;
GodotAudioWorklet.worklet = null;
GodotAudioWorklet.promise = null;
resolve();
- }).catch(function (err) { /* aborted? */ });
+ }).catch(function (err) {
+ // Aborted?
+ GodotRuntime.error(err);
+ });
});
},
},
diff --git a/platform/web/js/libs/library_godot_display.js b/platform/web/js/libs/library_godot_display.js
index 91cb8e728a..39c8569655 100644
--- a/platform/web/js/libs/library_godot_display.js
+++ b/platform/web/js/libs/library_godot_display.js
@@ -174,7 +174,7 @@ const GodotDisplayCursor = {
$GodotDisplayCursor__deps: ['$GodotOS', '$GodotConfig'],
$GodotDisplayCursor__postset: 'GodotOS.atexit(function(resolve, reject) { GodotDisplayCursor.clear(); resolve(); });',
$GodotDisplayCursor: {
- shape: 'auto',
+ shape: 'default',
visible: true,
cursors: {},
set_style: function (style) {
@@ -185,7 +185,7 @@ const GodotDisplayCursor = {
let css = shape;
if (shape in GodotDisplayCursor.cursors) {
const c = GodotDisplayCursor.cursors[shape];
- css = `url("${c.url}") ${c.x} ${c.y}, auto`;
+ css = `url("${c.url}") ${c.x} ${c.y}, default`;
}
if (GodotDisplayCursor.visible) {
GodotDisplayCursor.set_style(css);
@@ -193,7 +193,7 @@ const GodotDisplayCursor = {
},
clear: function () {
GodotDisplayCursor.set_style('');
- GodotDisplayCursor.shape = 'auto';
+ GodotDisplayCursor.shape = 'default';
GodotDisplayCursor.visible = true;
Object.keys(GodotDisplayCursor.cursors).forEach(function (key) {
URL.revokeObjectURL(GodotDisplayCursor.cursors[key]);
diff --git a/platform/web/js/libs/library_godot_javascript_singleton.js b/platform/web/js/libs/library_godot_javascript_singleton.js
index 692f27676a..c86cbbae45 100644
--- a/platform/web/js/libs/library_godot_javascript_singleton.js
+++ b/platform/web/js/libs/library_godot_javascript_singleton.js
@@ -88,7 +88,7 @@ const GodotJSWrapper = {
return GodotRuntime.getHeapValue(val, 'double');
case 4:
return GodotRuntime.parseString(GodotRuntime.getHeapValue(val, '*'));
- case 21: // OBJECT
+ case 24: // OBJECT
return GodotJSWrapper.get_proxied_value(GodotRuntime.getHeapValue(val, 'i64'));
default:
return undefined;
@@ -117,7 +117,7 @@ const GodotJSWrapper = {
}
const id = GodotJSWrapper.get_proxied(p_val);
GodotRuntime.setHeapValue(p_exchange, id, 'i64');
- return 21;
+ return 24; // OBJECT
},
},
diff --git a/platform/web/js/libs/library_godot_os.js b/platform/web/js/libs/library_godot_os.js
index 377eec3234..ce64fb98c0 100644
--- a/platform/web/js/libs/library_godot_os.js
+++ b/platform/web/js/libs/library_godot_os.js
@@ -106,12 +106,14 @@ autoAddDeps(GodotConfig, '$GodotConfig');
mergeInto(LibraryManager.library, GodotConfig);
const GodotFS = {
- $GodotFS__deps: ['$ERRNO_CODES', '$FS', '$IDBFS', '$GodotRuntime'],
+ $GodotFS__deps: ['$FS', '$IDBFS', '$GodotRuntime'],
$GodotFS__postset: [
'Module["initFS"] = GodotFS.init;',
'Module["copyToFS"] = GodotFS.copy_to_fs;',
].join(''),
$GodotFS: {
+ // ERRNO_CODES works every odd version of emscripten, but this will break too eventually.
+ ENOENT: 44,
_idbfs: false,
_syncing: false,
_mount_points: [],
@@ -138,8 +140,9 @@ const GodotFS = {
try {
FS.stat(dir);
} catch (e) {
- if (e.errno !== ERRNO_CODES.ENOENT) {
- throw e;
+ if (e.errno !== GodotFS.ENOENT) {
+ // Let mkdirTree throw in case, we cannot trust the above check.
+ GodotRuntime.error(e);
}
FS.mkdirTree(dir);
}
@@ -208,8 +211,9 @@ const GodotFS = {
try {
FS.stat(dir);
} catch (e) {
- if (e.errno !== ERRNO_CODES.ENOENT) {
- throw e;
+ if (e.errno !== GodotFS.ENOENT) {
+ // Let mkdirTree throw in case, we cannot trust the above check.
+ GodotRuntime.error(e);
}
FS.mkdirTree(dir);
}