tracker: add restart on token expiration for canvas tracker

This commit is contained in:
nick-delirium 2024-09-26 14:29:31 +02:00
parent 62d3636136
commit bd7ecf18f4
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
5 changed files with 19 additions and 4 deletions

View file

@ -1,6 +1,7 @@
# 14.0.7
- check for stopping status during restarts
- restart if token expired during canvas fetch
# 14.0.6

Binary file not shown.

View file

@ -1,7 +1,7 @@
{
"name": "@openreplay/tracker",
"description": "The OpenReplay tracker main package",
"version": "14.0.7-beta.0",
"version": "14.0.7",
"keywords": [
"logging",
"replay"

View file

@ -128,7 +128,7 @@ class CanvasRecorder {
return
}
if (!canvas || !hasTag(canvas, 'canvas') || canvas !== node) {
this.app.debug.log('Canvas element not in sync')
this.app.debug.log('Canvas element not in sync', canvas, node)
clearInterval(int)
return
} else {
@ -160,6 +160,14 @@ class CanvasRecorder {
}
})
const initRestart = () => {
this.app.debug.log('Restarting tracker; token expired')
this.app.stop(false)
setTimeout(() => {
void this.app.start({}, true)
}, 250)
}
fetch(this.app.options.ingestPoint + '/v1/web/images', {
method: 'POST',
headers: {
@ -167,7 +175,10 @@ class CanvasRecorder {
},
body: formData,
})
.then(() => {
.then((r) => {
if (r.status === 401) {
return initRestart()
}
return true
})
.catch((e) => {

View file

@ -34,6 +34,7 @@ export default class Session {
private projectID: string | undefined
private tabId: string
public userInfo: UserInfo
private token: string | undefined
constructor(
private readonly app: App,
@ -109,10 +110,12 @@ export default class Session {
}
getSessionToken(): string | undefined {
return this.app.sessionStorage.getItem(this.options.session_token_key) || undefined
const token = this.token || this.app.sessionStorage.getItem(this.options.session_token_key)
return token || undefined
}
setSessionToken(token: string): void {
this.token = token
this.app.sessionStorage.setItem(this.options.session_token_key, token)
}