aboutsummaryrefslogtreecommitdiff
path: root/webAO/client.js
diff options
context:
space:
mode:
authorcaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-13 01:29:10 -0500
committercaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-13 01:29:10 -0500
commitaf6b6a6d5cbf669024d88146ca5913a0676e4368 (patch)
tree0a270f657e0f6c2018e5ebfbbc59d4631c717116 /webAO/client.js
parent39da04dc796b635b43879d285bc9d2c2aabc8761 (diff)
Resolve too many network calls
Diffstat (limited to 'webAO/client.js')
-rw-r--r--webAO/client.js25
1 files changed, 15 insertions, 10 deletions
diff --git a/webAO/client.js b/webAO/client.js
index e07c7e9..36e2555 100644
--- a/webAO/client.js
+++ b/webAO/client.js
@@ -778,29 +778,28 @@ class Client extends EventEmitter {
* @param {Number} charid character ID
*/
async handleCharacterInfo(chargs, charid) {
+
if (chargs[0]) {
let cini = {};
+ const img = document.getElementById(`demo_${charid}`);
const getCharIcon = async () => {
const extensions = [
'.png',
'.webp',
];
+ img.alt = chargs[0]
const charIconBaseUrl = `${AO_HOST}characters/${encodeURI(chargs[0].toLowerCase())}/char_icon`;
for (let i = 0; i < extensions.length; i++) {
const fileUrl = charIconBaseUrl + extensions[i];
const exists = await fileExists(fileUrl);
if (exists) {
- return fileUrl;
+ img.alt = chargs[0];
+ img.src = fileUrl;
+ return
}
}
- return transparentPNG;
};
-
- const charIconUrlResponse = await getCharIcon();
- const icon = charIconUrlResponse || transparentPNG;
- const img = document.getElementById(`demo_${charid}`);
- img.alt = chargs[0];
- img.src = icon; // seems like a good time to load the icon
+ await getCharIcon();
// If the ini doesn't exist on the server this will throw an error
try {
@@ -844,7 +843,7 @@ class Client extends EventEmitter {
side: safeTags(cini.options.side).toLowerCase(),
chat: (cini.options.chat === '') ? safeTags(cini.options.chat).toLowerCase() : safeTags(cini.options.category).toLowerCase(),
evidence: chargs[3],
- icon,
+ icon: img.src,
inifile: cini,
muted: false,
};
@@ -887,12 +886,18 @@ class Client extends EventEmitter {
* @param {Array} args packet arguments
*/
async handleSC(args) {
+ const sleep = ms => new Promise(r => setTimeout(r, ms));
+
+ // Add this so people can see characters loading on the screen.
+ document.getElementById('client_loading').style.display = 'none';
+ document.getElementById('client_charselect').style.display = 'block';
+
document.getElementById('client_loadingtext').innerHTML = 'Loading Characters';
for (let i = 1; i < args.length; i++) {
document.getElementById('client_loadingtext').innerHTML = `Loading Character ${i}/${this.char_list_length}`;
const chargs = args[i].split('&');
const charid = i - 1;
-
+ await sleep(.1) // TODO: Too many network calls without this. net::ERR_INSUFFICIENT_RESOURCES
this.handleCharacterInfo(chargs, charid);
}
// We're done with the characters, request the music