Build 533169stable
Module 107750
2,751 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{E$:()=>g,VR:()=>y,ZH:()=>I,f0:()=>S,iD:()=>m,oG:()=>A,tB:()=>h,tO:()=>E,v7:()=>T}),n(142703);var r=n(562465),i=n(451988),s=n(73153),a=n(927813),o=n(25171),l=n(723702),u=n(210528),c=n(272984),d=n(652215);let _=5e3,f=5e3;function p(e,t,n,r){let s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1;return e(r={...r,headers:{authorization:`Bearer ${n}`}}).then(e=>202===e.status?Promise.reject(e):e).catch(n=>{let a=!0!==r.onlyRetryOnAuthorizationErrors&&202===n.status;return(401===n.status||a)&&s>0?(202===n.status?(0,i.BK)(_):Promise.resolve()).then(()=>m(t)).then(n=>{let{body:{access_token:i}}=n;return p(e,t,i,r,s-1)}).then(e=>new Promise(t=>setImmediate(()=>t(e)))):Promise.reject(n)})}let h={get:p.bind(null,r.Bo.get),put:p.bind(null,r.Bo.put)};function m(e){return r.Bo.get({url:d.Rsh.CONNECTION_ACCESS_TOKEN(d.fg2.SPOTIFY,e),oldFormErrors:!0,rejectWithError:!1}).catch(t=>{if(t.body?.code===d.t02.CONNECTION_REVOKED)s.h.dispatch({type:"SPOTIFY_ACCOUNT_ACCESS_TOKEN_REVOKE",accountId:e});else if(429===t.status){let n=t.headers["retry-after"]*a.A.Millis.SECOND,r=isNaN(n)||0===n?f:n;return(0,i.BK)(r).then(()=>m(e))}return Promise.reject(t)}).then(t=>{let{access_token:n}=t.body;return s.h.dispatch({type:"SPOTIFY_ACCOUNT_ACCESS_TOKEN",accountId:e,accessToken:n}),t})}function E(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2;return h.put(e,t,{url:c.RQ.NOTIFICATIONS_PLAYER,query:{connection_id:n}}).catch(s=>r<=0?Promise.reject(s):(0,i.BK)(_).then(()=>E(e,t,n,r-1)))}function g(e,t){return h.get(e,t,{url:c.RQ.PROFILE}).then(t=>(s.h.dispatch({type:"SPOTIFY_PROFILE_UPDATE",accountId:e,isPremium:"premium"===t.body.product}),t))}function A(e,t){return h.get(e,t,{url:c.RQ.PLAYER_DEVICES}).then(t=>(t.body&&s.h.dispatch({type:"SPOTIFY_SET_DEVICES",accountId:e,devices:t.body.devices}),t))}function I(e,t,n,r){let i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},a=c.RQ.PLAYER_OPEN(r,n,!1),{deviceId:o,position:l,contextUri:u,repeat:d}=i;return h.put(e,t,{url:c.RQ.PLAYER_PLAY,query:{device_id:o},body:{context_uri:null!=u?u:void 0,uris:null==u?[a]:void 0,offset:null!=u?{uri:a}:void 0,position_ms:null!=l?l:0}}).then(n=>null==d?n:h.put(e,t,{url:c.RQ.PLAYER_REPEAT,query:{device_id:o,state:d?"context":"off"}})).then(e=>(s.h.dispatch({type:"SPOTIFY_PLAYER_PLAY",id:n,position:null!=l?l:0}),e))}function T(e,t){return h.put(e,t,{url:c.RQ.PLAYER_PAUSE}).then(e=>(s.h.dispatch({type:"SPOTIFY_PLAYER_PAUSE"}),e))}function S(){!u.A.isProtocolRegistered()&&(0,l.isDesktop)()&&o.A.isProtocolRegistered(c.gY).then(e=>{s.h.dispatch({type:"SPOTIFY_SET_PROTOCOL_REGISTERED",isRegistered:e})})}function y(e,t){s.h.dispatch({type:"SPOTIFY_SET_ACTIVE_DEVICE",accountId:e,deviceId:t})}}