aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--webAO/client.js92
-rw-r--r--webAO/master.js26
-rw-r--r--webAO/services/request.js54
-rw-r--r--webAO/utils/calculateGifLength.js32
-rw-r--r--webAO/utils/calculateWebpLength.js12
-rw-r--r--webAO/utils/calculatorHandler.js10
-rw-r--r--webAO/utils/getCookie.js32
-rw-r--r--webAO/utils/setCookie.js8
8 files changed, 129 insertions, 137 deletions
diff --git a/webAO/client.js b/webAO/client.js
index 1d04349..b6a4c38 100644
--- a/webAO/client.js
+++ b/webAO/client.js
@@ -4,7 +4,7 @@
* credits to aleks for original idea and source
*/
-import FingerprintJS from '@fingerprintjs/fingerprintjs'
+import FingerprintJS from '@fingerprintjs/fingerprintjs';
import { EventEmitter } from 'events';
import {
@@ -12,10 +12,10 @@ import {
} from './encoding.js';
// Load some defaults for the background and evidence dropdowns
-import vanilla_character_arr from "./constants/characters.js";
-import vanilla_music_arr from "./constants/music.js";
-import vanilla_background_arr from "./constants/backgrounds.js";
-import vanilla_evidence_arr from "./constants/evidence.js";
+import vanilla_character_arr from './constants/characters.js';
+import vanilla_music_arr from './constants/music.js';
+import vanilla_background_arr from './constants/backgrounds.js';
+import vanilla_evidence_arr from './constants/evidence.js';
import chatbox_arr from './styles/chatbox/chatboxes.js';
import iniParse from './iniParse';
@@ -60,24 +60,22 @@ let extrafeatures = [];
let hdid;
-
function isLowMemory() {
if (/webOS|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|PlayStation|Nintendo|Opera Mini/i.test(navigator.userAgent)) {
oldLoading = true;
}
}
-const fpPromise = FingerprintJS.load()
+const fpPromise = FingerprintJS.load();
fpPromise
- .then(fp => fp.get())
- .then(result => {
-
- hdid = result.visitorId;
- client = new Client(serverIP);
- viewport = new Viewport();
-
- isLowMemory();
- client.loadResources();
-});
+ .then((fp) => fp.get())
+ .then((result) => {
+ hdid = result.visitorId;
+ client = new Client(serverIP);
+ viewport = new Viewport();
+
+ isLowMemory();
+ client.loadResources();
+ });
let lastICMessageTime = new Date(0);
@@ -1033,8 +1031,8 @@ class Client extends EventEmitter {
}
isAudio(trackname) {
- const audioEndings = ['.wav', '.mp3', '.ogg', '.opus']
- return audioEndings.filter(ending => trackname.endsWith(ending)).length === 1
+ const audioEndings = ['.wav', '.mp3', '.ogg', '.opus'];
+ return audioEndings.filter((ending) => trackname.endsWith(ending)).length === 1;
}
addTrack(trackname) {
@@ -1871,7 +1869,7 @@ class Viewport {
}
if ('def,pro,wit'.includes(position)) {
- document.getElementById('client_'+position+'_bench').style.display = 'none';
+ document.getElementById(`client_${position}_bench`).style.display = 'none';
view.style.display = '';
document.getElementById('client_classicview').style.display = 'none';
switch (position) {
@@ -1925,19 +1923,19 @@ class Viewport {
* silently fail and return 0 instead.
* @param {string} filename the animation file name
*/
-
+
async getAnimLength(url) {
- const extensions = ['.gif','.webp']
+ const extensions = ['.gif', '.webp'];
for (const extension of extensions) {
- const urlWithExtension = url+extension
- const exists = await fileExists(urlWithExtension)
+ const urlWithExtension = url + extension;
+ const exists = await fileExists(urlWithExtension);
if (exists) {
- const fileBuffer = await requestBuffer(urlWithExtension)
- const length = calculatorHandler[extension](fileBuffer)
- return length
+ const fileBuffer = await requestBuffer(urlWithExtension);
+ const length = calculatorHandler[extension](fileBuffer);
+ return length;
}
- };
- return 0
+ }
+ return 0;
}
oneSuccess(promises) {
@@ -2042,26 +2040,26 @@ class Viewport {
const apng_s = document.getElementById(`client_${position}${pairID}_apng`);
const webp_s = document.getElementById(`client_${position}${pairID}_webp`);
const extensionsMap = {
- '.gif': gif_s,
- '.png': png_s,
- '.apng': apng_s,
- '.webp': webp_s
- }
+ '.gif': gif_s,
+ '.png': png_s,
+ '.apng': apng_s,
+ '.webp': webp_s,
+ };
for (const [extension, htmlElement] of Object.entries(extensionsMap)) {
// Hides all sprites before creating a new sprite
if (this.lastChar !== this.chatmsg.name) {
- htmlElement.src = transparentPNG
+ htmlElement.src = transparentPNG;
}
let url;
if (extension === '.png') {
- url = `${characterFolder}${encodeURI(charactername)}/${encodeURI(emotename)}${extension}`
+ url = `${characterFolder}${encodeURI(charactername)}/${encodeURI(emotename)}${extension}`;
} else {
- url = `${characterFolder}${encodeURI(charactername)}/${encodeURI(prefix)}${encodeURI(emotename)}${extension}`
+ url = `${characterFolder}${encodeURI(charactername)}/${encodeURI(prefix)}${encodeURI(emotename)}${extension}`;
}
- const exists = fileExistsSync(url)
+ const exists = fileExistsSync(url);
if (exists) {
- htmlElement.src = url
+ htmlElement.src = url;
return;
}
}
@@ -2280,7 +2278,7 @@ class Viewport {
const effectlayer = document.getElementById('client_fg');
let charLayers = document.getElementById('client_char');
let pairLayers = document.getElementById('client_pair_char');
-
+
if ('def,pro,wit'.includes(this.chatmsg.side)) {
charLayers = document.getElementById(`client_${this.chatmsg.side}_char`);
pairLayers = document.getElementById(`client_${this.chatmsg.side}_pair_char`);
@@ -2411,7 +2409,6 @@ class Viewport {
}
}
-
/**
* Triggered when the Return key is pressed on the out-of-character chat input box.
* @param {KeyboardEvent} event
@@ -2697,7 +2694,7 @@ window.iniedit = iniedit;
export async function switchPanTilt(addcheck) {
const background = document.getElementById('client_fullview');
if (addcheck === 1) {
- document.getElementById('client_pantilt').checked = true;
+ document.getElementById('client_pantilt').checked = true;
document.getElementById('client_court').style.display = '';
} else if (addcheck === 2) {
document.getElementById('client_pantilt').checked = false;
@@ -2824,8 +2821,6 @@ async function requestBuffer(url) {
});
}
-
-
/**
* Checks if a file exists at the specified URI.
* @param {string} url the URI to be checked
@@ -2840,15 +2835,14 @@ async function fileExists(url) {
}
const fileExistsSync = (url) => {
try {
- var http = new XMLHttpRequest();
+ const http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
- return http.status!=404;
+ return http.status != 404;
} catch (e) {
- return false
+ return false;
}
-}
-
+};
/**
* Triggered when the reconnect button is pushed.
diff --git a/webAO/master.js b/webAO/master.js
index d03f0d7..7e4906e 100644
--- a/webAO/master.js
+++ b/webAO/master.js
@@ -1,4 +1,4 @@
-import FingerprintJS from '@fingerprintjs/fingerprintjs'
+import FingerprintJS from '@fingerprintjs/fingerprintjs';
import { unescapeChat, safeTags } from './encoding.js';
@@ -21,22 +21,22 @@ servers[-1] = {
name: 'Localhost', description: 'This is your computer on port 50001', ip: '127.0.0.1', port: 50001, assets: '', online: 'Online: ?/?',
};
-const fpPromise = FingerprintJS.load()
+const fpPromise = FingerprintJS.load();
fpPromise
- .then(fp => fp.get())
- .then(result => {
- hdid = result.visitorId;
+ .then((fp) => fp.get())
+ .then((result) => {
+ hdid = result.visitorId;
- check_https();
+ check_https();
- masterserver = new WebSocket(`ws://${MASTERSERVER_IP}`);
- masterserver.onopen = (evt) => onOpen(evt);
- masterserver.onerror = (evt) => onError(evt);
- masterserver.onmessage = (evt) => onMessage(evt);
+ masterserver = new WebSocket(`ws://${MASTERSERVER_IP}`);
+ masterserver.onopen = (evt) => onOpen(evt);
+ masterserver.onerror = (evt) => onError(evt);
+ masterserver.onmessage = (evt) => onMessage(evt);
- // i don't need the ms to play alone
- setTimeout(() => checkOnline(-1, '127.0.0.1:50001'), 0);
-});
+ // i don't need the ms to play alone
+ setTimeout(() => checkOnline(-1, '127.0.0.1:50001'), 0);
+ });
export function check_https() {
if (document.location.protocol === 'https:') {
diff --git a/webAO/services/request.js b/webAO/services/request.js
index f21f881..6479dcc 100644
--- a/webAO/services/request.js
+++ b/webAO/services/request.js
@@ -4,31 +4,29 @@
* @returns response data
* @throws {Error} if status code is not 2xx, or a network error occurs
*/
- const request = async url => {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.responseType = 'text';
- xhr.addEventListener('error', () => {
- const err = new Error(`Request for ${url} failed: ${xhr.statusText}`);
- err.code = xhr.status;
- reject(err);
- });
- xhr.addEventListener('abort', () => {
- const err = new Error(`Request for ${url} was aborted!`);
- err.code = xhr.status;
- reject(err);
- });
- xhr.addEventListener('load', () => {
- if (xhr.status < 200 || xhr.status >= 300) {
- const err = new Error(`Request for ${url} failed with status code ${xhr.status}`);
- err.code = xhr.status;
- reject(err);
- } else {
- resolve(xhr.response);
- }
- });
- xhr.open('GET', url, true);
- xhr.send();
- });
- }
- export default request \ No newline at end of file
+const request = async (url) => new Promise((resolve, reject) => {
+ const xhr = new XMLHttpRequest();
+ xhr.responseType = 'text';
+ xhr.addEventListener('error', () => {
+ const err = new Error(`Request for ${url} failed: ${xhr.statusText}`);
+ err.code = xhr.status;
+ reject(err);
+ });
+ xhr.addEventListener('abort', () => {
+ const err = new Error(`Request for ${url} was aborted!`);
+ err.code = xhr.status;
+ reject(err);
+ });
+ xhr.addEventListener('load', () => {
+ if (xhr.status < 200 || xhr.status >= 300) {
+ const err = new Error(`Request for ${url} failed with status code ${xhr.status}`);
+ err.code = xhr.status;
+ reject(err);
+ } else {
+ resolve(xhr.response);
+ }
+ });
+ xhr.open('GET', url, true);
+ xhr.send();
+});
+export default request;
diff --git a/webAO/utils/calculateGifLength.js b/webAO/utils/calculateGifLength.js
index a57264d..1df0ba9 100644
--- a/webAO/utils/calculateGifLength.js
+++ b/webAO/utils/calculateGifLength.js
@@ -1,27 +1,27 @@
- /**
+/**
* Adds up the frame delays to find out how long a GIF is
* I totally didn't steal this
* @param {data} gifFile the GIF data
*/
const calculateGifLength = (gifFile) => {
- const d = new Uint8Array(gifFile);
- // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/
- // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt
- let duration = 0;
- for (let i = 0; i < d.length; i++) {
- // Find a Graphic Control Extension hex(21F904__ ____ __00)
- if (d[i] === 0x21
+ const d = new Uint8Array(gifFile);
+ // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/
+ // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt
+ let duration = 0;
+ for (let i = 0; i < d.length; i++) {
+ // Find a Graphic Control Extension hex(21F904__ ____ __00)
+ if (d[i] === 0x21
&& d[i + 1] === 0xF9
&& d[i + 2] === 0x04
&& d[i + 7] === 0x00) {
- // Swap 5th and 6th bytes to get the delay per frame
- const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF);
+ // Swap 5th and 6th bytes to get the delay per frame
+ const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF);
- // Should be aware browsers have a minimum frame delay
- // e.g. 6ms for IE, 2ms modern browsers (50fps)
- duration += delay < 2 ? 10 : delay;
- }
+ // Should be aware browsers have a minimum frame delay
+ // e.g. 6ms for IE, 2ms modern browsers (50fps)
+ duration += delay < 2 ? 10 : delay;
}
- return duration * 10;
}
- export default calculateGifLength \ No newline at end of file
+ return duration * 10;
+};
+export default calculateGifLength;
diff --git a/webAO/utils/calculateWebpLength.js b/webAO/utils/calculateWebpLength.js
index 38da7c1..1b422a0 100644
--- a/webAO/utils/calculateWebpLength.js
+++ b/webAO/utils/calculateWebpLength.js
@@ -1,22 +1,22 @@
const calculateWebpLength = (webpFile) => {
- let d = new Uint8Array(webpFile);
+ const d = new Uint8Array(webpFile);
// https://developers.google.com/speed/webp/docs/riff_container#animation
let duration = 0;
- for (var i = 0; i < d.length; i++) {
+ for (let i = 0; i < d.length; i++) {
// Find ANMF header (41 4E 4D 46)
if (d[i] === 0x41
&& d[i + 1] === 0x4E
&& d[i + 2] === 0x4D
&& d[i + 3] === 0x46) {
// Swap 5th and 6th bytes to get the delay per frame
- let delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF);
+ const delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF);
- // Should be aware browsers have a minimum frame delay
+ // Should be aware browsers have a minimum frame delay
// e.g. 6ms for IE, 2ms modern browsers (50fps)
duration += delay < 2 ? 10 : delay;
}
}
return duration;
-}
+};
-export default calculateWebpLength \ No newline at end of file
+export default calculateWebpLength;
diff --git a/webAO/utils/calculatorHandler.js b/webAO/utils/calculatorHandler.js
index 5ed8a43..7686573 100644
--- a/webAO/utils/calculatorHandler.js
+++ b/webAO/utils/calculatorHandler.js
@@ -1,7 +1,7 @@
-import calculateGifLength from "./calculateGifLength";
-import calculateWebpLength from "./calculateWebpLength";
+import calculateGifLength from './calculateGifLength';
+import calculateWebpLength from './calculateWebpLength';
export default {
- '.gif': calculateGifLength,
- '.webp': calculateWebpLength
-} \ No newline at end of file
+ '.gif': calculateGifLength,
+ '.webp': calculateWebpLength,
+};
diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.js
index 000c870..3be0733 100644
--- a/webAO/utils/getCookie.js
+++ b/webAO/utils/getCookie.js
@@ -5,22 +5,22 @@
* @param {String} cname The name of the cookie to return
*/
const getCookie = (cname) => {
- try {
- const name = `${cname}=`;
- const decodedCookie = decodeURIComponent(document.cookie);
- const ca = decodedCookie.split(';');
- for (let i = 0; i < ca.length; i++) {
- let c = ca[i];
- while (c.charAt(0) === ' ') {
- c = c.substring(1);
- }
- if (c.indexOf(name) === 0) {
- return c.substring(name.length, c.length);
- }
+ try {
+ const name = `${cname}=`;
+ const decodedCookie = decodeURIComponent(document.cookie);
+ const ca = decodedCookie.split(';');
+ for (let i = 0; i < ca.length; i++) {
+ let c = ca[i];
+ while (c.charAt(0) === ' ') {
+ c = c.substring(1);
+ }
+ if (c.indexOf(name) === 0) {
+ return c.substring(name.length, c.length);
}
- return '';
- } catch (error) {
- return '';
}
+ return '';
+ } catch (error) {
+ return '';
}
- export default getCookie; \ No newline at end of file
+};
+export default getCookie;
diff --git a/webAO/utils/setCookie.js b/webAO/utils/setCookie.js
index d3699a2..9734eae 100644
--- a/webAO/utils/setCookie.js
+++ b/webAO/utils/setCookie.js
@@ -4,7 +4,7 @@
* @param {String} cname The name of the cookie to return
* @param {String} value The value of that cookie option
*/
- const setCookie = (cname, value) => {
- document.cookie = `${cname}=${value}`;
- }
- export default setCookie \ No newline at end of file
+const setCookie = (cname, value) => {
+ document.cookie = `${cname}=${value}`;
+};
+export default setCookie;