Merge pull request #702 from openreplay/tracker-project-url

Tracker method to get active session url
This commit is contained in:
Delirium 2022-08-30 14:13:07 +01:00 committed by GitHub
commit 87f9e72eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 5 deletions

View file

@ -27,7 +27,7 @@ module.exports = {
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/prefer-readonly': 'warn',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
@ -46,4 +46,4 @@ module.exports = {
'@typescript-eslint/no-unused-expressions': 'warn',
'@typescript-eslint/no-useless-constructor': 'warn',
},
};
};

View file

@ -290,6 +290,17 @@ export default class App {
getSessionID(): string | undefined {
return this.session.getInfo().sessionID || undefined
}
getSessionURL(): string | undefined {
const { projectID, sessionID } = this.session.getInfo()
if (!projectID || !sessionID) {
this.debug.error('OpenReplay error: Unable to build session URL')
return undefined
}
return this.options.ingestPoint.replace(/\/ingest$/, `${projectID}/session/${sessionID}`)
}
getHost(): string {
return new URL(this.options.ingestPoint).hostname
}
@ -409,6 +420,7 @@ export default class App {
token,
userUUID,
sessionID,
projectID,
beaconSizeLimit,
startTimestamp, // real startTS, derived from sessionID
} = r
@ -423,7 +435,8 @@ export default class App {
}
this.session.setSessionToken(token)
this.localStorage.setItem(this.options.local_uuid_key, userUUID)
this.session.update({ sessionID, timestamp: startTimestamp || timestamp }) // TODO: no no-explicit 'any'
this.session.update({ sessionID, timestamp: startTimestamp || timestamp, projectID }) // TODO: no no-explicit 'any'
const startWorkerMsg: WorkerMessageData = {
type: 'auth',
token,

View file

@ -5,6 +5,7 @@ interface SessionInfo {
metadata: Record<string, string>
userID: string | null
timestamp: number
projectID?: string
}
type OnUpdateCallback = (i: Partial<SessionInfo>) => void
@ -19,8 +20,9 @@ export default class Session {
private sessionID: string | undefined
private readonly callbacks: OnUpdateCallback[] = []
private timestamp = 0
private projectID: string | undefined
constructor(private readonly app: App, private options: Options) {}
constructor(private readonly app: App, private readonly options: Options) {}
attachUpdateCallback(cb: OnUpdateCallback) {
this.callbacks.push(cb)
@ -35,7 +37,7 @@ export default class Session {
this.callbacks.forEach((cb) => cb(newInfo))
}
update(newInfo: Partial<SessionInfo>) {
update(newInfo: Partial<SessionInfo>): void {
if (newInfo.userID !== undefined) {
// TODO clear nullable/undefinable types
this.userID = newInfo.userID
@ -49,6 +51,9 @@ export default class Session {
if (newInfo.timestamp !== undefined) {
this.timestamp = newInfo.timestamp
}
if (newInfo.projectID !== undefined) {
this.projectID = newInfo.projectID
}
this.handleUpdate(newInfo)
}
@ -116,6 +121,7 @@ export default class Session {
metadata: this.metadata,
userID: this.userID,
timestamp: this.timestamp,
projectID: this.projectID,
}
}

View file

@ -209,6 +209,13 @@ export default class API {
return this.getSessionID()
}
getSessionURL(): string | undefined {
if (this.app === null) {
return undefined
}
return this.app.getSessionURL()
}
setUserID(id: string): void {
if (typeof id === 'string' && this.app !== null) {
this.app.session.setUserID(id)