2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-03-21 12:03:14 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} XHRSettingsObject
|
|
|
|
*
|
2018-05-08 12:30:33 +00:00
|
|
|
* @property {XMLHttpRequestResponseType} responseType - The response type of the XHR request, i.e. `blob`, `text`, etc.
|
|
|
|
* @property {boolean} [async=true] - Should the XHR request use async or not?
|
|
|
|
* @property {string} [user=''] - Optional username for the XHR request.
|
|
|
|
* @property {string} [password=''] - Optional password for the XHR request.
|
|
|
|
* @property {integer} [timeout=0] - Optional XHR timeout value.
|
|
|
|
* @property {(string|undefined)} [header] - This value is used to populate the XHR `setRequestHeader` and is undefined by default.
|
|
|
|
* @property {(string|undefined)} [headerValue] - This value is used to populate the XHR `setRequestHeader` and is undefined by default.
|
|
|
|
* @property {(string|undefined)} [requestedWith] - This value is used to populate the XHR `setRequestHeader` and is undefined by default.
|
|
|
|
* @property {(string|undefined)} [overrideMimeType] - Provide a custom mime-type to use instead of the default.
|
2018-03-21 12:03:14 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-08 17:00:14 +00:00
|
|
|
/**
|
|
|
|
* Creates an XHRSettings Object with default values.
|
|
|
|
*
|
|
|
|
* @function Phaser.Loader.XHRSettings
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-21 12:03:14 +00:00
|
|
|
* @param {XMLHttpRequestResponseType} [responseType=''] - The responseType, such as 'text'.
|
2018-02-08 17:00:14 +00:00
|
|
|
* @param {boolean} [async=true] - Should the XHR request use async or not?
|
2018-03-21 12:03:14 +00:00
|
|
|
* @param {string} [user=''] - Optional username for the XHR request.
|
|
|
|
* @param {string} [password=''] - Optional password for the XHR request.
|
2018-02-08 17:00:14 +00:00
|
|
|
* @param {integer} [timeout=0] - Optional XHR timeout value.
|
|
|
|
*
|
2018-03-21 12:03:14 +00:00
|
|
|
* @return {XHRSettingsObject} The XHRSettings object as used by the Loader.
|
2018-02-08 17:00:14 +00:00
|
|
|
*/
|
2016-11-30 00:18:34 +00:00
|
|
|
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; }
|
|
|
|
|
2018-03-21 12:03:14 +00:00
|
|
|
// Before sending a request, set the xhr.responseType to "text",
|
|
|
|
// "arraybuffer", "blob", or "document", depending on your data needs.
|
2016-11-30 17:16:45 +00:00
|
|
|
// Note, setting xhr.responseType = '' (or omitting) will default the response to "text".
|
2016-11-30 00:18:34 +00:00
|
|
|
|
|
|
|
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,
|
2018-05-04 16:33:48 +00:00
|
|
|
requestedWith: false,
|
2016-11-30 00:18:34 +00:00
|
|
|
|
|
|
|
// overrideMimeType
|
|
|
|
overrideMimeType: undefined
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = XHRSettings;
|