openreplay/frontend/app/player/mobile/managers/SnapshotManager.ts
Delirium e207d37e69
Ios player v2 (#1901)
* feat(ui): new ios player start

* fix(ui): image player

* fix(ui): fix autoplay

* fix(ui): fix copy paste code; error handler; default mode null

* fix(ui): fix loader animation

* fix(ui): memory cleanup

* fix(ui): memory cleanup
2024-02-22 12:50:19 +01:00

40 lines
No EOL
1,020 B
TypeScript

import { TarFile } from "js-untar";
import ListWalker from 'Player/common/ListWalker';
interface Snapshots {
[timestamp: number]: TarFile
}
type Timestamp = { time: number }
export default class SnapshotManager extends ListWalker<Timestamp> {
private snapshots: Snapshots = {}
public mapToSnapshots(files: TarFile[]) {
const filenameRegexp = /(\d+)_1_(\d+)\.jpeg$/;
const firstPair = files[0].name.match(filenameRegexp)
const sessionStart = firstPair ? parseInt(firstPair[1], 10) : 0
files.forEach(file => {
const [_, _2, imageTimestamp] = file
.name
.match(filenameRegexp)
?.map(n => parseInt(n, 10)) ?? [0, 0, 0]
const messageTime = imageTimestamp - sessionStart
this.snapshots[messageTime] = file
this.append({ time: messageTime })
})
}
public moveReady(t: number) {
const msg = this.moveGetLast(t)
if (msg) {
return this.snapshots[msg.time]
}
}
public clean() {
this.snapshots = {}
this.reset()
}
}