diff --git a/v3/src/loader/Loader.js b/v3/src/loader/Loader.js new file mode 100644 index 000000000..0ccdd2c9c --- /dev/null +++ b/v3/src/loader/Loader.js @@ -0,0 +1,41 @@ +var Set = require('../structs/Set'); +var XHRSettings = require('./XHRSettings'); + +var Loader = function () +{ + // Move to a 'setURL' method + this.baseURL = ''; + this.path = ''; + + this.tag = ''; + + this.enableParallel = true; + + this.maxParallelDownloads = 4; + + // xhr specific global settings (can be overridden on a per-file basis) + this.xhr = XHRSettings(); + + this.crossOrigin = undefined; + + this.list = new Set(); + this.inflight = new Set(); + this.failed = new Set(); + this.queue = new Set(); + this.storage = new Set(); + + this._state = 'PENDING'; +}; + +Loader.prototype.contructor = Loader; + +Loader.prototype = { + + add: function () + { + + } + +}; + +module.exports = Loader; diff --git a/v3/src/loader/MergeXHRSettings.js b/v3/src/loader/MergeXHRSettings.js new file mode 100644 index 000000000..32f642748 --- /dev/null +++ b/v3/src/loader/MergeXHRSettings.js @@ -0,0 +1,27 @@ +var XHRSettings = require('./XHRSettings'); + +// Takes two XHR Objects and creates a new object + +// The new object is based on global initially, but any setting in +// local overrides the global value. + +var MergeXHRSettings = function (global, local) +{ + var output = (global === undefined) ? XHRSettings() : Object.assign(global); + + if (local) + { + for (var setting in local) + { + if (local[setting] !== undefined) + { + output[setting] = local[setting]; + } + } + } + + return output; + +}; + +module.exports = MergeXHRSettings; diff --git a/v3/src/loader/XHRLoader.js b/v3/src/loader/XHRLoader.js new file mode 100644 index 000000000..d02ca43fd --- /dev/null +++ b/v3/src/loader/XHRLoader.js @@ -0,0 +1,34 @@ +var MergeXHRSettings = require('./MergeXHRSettings'); + +var XHRLoader = function (file, globalXHRSettings) +{ + var config = MergeXHRSettings(globalXHRSettings, file.xhr); + + var xhr = new XMLHttpRequest(); + + xhr.open('GET', file.src, config.async, config.user, config.password); + + xhr.responseType = file.xhr.responseType; + xhr.timeout = config.timeout; + + if (config.header && config.headerValue) + { + xhr.setRequestHeader(config.header, config.headerValue); + } + + if (config.overrideMimeType) + { + xhr.overrideMimeType(config.overrideMimeType); + } + + // After a successful request, the xhr.response property will contain the requested data as a DOMString, ArrayBuffer, Blob, or Document (depending on what was set for responseType.) + + xhr.onload = file.onLoad(xhr); + xhr.onerror = file.onError(xhr); + + xhr.send(); + + return xhr; +}; + +module.exports = XHRLoader; diff --git a/v3/src/loader/XHRSettings.js b/v3/src/loader/XHRSettings.js new file mode 100644 index 000000000..1e3f83f3b --- /dev/null +++ b/v3/src/loader/XHRSettings.js @@ -0,0 +1,38 @@ +// Creates an XHRSettings Object with default values + +var XHRSettings = function (responseType, async, user, password, timeout) +{ + if (responseType === undefined) { responseType = ''; } + if (async === undefined) { async = true; } + if (user === undefined) { user = ''; } + if (password === undefined) { password = ''; } + if (timeout === undefined) { timeout = 0; } + + // Before sending a request, set the xhr.responseType to "text", "arraybuffer", "blob", or "document", depending on your data needs. Note, setting xhr.responseType = '' (or omitting) will default the response to "text". + + return { + + // Ignored by the Loader, only used by File. + responseType: responseType, + + async: async, + + // credentials + user: user, + password: password, + + // timeout in ms (0 = no timeout) + timeout: timeout, + + // setRequestHeader + header: undefined, + headerValue: undefined, + + // overrideMimeType + overrideMimeType: undefined + + }; + +}; + +module.exports = XHRSettings; diff --git a/v3/src/loader/filetypes/Image.js b/v3/src/loader/filetypes/Image.js new file mode 100644 index 000000000..e69de29bb