Skip to content

Feature/store session files - #3

Open
engbergandreas wants to merge 5 commits into
masterfrom
feature/store-session-files
Open

Feature/store session files#3
engbergandreas wants to merge 5 commits into
masterfrom
feature/store-session-files

Conversation

@engbergandreas

Copy link
Copy Markdown
Member

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .astrorec files; replay scripts to late joiners).
  • Adds SESSION_RECORDING_DIR environment 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.readUint8 is likely a typo/incompatible API; prefer readUInt8 for 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.

Comment thread src/session.ts Outdated
Comment thread src/session.ts
Comment thread src/session.ts
Comment thread src/app.ts
Comment thread src/session.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/app.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants