forked from seth/ipv4.army
linting
This commit is contained in:
parent
ad23ab1907
commit
a65ee6fe67
15 changed files with 564 additions and 466 deletions
|
@ -1,88 +1,89 @@
|
|||
import ReconnectingWebSocket from 'reconnecting-websocket';
|
||||
import ReconnectingWebSocket from "reconnecting-websocket";
|
||||
|
||||
export default class {
|
||||
private _socket: ReconnectingWebSocket;
|
||||
private _keepAlive: NodeJS.Timeout | null;
|
||||
private _interval: NodeJS.Timeout | null;
|
||||
private _callback: (data: number) => void;
|
||||
private _socket: ReconnectingWebSocket;
|
||||
private _keepAlive: NodeJS.Timeout | null;
|
||||
private _interval: NodeJS.Timeout | null;
|
||||
private _callback: (data: number) => void;
|
||||
|
||||
constructor(callback: (data: number) => void) {
|
||||
this._socket = new ReconnectingWebSocket("wss://app.hyperate.io/socket/websocket?token=wv39nM6iyrNJulvpmMQrimYPIXy2dVrYRjkuHpbRapKT2VSh65ngDGHdCdCtmEN9")
|
||||
this._keepAlive = null;
|
||||
this._interval = null;
|
||||
this._callback = callback;
|
||||
constructor(callback: (data: number) => void) {
|
||||
this._socket = new ReconnectingWebSocket(
|
||||
"wss://app.hyperate.io/socket/websocket?token=wv39nM6iyrNJulvpmMQrimYPIXy2dVrYRjkuHpbRapKT2VSh65ngDGHdCdCtmEN9",
|
||||
);
|
||||
this._keepAlive = null;
|
||||
this._interval = null;
|
||||
this._callback = callback;
|
||||
|
||||
this._socket.binaryType = "arraybuffer";
|
||||
this._socket.binaryType = "arraybuffer";
|
||||
|
||||
this._socket.onopen = () => {
|
||||
console.log("Hyperate socket opened")
|
||||
this._socket.onopen = () => {
|
||||
console.log("Hyperate socket opened");
|
||||
|
||||
this._socket.send(
|
||||
JSON.stringify({
|
||||
topic: "hr:84aa0f",
|
||||
event: "phx_join",
|
||||
payload: {},
|
||||
ref: 0,
|
||||
}),
|
||||
);
|
||||
this._socket.send(
|
||||
JSON.stringify({
|
||||
topic: "hr:84aa0f",
|
||||
event: "phx_join",
|
||||
payload: {},
|
||||
ref: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
this._keepAlive = setInterval(() => {
|
||||
this._socket.send(
|
||||
JSON.stringify({
|
||||
topic: "phoenix",
|
||||
event: "heartbeat",
|
||||
payload: {},
|
||||
ref: 0,
|
||||
}),
|
||||
);
|
||||
}, 10000);
|
||||
}
|
||||
this._keepAlive = setInterval(() => {
|
||||
this._socket.send(
|
||||
JSON.stringify({
|
||||
topic: "phoenix",
|
||||
event: "heartbeat",
|
||||
payload: {},
|
||||
ref: 0,
|
||||
}),
|
||||
);
|
||||
}, 10000);
|
||||
};
|
||||
|
||||
this._socket.onmessage = ({ data }: MessageEvent) => {
|
||||
data = JSON.parse(data);
|
||||
this._socket.onmessage = ({ data }: MessageEvent) => {
|
||||
data = JSON.parse(data);
|
||||
|
||||
switch (data.event) {
|
||||
case "hr_update": {
|
||||
this._callback(data.payload.hr);
|
||||
this.heartbeat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (data.event) {
|
||||
case "hr_update": {
|
||||
this._callback(data.payload.hr);
|
||||
this.heartbeat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this._socket.onerror = () => {
|
||||
console.error("Hyperate socket error");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
if (this._interval) {
|
||||
clearInterval(this._interval);
|
||||
this._interval = null;
|
||||
}
|
||||
}
|
||||
this._socket.onerror = () => {
|
||||
console.error("Hyperate socket error");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
if (this._interval) {
|
||||
clearInterval(this._interval);
|
||||
this._interval = null;
|
||||
}
|
||||
};
|
||||
|
||||
this._socket.onclose = () => {
|
||||
console.log("Hyperate socket closed");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
if (this._interval) {
|
||||
clearInterval(this._interval);
|
||||
this._interval = null;
|
||||
}
|
||||
}
|
||||
this._socket.onclose = () => {
|
||||
console.log("Hyperate socket closed");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
if (this._interval) {
|
||||
clearInterval(this._interval);
|
||||
this._interval = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private heartbeat() {
|
||||
if (this._interval) {
|
||||
clearTimeout(this._interval);
|
||||
this._interval = null;
|
||||
}
|
||||
this._interval = setTimeout(() => {
|
||||
this._callback(0);
|
||||
}, 6000);
|
||||
}
|
||||
}
|
||||
private heartbeat() {
|
||||
if (this._interval) {
|
||||
clearTimeout(this._interval);
|
||||
this._interval = null;
|
||||
}
|
||||
this._interval = setTimeout(() => {
|
||||
this._callback(0);
|
||||
}, 6000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +1,66 @@
|
|||
import ReconnectingWebSocket from 'reconnecting-websocket';
|
||||
import ReconnectingWebSocket from "reconnecting-websocket";
|
||||
|
||||
export default class {
|
||||
private _socket: ReconnectingWebSocket;
|
||||
private _keepAlive: NodeJS.Timeout | null;
|
||||
private _callback: (data: { [key: string]: string }) => void;
|
||||
private _socket: ReconnectingWebSocket;
|
||||
private _keepAlive: NodeJS.Timeout | null;
|
||||
private _callback: (data: { [key: string]: string }) => void;
|
||||
|
||||
constructor(callback: (data: { [key: string]: string }) => void) {
|
||||
this._socket = new ReconnectingWebSocket("wss://lanyard.creations.works/socket")
|
||||
this._keepAlive = null;
|
||||
this._callback = callback;
|
||||
constructor(callback: (data: { [key: string]: string }) => void) {
|
||||
this._socket = new ReconnectingWebSocket(
|
||||
"wss://lanyard.creations.works/socket",
|
||||
);
|
||||
this._keepAlive = null;
|
||||
this._callback = callback;
|
||||
|
||||
this._socket.binaryType = "arraybuffer";
|
||||
this._socket.binaryType = "arraybuffer";
|
||||
|
||||
this._socket.onopen = () => {
|
||||
console.log("Lanyard socket opened")
|
||||
}
|
||||
this._socket.onopen = () => {
|
||||
console.log("Lanyard socket opened");
|
||||
};
|
||||
|
||||
this._socket.onmessage = ({ data }: MessageEvent) => {
|
||||
data = JSON.parse(data);
|
||||
this._socket.onmessage = ({ data }: MessageEvent) => {
|
||||
data = JSON.parse(data);
|
||||
|
||||
switch (data.op) {
|
||||
case 0: {
|
||||
this._callback(data.d)
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
this._socket.send(JSON.stringify({
|
||||
op: 2,
|
||||
d: {
|
||||
subscribe_to_id: "1273447359417942128"
|
||||
}
|
||||
}))
|
||||
this._keepAlive = setInterval(() => {
|
||||
this._socket.send(JSON.stringify({
|
||||
op: 3
|
||||
}))
|
||||
}, data.d.heartbeat_interval)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (data.op) {
|
||||
case 0: {
|
||||
this._callback(data.d);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
this._socket.send(
|
||||
JSON.stringify({
|
||||
op: 2,
|
||||
d: {
|
||||
subscribe_to_id: "1273447359417942128",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this._keepAlive = setInterval(() => {
|
||||
this._socket.send(
|
||||
JSON.stringify({
|
||||
op: 3,
|
||||
}),
|
||||
);
|
||||
}, data.d.heartbeat_interval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this._socket.onerror = () => {
|
||||
console.error("Lanyard socket error");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
}
|
||||
this._socket.onerror = () => {
|
||||
console.error("Lanyard socket error");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
};
|
||||
|
||||
this._socket.onclose = () => {
|
||||
console.log("Lanyard socket closed");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
this._socket.onclose = () => {
|
||||
console.log("Lanyard socket closed");
|
||||
if (this._keepAlive) {
|
||||
clearInterval(this._keepAlive);
|
||||
this._keepAlive = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,71 +4,79 @@ import Lanyard from "./Sockets/Lanyard";
|
|||
const development = process.env.NODE_ENV === "development";
|
||||
|
||||
const build = async () => {
|
||||
return await Bun.build({
|
||||
entrypoints: ['./src/front/index.html'],
|
||||
outdir: './dist',
|
||||
minify: !development,
|
||||
sourcemap: (development ? "inline" : "none"),
|
||||
splitting: true,
|
||||
publicPath: "/assets/",
|
||||
})
|
||||
}
|
||||
return await Bun.build({
|
||||
entrypoints: ["./src/front/index.html"],
|
||||
outdir: "./dist",
|
||||
minify: !development,
|
||||
sourcemap: development ? "inline" : "none",
|
||||
splitting: true,
|
||||
publicPath: "/assets/",
|
||||
});
|
||||
};
|
||||
|
||||
const respOptions = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-cache",
|
||||
"Content-Encoding": "gzip",
|
||||
}
|
||||
}
|
||||
const okResp = new Response(Bun.gzipSync(JSON.stringify({ data: "ok" })), respOptions)
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-cache",
|
||||
"Content-Encoding": "gzip",
|
||||
},
|
||||
};
|
||||
const okResp = new Response(
|
||||
Bun.gzipSync(JSON.stringify({ data: "ok" })),
|
||||
respOptions,
|
||||
);
|
||||
const Responses = {
|
||||
ok: () => {
|
||||
return okResp.clone();
|
||||
},
|
||||
json: (data: { [key: string]: string }) => {
|
||||
return new Response(Bun.gzipSync(JSON.stringify(data)), respOptions);
|
||||
},
|
||||
file: async (file: Bun.BunFile) => {
|
||||
return new Response(Bun.gzipSync(await file.arrayBuffer()), {
|
||||
headers: {
|
||||
"Content-Type": file.type,
|
||||
"Cache-Control": "public, max-age=31536000",
|
||||
"Content-Encoding": "gzip",
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
ok: () => {
|
||||
return okResp.clone();
|
||||
},
|
||||
json: (data: { [key: string]: string }) => {
|
||||
return new Response(Bun.gzipSync(JSON.stringify(data)), respOptions);
|
||||
},
|
||||
file: async (file: Bun.BunFile) => {
|
||||
return new Response(Bun.gzipSync(await file.arrayBuffer()), {
|
||||
headers: {
|
||||
"Content-Type": file.type,
|
||||
"Cache-Control": "public, max-age=31536000",
|
||||
"Content-Encoding": "gzip",
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const postAnalytics = async (req: Request | Bun.BunRequest, server: Bun.Server) => {
|
||||
return await fetch("https://plausible.creations.works/api/event", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": req.headers.get("user-agent") || "",
|
||||
"X-Forwarded-For": String(
|
||||
req.headers.get("CF-Connecting-IP") ||
|
||||
req.headers.get("X-Real-IP") ||
|
||||
req.headers.get("X-Forwarded-For")?.split(",")[0] ||
|
||||
(typeof server.requestIP(req) === "string" ? server.requestIP(req) : (server.requestIP(req)?.address || ""))
|
||||
),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: "ipv4.army",
|
||||
name: "pageview",
|
||||
url: req.url,
|
||||
referrer: req.headers.get("referer") || "",
|
||||
})
|
||||
})
|
||||
}
|
||||
const postAnalytics = async (
|
||||
req: Request | Bun.BunRequest,
|
||||
server: Bun.Server,
|
||||
) => {
|
||||
return await fetch("https://plausible.creations.works/api/event", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": req.headers.get("user-agent") || "",
|
||||
"X-Forwarded-For": String(
|
||||
req.headers.get("CF-Connecting-IP") ||
|
||||
req.headers.get("X-Real-IP") ||
|
||||
req.headers.get("X-Forwarded-For")?.split(",")[0] ||
|
||||
(typeof server.requestIP(req) === "string"
|
||||
? server.requestIP(req)
|
||||
: server.requestIP(req)?.address || ""),
|
||||
),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: "ipv4.army",
|
||||
name: "pageview",
|
||||
url: req.url,
|
||||
referrer: req.headers.get("referer") || "",
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
Sockets: {
|
||||
Hyperate,
|
||||
Lanyard
|
||||
},
|
||||
Responses,
|
||||
build,
|
||||
development,
|
||||
postAnalytics,
|
||||
};
|
||||
Sockets: {
|
||||
Hyperate,
|
||||
Lanyard,
|
||||
},
|
||||
Responses,
|
||||
build,
|
||||
development,
|
||||
postAnalytics,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue