fix(tracker):3.5.7:fetch keepalive size limit check
This commit is contained in:
parent
09069329ca
commit
498e562d1b
2 changed files with 27 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@openreplay/tracker",
|
||||
"description": "The OpenReplay tracker main package",
|
||||
"version": "3.5.6",
|
||||
"version": "3.5.7",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"replay"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,26 @@
|
|||
const INGEST_PATH = "/v1/web/i"
|
||||
|
||||
const KEEPALIVE_SIZE_LIMIT = 64 << 10 // 64 kB
|
||||
|
||||
// function sendXHR(url: string, token: string, batch: Uint8Array): Promise<XMLHttpRequest> {
|
||||
// const req = new XMLHttpRequest()
|
||||
// req.open("POST", url)
|
||||
// req.setRequestHeader("Authorization", "Bearer " + token)
|
||||
// return new Promise((res, rej) => {
|
||||
// req.onreadystatechange = function() {
|
||||
// if (this.readyState === 4) {
|
||||
// if (this.status == 0) {
|
||||
// return; // happens simultaneously with onerror
|
||||
// }
|
||||
// res(this)
|
||||
// }
|
||||
// }
|
||||
// req.onerror = rej
|
||||
// req.send(batch.buffer)
|
||||
// })
|
||||
// }
|
||||
|
||||
|
||||
export default class QueueSender {
|
||||
private attemptsCount = 0
|
||||
private busy = false
|
||||
|
|
@ -24,7 +45,6 @@ export default class QueueSender {
|
|||
if (this.busy || !this.token) {
|
||||
this.queue.push(batch)
|
||||
} else {
|
||||
this.busy = true
|
||||
this.sendBatch(batch)
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +60,8 @@ export default class QueueSender {
|
|||
|
||||
// would be nice to use Beacon API, but it is not available in WebWorker
|
||||
private sendBatch(batch: Uint8Array):void {
|
||||
this.busy = true
|
||||
|
||||
fetch(this.ingestURL, {
|
||||
body: batch,
|
||||
method: 'POST',
|
||||
|
|
@ -47,7 +69,7 @@ export default class QueueSender {
|
|||
"Authorization": "Bearer " + this.token,
|
||||
//"Content-Type": "",
|
||||
},
|
||||
keepalive: true,
|
||||
keepalive: batch.length < KEEPALIVE_SIZE_LIMIT,
|
||||
})
|
||||
.then(r => {
|
||||
if (r.status === 401) { // TODO: continuous session ?
|
||||
|
|
@ -69,8 +91,9 @@ export default class QueueSender {
|
|||
}
|
||||
})
|
||||
.catch(e => {
|
||||
console.warn("OpenReplay:", e)
|
||||
this.retry(batch)
|
||||
}) // Does it handle offline exceptions (?)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue