32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { API_PREFIX, HTTP_SCHEME, PREF } from "./const";
|
|
|
|
interface SessionData {
|
|
"player_count": string;
|
|
"players": string;
|
|
"worthy_answers": string;
|
|
"completed_riddles": string;
|
|
"points": string;
|
|
"bought_hints": string;
|
|
"voice_over": string;
|
|
};
|
|
|
|
export async function heartbeat(data: SessionData, code: string) {
|
|
const res = await fetch(`${HTTP_SCHEME}://${API_PREFIX}/sessions?code=${code}`,
|
|
{
|
|
"method": "POST",
|
|
"cache": "no-cache",
|
|
"body": JSON.stringify(data)
|
|
}
|
|
);
|
|
return res;
|
|
}
|
|
|
|
export function setSessionData(data: SessionData) {
|
|
localStorage.setItem(PREF.playerCount, data.player_count);
|
|
localStorage.setItem(PREF.players, data.players);
|
|
localStorage.setItem(PREF.worthyWords, data.worthy_answers);
|
|
localStorage.setItem(PREF.completed_riddles, data.completed_riddles);
|
|
localStorage.setItem(PREF.points, data.points);
|
|
localStorage.setItem(PREF.boughtHints, data.bought_hints);
|
|
localStorage.setItem(PREF.voiceover, data.voice_over);
|
|
} |