diff --git a/assets/js/common.ts b/assets/js/common.ts index 19b523c..fb90c7e 100644 --- a/assets/js/common.ts +++ b/assets/js/common.ts @@ -3,6 +3,8 @@ import { createApp } from 'petite-vue' import { api, polling } from './settings' import { pageid } from '@params' +const interaction = createRandString(1) + type confdata = { apiurl: string pollurl: string @@ -82,6 +84,15 @@ function handle(msg) { // basic functions - move to api.ts +async function send(url: string, data: any) { + data._interaction = interaction + const body = JSON.stringify(data) + return fetch(url, { + method: 'POST', + body: body + }) +} + function createRandString(size: number): string { const arr = new Uint32Array(size) crypto.getRandomValues(arr) @@ -108,8 +119,8 @@ async function dopoll(app: typeof appdata) { const wait_time = 10000 while (true) { try { - let res = await fetch(app.conf.pollurl) - let msg = await res.json() + const res = await(send(app.conf.pollurl, {})) + const msg = await res.json() console.log(msg) switch (msg.status) { case 'idle':