43 lines
965 B
Python
43 lines
965 B
Python
from session.db import SessionDB
|
|
|
|
|
|
class SessionReplay:
|
|
|
|
def __init__(self, db: SessionDB):
|
|
self.db = db
|
|
|
|
# -----------------------------
|
|
# REPLAY SESSION
|
|
# -----------------------------
|
|
def replay(self, session_id):
|
|
|
|
stream = self.db.get_replay_stream(session_id)
|
|
|
|
for event in stream:
|
|
|
|
yield {
|
|
"ts": event["ts"],
|
|
"type": event["type"],
|
|
"data": event["data"]
|
|
}
|
|
|
|
# -----------------------------
|
|
# REPLAY FROM SNAPSHOT
|
|
# -----------------------------
|
|
def replay_from_snapshot(self, session_id, index=0):
|
|
|
|
snapshots = self.db.snapshots[session_id]
|
|
|
|
if not snapshots:
|
|
return []
|
|
|
|
base = snapshots[index]
|
|
|
|
return {
|
|
"snapshot": base,
|
|
"events_after": [
|
|
e for e in self.db.events[session_id]
|
|
if e["ts"] >= base["ts"]
|
|
]
|
|
}
|