linting
All checks were successful
Code quality checks / biome (push) Successful in 7s

This commit is contained in:
Seth 2025-05-04 20:55:40 -04:00
parent ad23ab1907
commit a65ee6fe67
15 changed files with 564 additions and 466 deletions

View file

@ -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;
}
};
}
}