313 lines
7.8 KiB
TypeScript
313 lines
7.8 KiB
TypeScript
// Metro module 10943 (f10944).
|
|
import SpotifyProtocolStore from "./SpotifyProtocolStore";
|
|
import { SpotifyEndpoints, SPOTIFY_APP_PROTOCOL } from "./SpotifyConstants";
|
|
import { Endpoints, PlatformTypes } from "../../Constants";
|
|
import { HTTP } from "../../_bundle/sendRequest";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { isDesktop } from "../../utils/PlatformUtils";
|
|
import GameUtils_native from "../../utils/GameUtils.native";
|
|
function $mk85947() {
|
|
return (a0) => a0.status === 202 ? Promise.reject(a0) : a0;
|
|
}
|
|
function $mk85948($env) {
|
|
return (a0) => {
|
|
let r7, r17;
|
|
const r4 = $env;
|
|
const r9 = r4[2].onlyRetryOnAuthorizationErrors !== true && a0.status === 202;
|
|
if (!(a0.status !== 401 && !r9) && r4[3] > 0) {
|
|
if (a0.status === 202) {
|
|
const r23 = $env.$parent;
|
|
r7 = (0, r23[0])(r23[2][3]).timeoutPromise(5000);
|
|
} else {
|
|
r7 = Promise.resolve();
|
|
}
|
|
r17 = r7.then($mk107590(r4)).then($mk107591(r4)).then((c30308_0) => new Promise((c31601_0) => setImmediate(() => c31601_0(c30308_0))));
|
|
} else {
|
|
r17 = Promise.reject(a0);
|
|
}
|
|
return r17;
|
|
};
|
|
}
|
|
function $mk85949($env) {
|
|
return (a0) => {
|
|
const code = a0.body?.code;
|
|
const r8 = $env;
|
|
const r12 = $env.$parent;
|
|
if (code === r12[6].CONNECTION_REVOKED) {
|
|
(0, r12[1])(r12[2][5]).dispatch({
|
|
type: "SPOTIFY_ACCOUNT_ACCESS_TOKEN_REVOKE",
|
|
accountId: r8[0]
|
|
});
|
|
} else if (a0.status === 429) {
|
|
const r9 = a0.headers["retry-after"];
|
|
const r10 = r12[1];
|
|
const r16 = r12[2];
|
|
const r21 = r9 * r10(r16[6]).Millis.SECOND;
|
|
const r25 = isNaN(r21) ? 5000 : r21 !== 0 ? r21 : 5000;
|
|
return (0, r12[0])(r16[3]).timeoutPromise(r25).then($mk107593(r8));
|
|
}
|
|
return Promise.reject(a0);
|
|
};
|
|
}
|
|
function $mk85950($env) {
|
|
return (a0) => {
|
|
const access_token = a0.body.access_token;
|
|
const r7 = $env.$parent;
|
|
(0, r7[1])(r7[2][5]).dispatch({
|
|
type: "SPOTIFY_ACCOUNT_ACCESS_TOKEN",
|
|
accountId: $env[0],
|
|
accessToken: access_token
|
|
});
|
|
return a0;
|
|
};
|
|
}
|
|
function $mk85951($env) {
|
|
return (a0) => {
|
|
let r15;
|
|
const r2 = $env;
|
|
if (r2[3] <= 0) {
|
|
r15 = Promise.reject(a0);
|
|
} else {
|
|
const r6 = $env.$parent;
|
|
r15 = (0, r6[0])(r6[2][3]).timeoutPromise(5000).then($mk107594(r2));
|
|
}
|
|
return r15;
|
|
};
|
|
}
|
|
function $mk107590($env) {
|
|
return () => {
|
|
let env30306;
|
|
const r5 = $env.$parent;
|
|
const r8 = $env[1];
|
|
const r9 = env30306 = {
|
|
$parent: r5
|
|
};
|
|
env30306[0] = r8;
|
|
return (0, r5[0])(r5[2][4]).HTTP.get({
|
|
url: r5[7].CONNECTION_ACCESS_TOKEN(r5[8].SPOTIFY, r8),
|
|
oldFormErrors: true,
|
|
rejectWithError: false
|
|
}).catch($mk85949(r9)).then($mk85950(r9));
|
|
};
|
|
}
|
|
function $mk107591($env) {
|
|
return (a0) => {
|
|
let env30307;
|
|
const r2 = $env;
|
|
const access_token = a0.body.access_token;
|
|
const r4 = r2[0];
|
|
const r12 = r2[1];
|
|
const r5 = r2[2];
|
|
const r14 = r2[3] - 1;
|
|
const r16 = env30307 = {
|
|
$parent: $env.$parent
|
|
};
|
|
env30307[0] = r4;
|
|
env30307[1] = r12;
|
|
env30307[2] = r5;
|
|
env30307[3] = r14;
|
|
const r17 = {
|
|
...r5,
|
|
headers: {
|
|
authorization: `Bearer ${access_token}`
|
|
}
|
|
};
|
|
env30307[2] = r17;
|
|
return r4(r17).then($mk85947()).catch($mk85948(r16));
|
|
};
|
|
}
|
|
function $mk107593($env) {
|
|
return () => {
|
|
let env30309;
|
|
const r5 = $env.$parent;
|
|
const r8 = $env[0];
|
|
const r9 = env30309 = {
|
|
$parent: r5
|
|
};
|
|
env30309[0] = r8;
|
|
return (0, r5[0])(r5[2][4]).HTTP.get({
|
|
url: r5[7].CONNECTION_ACCESS_TOKEN(r5[8].SPOTIFY, r8),
|
|
oldFormErrors: true,
|
|
rejectWithError: false
|
|
}).catch($mk85949(r9)).then($mk85950(r9));
|
|
};
|
|
}
|
|
function $mk107594($env) {
|
|
return () => {
|
|
let env30310;
|
|
const r1 = $env;
|
|
const r7 = $env.$parent;
|
|
const r6 = r1[0];
|
|
const r5 = r1[1];
|
|
const connection_id = r1[2];
|
|
const r10 = r1[3] - 1;
|
|
const r11 = env30310 = {
|
|
$parent: r7
|
|
};
|
|
env30310[0] = r6;
|
|
env30310[1] = r5;
|
|
env30310[2] = connection_id;
|
|
env30310[3] = r10;
|
|
return r7[9].put(r6, r5, {
|
|
url: r7[5].NOTIFICATIONS_PLAYER,
|
|
query: {
|
|
connection_id
|
|
}
|
|
}).catch($mk85951(r11));
|
|
};
|
|
}
|
|
let c7370_9;
|
|
let env7370 = {};
|
|
const apiRequest = function apiRequest(a0, a1, a2, a3) {
|
|
let env18385;
|
|
const r2 = env18385 = {
|
|
$parent: env7370
|
|
};
|
|
env18385[0] = a0;
|
|
env18385[1] = a1;
|
|
env18385[2] = a3;
|
|
let r11 = arguments[4];
|
|
if (r11 === void 0) {
|
|
r11 = 1;
|
|
}
|
|
env18385[3] = r11;
|
|
const r12 = {
|
|
...a3,
|
|
headers: {
|
|
authorization: `Bearer ${a2}`
|
|
}
|
|
};
|
|
env18385[2] = r12;
|
|
return a0(r12).then($mk85947()).catch($mk85948(r2));
|
|
};
|
|
c7370_9 = {
|
|
get: apiRequest.bind(null, HTTP.get),
|
|
put: apiRequest.bind(null, HTTP.put)
|
|
};
|
|
export { c7370_9 as SpotifyAPI };
|
|
export function getAccessToken(a0) {
|
|
let env18386;
|
|
const r1 = env18386 = {
|
|
$parent: env7370
|
|
};
|
|
env18386[0] = a0;
|
|
return HTTP.get({
|
|
url: Endpoints.CONNECTION_ACCESS_TOKEN(PlatformTypes.SPOTIFY, a0),
|
|
oldFormErrors: true,
|
|
rejectWithError: false
|
|
}).catch($mk85949(r1)).then($mk85950(r1));
|
|
}
|
|
export function subscribePlayerStateNotifications(a0, a1, a2) {
|
|
let env18387;
|
|
const r2 = env18387 = {
|
|
$parent: env7370
|
|
};
|
|
env18387[0] = a0;
|
|
env18387[1] = a1;
|
|
env18387[2] = a2;
|
|
let r3 = arguments[3];
|
|
if (r3 === void 0) {
|
|
r3 = 2;
|
|
}
|
|
env18387[3] = r3;
|
|
return c7370_9.put(a0, a1, {
|
|
url: SpotifyEndpoints.NOTIFICATIONS_PLAYER,
|
|
query: {
|
|
connection_id: a2
|
|
}
|
|
}).catch($mk85951(r2));
|
|
}
|
|
export function getProfile(a0, a1) {
|
|
const accountId = a0;
|
|
return c7370_9.get(a0, a1, {
|
|
url: SpotifyEndpoints.PROFILE
|
|
}).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "SPOTIFY_PROFILE_UPDATE",
|
|
accountId,
|
|
isPremium: result.body.product === "premium"
|
|
});
|
|
return result;
|
|
});
|
|
}
|
|
export function getDevices(a0, a1) {
|
|
const accountId2 = a0;
|
|
return c7370_9.get(a0, a1, {
|
|
url: SpotifyEndpoints.PLAYER_DEVICES
|
|
}).then((result) => {
|
|
if (result.body) {
|
|
Dispatcher.dispatch({
|
|
type: "SPOTIFY_SET_DEVICES",
|
|
accountId: accountId2,
|
|
devices: result.body.devices
|
|
});
|
|
}
|
|
return result;
|
|
});
|
|
}
|
|
export function play(a0, a1, a2, a3) {
|
|
const id = a2;
|
|
let r4 = arguments[4];
|
|
if (r4 === void 0) {
|
|
r4 = {};
|
|
}
|
|
const uri = SpotifyEndpoints.PLAYER_OPEN(a3, a2, false);
|
|
const { deviceId, position, contextUri, repeat } = r4;
|
|
return c7370_9.put(a0, a1, {
|
|
url: SpotifyEndpoints.PLAYER_PLAY,
|
|
query: {
|
|
device_id: deviceId
|
|
},
|
|
body: {
|
|
context_uri: contextUri ?? void 0,
|
|
uris: contextUri == null ? [uri] : void 0,
|
|
offset: contextUri != null ? {
|
|
uri
|
|
} : void 0,
|
|
position_ms: position != null ? position : 0
|
|
}
|
|
}).then((result) => repeat != null ? c7370_9.put(a0, a1, {
|
|
url: SpotifyEndpoints.PLAYER_REPEAT,
|
|
query: {
|
|
device_id: deviceId,
|
|
state: repeat ? "context" : "off"
|
|
}
|
|
}) : result).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "SPOTIFY_PLAYER_PLAY",
|
|
id,
|
|
position: position != null ? position : 0
|
|
});
|
|
return result;
|
|
});
|
|
}
|
|
export function pause(a0, a1) {
|
|
return c7370_9.put(a0, a1, {
|
|
url: SpotifyEndpoints.PLAYER_PAUSE
|
|
}).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "SPOTIFY_PLAYER_PAUSE"
|
|
});
|
|
return result;
|
|
});
|
|
}
|
|
export function fetchIsSpotifyProtocolRegistered() {
|
|
if (!SpotifyProtocolStore.isProtocolRegistered()) {
|
|
if (isDesktop()) {
|
|
GameUtils_native.isProtocolRegistered(SPOTIFY_APP_PROTOCOL).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "SPOTIFY_SET_PROTOCOL_REGISTERED",
|
|
isRegistered: result
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
export function setActiveDevice(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "SPOTIFY_SET_ACTIVE_DEVICE",
|
|
accountId: a0,
|
|
deviceId: a1
|
|
});
|
|
}
|