UNPKG

@sendbird/chat

Version:
2 lines (1 loc) 1.46 kB
import{V as e,t,g as s,Z as r,by as a,aF as n,bz as o,aD as d}from"./__bundle-d4c97ab8.js";var i=function(i,u){return new Promise((function(c,p){if("undefined"!=typeof XMLHttpRequest){var f=e.of(i),l=f.dispatcher,g=f.logger,h=u.requestId,m=u.method,q=u.url,v=u.headers,w=void 0===v?{}:v,b=u.data,E=void 0===b?"":b,y=u.uploadProgressHandler,H=!1,S=new XMLHttpRequest;S.open(m,q),Object.keys(w).forEach((function(e){S.setRequestHeader(e,w[e])})),y&&S.upload.addEventListener("progress",(function(e){e.lengthComputable?y(h,e.loaded,e.total):g.debug("Progress computing failed: `Content-Length` header is not given.")})),S.onabort=function(){p(t.requestCanceled)},S.onerror=function(e){p(t.networkError)},S.onreadystatechange=function(){if(S.readyState===XMLHttpRequest.DONE&&!H)if(0===S.status||S.status>=200&&S.status<400)try{var e=JSON.parse(S.responseText);c(new s(i,e))}catch(u){p(t.networkError)}else try{var d=JSON.parse(S.responseText);if(d){var u=new t(d);if(u.isSessionExpiredError){if(l.dispatch(new r({reason:u.code,message:u.message})),!(S instanceof a)){var f=new n;return l.dispatch(new o({request:S,deferred:f,error:u})),f.promise}}else u.isSessionInvalidatedError&&l.dispatch(new r({reason:u.code,message:u.message}));p(u)}else p(t.requestFailed)}catch(u){p(t.requestFailed)}},l.on((function(e){e instanceof d&&(e.requestId&&e.requestId!==h||(H=!0,S.abort()))})),S.send(E)}else p(t.xmlHttpRequestNotSupported)}))};export{i as xmlHttpRequest};