Skip to content

Instantly share code, notes, and snippets.

@hpr
Created April 26, 2024 01:49
Show Gist options
  • Save hpr/51480a635e2648d3a463b984ec54a210 to your computer and use it in GitHub Desktop.
Save hpr/51480a635e2648d3a463b984ec54a210 to your computer and use it in GitHub Desktop.
// (async () => {for (let i = 7150; i <= 7200; i++) {
// await new Promise(res => setTimeout(res, 100))
// const MEET = String(i);
const MEET = '7190';
const ws = new WebSocket(`wss://franklin-f56f3.firebaseio.com/.ws?${new URLSearchParams({v:5,ns:'franklin-f56f3'})}`);
let r = 1;
const send = p => ws.send(JSON.stringify({ t: "d", d: { r: r++, a: "q", b: { p: `/${MEET}/${p}`, h: "" } } }));
let msg = '';
ws.onmessage = async ({ data }) => {
msg += data;
let d;
try {
const resp = JSON.parse(msg);
d = resp.d ?? {};
msg = '';
} catch { return; }
const dat = d?.b?.d ?? {};
if (d.a === 'd') {
switch (d.b?.p?.split('/')[1]) {
case 'Schedule': {
for (const evt in dat) {
console.log(dat[evt].N, dat[evt].RN, new Date(dat[evt].T));
send(`MeetEvents/${evt}`);
await new Promise(res => setTimeout(res, 500))
}
break;
}
case 'MeetEvents': {
let out = `${dat.EID}\n`
for (const aid in dat.ED) {
const ath = dat.ED[aid];
// ath.PR, ath.SB
out += `${ath.A.N} ${ath.TN} ${ath.A.IAAF}\n`;
}
console.log(out);
break;
}
case 'Meta': {
console.log(MEET, dat.name, dat.startDate, dat);
break;
}
}
}
}
ws.onopen = () => send('Schedule');
// }
// })()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment