Feature/store session files - #3
Open
engbergandreas wants to merge 5 commits into
Open
Conversation
…scripts on late-joining peers
Contributor
There was a problem hiding this comment.
Pull request overview
Adds server-side persistence for session “Data” events to disk and enables late-joining peers to be brought up-to-date by replaying recorded script events, along with a REST endpoint to download the raw recording file.
Changes:
- Introduces recording file support in
Session(append serialized Data entries to per-session.astrorecfiles; replay scripts to late joiners). - Adds
SESSION_RECORDING_DIRenvironment configuration and ensures the directory exists at startup. - Adds an authenticated REST route to download a session’s recording file.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/types.ts | Adds DataType enum and RecordedFileEntry type used by recording/parsing logic. |
| src/types/env.d.ts | Declares SESSION_RECORDING_DIR env var type. |
| src/session.ts | Implements recording stream, file parsing, script replay for late joiners, and recording path helper. |
| src/index.ts | Ensures the recording directory exists on startup. |
| src/config/env.ts | Adds SESSION_RECORDING_DIR to validated environment schema. |
| src/app.ts | Adds GET /session/:id/recording download endpoint and starts recording on new session creation. |
| src/adminApi.ts | Import/order + formatting changes (no functional recording logic here). |
| .gitignore | Ignores recordings/ directory. |
| .env-sample | Documents/configures SESSION_RECORDING_DIR. |
Suppressed comments (4)
src/session.ts:102
- Typo in binary layout comment: "uin32" should be "uint32".
* [double (64-bit) elapsedMs][uin32 payloadLength][payload bytes]
src/session.ts:503
Buffer.readUint8is likely a typo/incompatible API; preferreadUInt8for reading the first byte.
// Store only Scripts events in RAM
const dataType = data.readUint8(0);
if (dataType === DataType.Script) {
this.recordedEntries.push(entry);
src/session.ts:481
- Typos/grammar in the recordEntry doc comment ("Scripts events"/"recieved").
* recording started. Scripts events are also stored in RAM for late-joining peers.
* Camera and Time updates will be recieved immediately upon joining and are therefore
* excluded from RAM cache.
src/session.ts:533
- Typos in elapsed-time doc comment ("messaged"/"recoonecting").
* is the first Data messaged ever recorded for the session, it is not reset by host
* disconnecting and/or recoonecting. If the server restarts mid-session, the downtime
* itself is not counted, i.e., elapsed time picks up where the previous run left off.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
src/session.ts:410
- On startup, resuming a session logs an error if the recording file does not exist (ENOENT). This is a common/expected situation (e.g., sessions created before recordings existed or if the recordings directory was cleared) and will unnecessarily spam error logs.
} catch (error) {
LERROR(
`Session '${this.id}': failed to load existing recording file '${this.recordingFilePath()}'`,
error
);
src/session.ts:480
- Spelling typo in comment: "receieved" -> "received".
* Camera and Time updates will be receieved immediately upon joining and are therefore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds all camera, time, and script events to a file on disk, which allows users to download a recorded session (A task to convert the file into a session recording will be made at a later stage). Further, any late-joining peer will have all scripts replayed before they receive new events so that they are up-to-date with the OpenSpace state.