mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Use "await" keyword in interceptHttpRequests()
This commit is contained in:
parent
cdc64da95f
commit
6b12b4add4
@ -9985,16 +9985,15 @@ function interceptHttpRequests() {
|
||||
|
||||
const consoleAddrs = {};
|
||||
|
||||
const patchIceCandidates = function(...arg) {
|
||||
const patchIceCandidates = async (...arg) => {
|
||||
// ICE server candidates
|
||||
const request = arg[0];
|
||||
const url = (typeof request === 'string') ? request : request.url;
|
||||
|
||||
if (url && url.endsWith('/ice') && url.includes('/sessions/') && request.method === 'GET') {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
const text = await response.clone().text();
|
||||
|
||||
return promise.then(response => {
|
||||
return response.clone().text().then(text => {
|
||||
if (!text.length) {
|
||||
return response;
|
||||
}
|
||||
@ -10013,8 +10012,6 @@ function interceptHttpRequests() {
|
||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -10080,10 +10077,9 @@ function interceptHttpRequests() {
|
||||
|
||||
// Get console IP
|
||||
if (url.includes('/configuration')) {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
|
||||
return promise.then(response => {
|
||||
return response.clone().json().then(obj => {
|
||||
const obj = await response.clone().json()
|
||||
console.log(obj);
|
||||
|
||||
const serverDetails = obj.serverDetails;
|
||||
@ -10099,13 +10095,10 @@ function interceptHttpRequests() {
|
||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
} else if (PREF_STREAM_TOUCH_CONTROLLER === 'all' && url.includes('inputconfigs')) {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
const obj = await response.clone().json();
|
||||
|
||||
return promise.then(response => {
|
||||
return response.clone().json().then(obj => {
|
||||
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
|
||||
GAME_XBOX_TITLE_ID = xboxTitleId;
|
||||
|
||||
@ -10132,11 +10125,9 @@ function interceptHttpRequests() {
|
||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return patchIceCandidates(...arg) || NATIVE_FETCH(...arg);
|
||||
return await patchIceCandidates(...arg) || NATIVE_FETCH(...arg);
|
||||
}
|
||||
|
||||
if (IS_REMOTE_PLAYING && url.includes('xhome') && url.includes('/login/user')) {
|
||||
@ -10184,17 +10175,16 @@ function interceptHttpRequests() {
|
||||
}
|
||||
|
||||
// ICE server candidates
|
||||
const patchedIpv6 = patchIceCandidates(...arg);
|
||||
const patchedIpv6 = await patchIceCandidates(...arg);
|
||||
if (patchedIpv6) {
|
||||
return patchedIpv6;
|
||||
}
|
||||
|
||||
// Server list
|
||||
if (!url.includes('xhome.') && url.endsWith('/v2/login/user')) {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
const obj = await response.clone().json();
|
||||
|
||||
return promise.then(response => {
|
||||
return response.clone().json().then(obj => {
|
||||
// Preload Remote Play
|
||||
BX_FLAGS.PreloadRemotePlay && RemotePlay.preload();
|
||||
|
||||
@ -10225,8 +10215,6 @@ function interceptHttpRequests() {
|
||||
|
||||
response.json = () => Promise.resolve(obj);
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Get region
|
||||
@ -10271,22 +10259,18 @@ function interceptHttpRequests() {
|
||||
|
||||
// Get wait time
|
||||
if (PREF_UI_LOADING_SCREEN_WAIT_TIME && url.includes('xboxlive.com') && url.includes('/waittime/')) {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
return promise.then(response => {
|
||||
return response.clone().json().then(json => {
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
|
||||
const json = await response.clone.json();
|
||||
if (json.estimatedAllocationTimeInSeconds > 0) {
|
||||
// Setup wait time overlay
|
||||
LoadingScreen.setupWaitTime(json.estimatedTotalWaitTimeInSeconds);
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (url.endsWith('/configuration') && url.includes('/sessions/cloud/') && request.method === 'GET') {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
|
||||
// Touch controller for all games
|
||||
if (PREF_STREAM_TOUCH_CONTROLLER === 'all') {
|
||||
TouchController.disable();
|
||||
@ -10301,8 +10285,8 @@ function interceptHttpRequests() {
|
||||
}
|
||||
|
||||
// Intercept configurations
|
||||
return promise.then(response => {
|
||||
return response.clone().text().then(text => {
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
const text = await response.clone().text();
|
||||
if (!text.length) {
|
||||
return response;
|
||||
}
|
||||
@ -10334,35 +10318,28 @@ function interceptHttpRequests() {
|
||||
response.text = () => Promise.resolve(JSON.stringify(obj));
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// catalog.gamepass
|
||||
if (url.startsWith('https://catalog.gamepass.com') && url.includes('/products')) {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
return promise.then(response => {
|
||||
return response.clone().json().then(json => {
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
const json = await response.clone().json()
|
||||
|
||||
for (let productId in json.Products) {
|
||||
TitlesInfo.saveFromCatalogInfo(json.Products[productId]);
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (PREF_STREAM_TOUCH_CONTROLLER === 'all' && (url.includes('/titles') || url.includes('/mru'))) {
|
||||
const promise = NATIVE_FETCH(...arg);
|
||||
return promise.then(response => {
|
||||
return response.clone().json().then(json => {
|
||||
const response = await NATIVE_FETCH(...arg);
|
||||
const json = await response.clone().json()
|
||||
for (let game of json.results) {
|
||||
TitlesInfo.saveFromTitleInfo(game);
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return NATIVE_FETCH(...arg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user