UNPKG

xgplayer-dash

Version:
47 lines (46 loc) 1.7 kB
import { createClass as _createClass, classCallCheck as _classCallCheck } from "../_virtual/_rollupPluginBabelHelpers.js"; var XHR = /* @__PURE__ */ _createClass(function XHR2() { var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, url = _ref.url, _ref$method = _ref.method, method = _ref$method === void 0 ? "GET" : _ref$method, _ref$type = _ref.type, type = _ref$type === void 0 ? "arraybuffer" : _ref$type, _ref$data = _ref.data, data = _ref$data === void 0 ? {} : _ref$data; _classCallCheck(this, XHR2); return new Promise(function(resolve, reject) { var R = new window.XMLHttpRequest(); var _method = method.toUpperCase(); var _data = []; if (type) { R.responseType = type; } for (var k in data) { if (Object.prototype.hasOwnProperty.call(data, k)) { _data.push("k=".concat(data[k])); } } if (_method === "GET") { R.open(_method, "".concat(url, "?").concat(_data.join("&"))); R.send(); } else if (_method === "post") { if (url.indexOf("data:application/json;base64") === 0) { R.open(_method, url, true); R.timeout = 0; R.withCredentials = false; R.send(_data); } else { R.open(_method, url); R.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); R.send(_data.join("&")); } } else { throw new Error("xhr ".concat(_method, " is not supported")); } R.onload = function() { if (R.status === 200 || R.status === 206) { resolve(R); } else { reject(R); } }; R.onerror = function() { reject(R); }; }); }); export { XHR as default };