poll: send interaction in POST data
This commit is contained in:
parent
ecf3f13622
commit
463fdb266b
1 changed files with 13 additions and 2 deletions
|
@ -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':
|
||||
|
|
Loading…
Add table
Reference in a new issue