This commit is contained in:
Chompstation Bot
2021-06-18 04:23:03 +00:00
committed by Darlantan
parent 5f76f2e855
commit 331e5230d6
332 changed files with 23458 additions and 9666 deletions

View File

@@ -1,3 +1,9 @@
/**
* @file
* @copyright 2020 Aleksej Komarov
* @license MIT
*/
let socket;
const queue = [];
const subscribers = [];
@@ -31,7 +37,7 @@ if (process.env.NODE_ENV !== 'production') {
window.onunload = () => socket && socket.close();
}
const subscribe = fn => subscribers.push(fn);
export const subscribe = fn => subscribers.push(fn);
/**
* A json serializer which handles circular references and other junk.
@@ -62,7 +68,10 @@ const serializeObject = obj => {
}
refs.push(value);
// Error object
if (value instanceof Error) {
const isError = value instanceof Error || (
value.code && value.message && value.message.includes('Error')
);
if (isError) {
return {
__error__: true,
string: String(value),
@@ -82,7 +91,7 @@ const serializeObject = obj => {
return json;
};
const sendRawMessage = msg => {
export const sendMessage = msg => {
if (process.env.NODE_ENV !== 'production') {
const json = serializeObject(msg);
// Send message using WebSocket
@@ -103,8 +112,8 @@ const sendRawMessage = msg => {
else {
const DEV_SERVER_IP = process.env.DEV_SERVER_IP || '127.0.0.1';
const req = new XMLHttpRequest();
req.open('POST', `http://${DEV_SERVER_IP}:3001`);
req.timeout = 500;
req.open('POST', `http://${DEV_SERVER_IP}:3001`, true);
req.timeout = 250;
req.send(json);
}
}
@@ -113,7 +122,7 @@ const sendRawMessage = msg => {
export const sendLogEntry = (level, ns, ...args) => {
if (process.env.NODE_ENV !== 'production') {
try {
sendRawMessage({
sendMessage({
type: 'log',
payload: {
level,