poll: send interaction in POST data

This commit is contained in:
Helmut Merz 2023-03-10 09:31:24 +01:00
parent ecf3f13622
commit 463fdb266b

View file

@ -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':