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