phaser/src/loader/XHRSettings.js

65 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2022-02-28 14:29:51 +00:00
* @copyright 2022 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +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'.
* @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.
2020-11-23 10:22:13 +00:00
* @param {number} [timeout=0] - Optional XHR timeout value.
* @param {boolean} [withCredentials=false] - Optional XHR withCredentials value.
*
2019-05-09 11:04:54 +00:00
* @return {Phaser.Types.Loader.XHRSettingsObject} The XHRSettings object as used by the Loader.
*/
var XHRSettings = function (responseType, async, user, password, timeout, withCredentials)
2016-11-30 00:18:34 +00:00
{
if (responseType === undefined) { responseType = ''; }
if (async === undefined) { async = true; }
if (user === undefined) { user = ''; }
if (password === undefined) { password = ''; }
if (timeout === undefined) { timeout = 0; }
if (withCredentials === undefined) { withCredentials = false; }
2016-11-30 00:18:34 +00:00
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.
// 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
2019-06-25 23:29:24 +00:00
headers: undefined,
2016-11-30 00:18:34 +00:00
header: undefined,
headerValue: undefined,
requestedWith: false,
2016-11-30 00:18:34 +00:00
// overrideMimeType
overrideMimeType: undefined,
// withCredentials
withCredentials: withCredentials
2016-11-30 00:18:34 +00:00
};
};
module.exports = XHRSettings;