45 lines
731 B
TypeScript
45 lines
731 B
TypeScript
import { api, polling } from './settings'
|
|
|
|
type confdata = {
|
|
pollurl: string
|
|
}
|
|
|
|
export function config (api, polling): confdata {
|
|
return { pollurl: '' }
|
|
}
|
|
|
|
export const pvapp = {
|
|
$delimiters: ['{|', '|}'],
|
|
conf: {} as confdata,
|
|
data: {},
|
|
output: '',
|
|
save,
|
|
poll
|
|
}
|
|
|
|
// method definitions
|
|
|
|
function save(value: string) {
|
|
this.output += '\n' + value
|
|
//this.newdata = ''
|
|
}
|
|
|
|
async function dopoll(app: typeof pvapp) {
|
|
while (true) {
|
|
try {
|
|
let res = await fetch(pvapp.conf.pollurl)
|
|
let msg = await res.json()
|
|
console.log(msg)
|
|
//app.handle(msg)
|
|
//app.newdata = data['status']
|
|
} catch (error) {
|
|
console.log(error)
|
|
await new Promise(r => setTimeout(r, 10000))
|
|
}
|
|
}
|
|
}
|
|
|
|
function poll() {
|
|
dopoll(this)
|
|
}
|
|
|