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 { api, polling } from './settings'
|
||||||
import { pageid } from '@params'
|
import { pageid } from '@params'
|
||||||
|
|
||||||
|
const interaction = createRandString(1)
|
||||||
|
|
||||||
type confdata = {
|
type confdata = {
|
||||||
apiurl: string
|
apiurl: string
|
||||||
pollurl: string
|
pollurl: string
|
||||||
|
@ -82,6 +84,15 @@ function handle(msg) {
|
||||||
|
|
||||||
// basic functions - move to api.ts
|
// 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 {
|
function createRandString(size: number): string {
|
||||||
const arr = new Uint32Array(size)
|
const arr = new Uint32Array(size)
|
||||||
crypto.getRandomValues(arr)
|
crypto.getRandomValues(arr)
|
||||||
|
@ -108,8 +119,8 @@ async function dopoll(app: typeof appdata) {
|
||||||
const wait_time = 10000
|
const wait_time = 10000
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
let res = await fetch(app.conf.pollurl)
|
const res = await(send(app.conf.pollurl, {}))
|
||||||
let msg = await res.json()
|
const msg = await res.json()
|
||||||
console.log(msg)
|
console.log(msg)
|
||||||
switch (msg.status) {
|
switch (msg.status) {
|
||||||
case 'idle':
|
case 'idle':
|
||||||
|
|
Loading…
Add table
Reference in a new issue