UNPKG

@kaltura-ng/kaltura-client

Version:
80 lines 3.48 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { CancelableAction } from '../utils/cancelable-action'; import { KalturaHttpClientBase } from './kaltura-http-client-base'; import { KalturaAPIException } from '../kaltura-api-exception'; var KalturaBrowserHttpClient = (function (_super) { __extends(KalturaBrowserHttpClient, _super); function KalturaBrowserHttpClient(config) { return _super.call(this, config) || this; } KalturaBrowserHttpClient.prototype._createCancelableAction = function (data) { var result = new CancelableAction(function (resolve, reject) { var promise = new Promise(function (promiseResolve, promiseReject) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { var resp = void 0; try { if (xhr.status == 200) { resp = JSON.parse(xhr.response); } else { resp = new Error(xhr.responseText); } } catch (e) { resp = new Error(xhr.responseText); } if (resp instanceof Error || resp instanceof KalturaAPIException) { promiseReject({ error: resp }); } else { promiseResolve(resp); } } }; xhr.open('POST', data.endpoint); if (data.headers) { Object.keys(data.headers).forEach(function (headerKey) { var headerValue = data.headers[headerKey]; xhr.setRequestHeader(headerKey, headerValue); }); } xhr.send(JSON.stringify(data.body)); }).then(resolve, reject); }); return result; }; KalturaBrowserHttpClient.prototype.request = function (request) { var _this = this; return new Promise(function (resolve, reject) { _super.prototype._request.call(_this, request).then(function (value) { resolve(value); }, function (reason) { reject(reason); }); }); }; KalturaBrowserHttpClient.prototype.multiRequest = function (arg) { var _this = this; return new Promise(function (resolve, reject) { _super.prototype._multiRequest.call(_this, arg).then(function (value) { resolve(value); }, function (reason) { reject(reason); }); }); }; return KalturaBrowserHttpClient; }(KalturaHttpClientBase)); export { KalturaBrowserHttpClient }; //# sourceMappingURL=kaltura-browser-http-client.js.map