Browse Source

Add Engine.setWebAssemblyFilenameExtension()

Some web game hosts only allow certain filename extensions. If .wasm is
not allowed, this function allows overriding the WebAssembly filename
extension to work around that restriction.
Leon Krause 7 years ago
parent
commit
32eb3e1b7d
1 changed files with 10 additions and 1 deletions
  1. 10 1
      platform/javascript/engine.js

+ 10 - 1
platform/javascript/engine.js

@@ -10,6 +10,7 @@
 	var DOWNLOAD_ATTEMPTS_MAX = 4;
 	var DOWNLOAD_ATTEMPTS_MAX = 4;
 
 
 	var basePath = null;
 	var basePath = null;
+	var wasmFilenameExtensionOverride = null;
 	var engineLoadPromise = null;
 	var engineLoadPromise = null;
 
 
 	var loadingFiles = {};
 	var loadingFiles = {};
@@ -299,6 +300,14 @@
 		return !!testContext;
 		return !!testContext;
 	};
 	};
 
 
+	Engine.setWebAssemblyFilenameExtension = function(override) {
+
+		if (String(override).length === 0) {
+			throw new Error('Invalid WebAssembly filename extension override');
+		}
+		wasmFilenameExtensionOverride = String(override);
+	}
+
 	Engine.load = function(newBasePath) {
 	Engine.load = function(newBasePath) {
 
 
 		if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
 		if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
@@ -306,7 +315,7 @@
 			if (typeof WebAssembly !== 'object')
 			if (typeof WebAssembly !== 'object')
 				return Promise.reject(new Error("Browser doesn't support WebAssembly"));
 				return Promise.reject(new Error("Browser doesn't support WebAssembly"));
 			// TODO cache/retrieve module to/from idb
 			// TODO cache/retrieve module to/from idb
-			engineLoadPromise = loadPromise(basePath + '.wasm').then(function(xhr) {
+			engineLoadPromise = loadPromise(basePath + '.' + (wasmFilenameExtensionOverride || 'wasm')).then(function(xhr) {
 				return xhr.response;
 				return xhr.response;
 			});
 			});
 			engineLoadPromise = engineLoadPromise.catch(function(err) {
 			engineLoadPromise = engineLoadPromise.catch(function(err) {