Skip to content

Room and eventsRoom

Recording

Record matches as replay files and receive recordings the room finishes for you.

A recording captures everything needed to replay a match: the stadium, every input and command, and checkpoints to verify playback. Recordings are binary .ball2drep files; decode them with readReplay().

A recording can run for up to one hour and 30 MB. When it reaches a limit, when the stadium changes, or when the room closes, the room finishes it for you and delivers it to onRecordingComplete.

startRecording()

method
room.startRecording(): void

Starts recording now, in any phase. It is synchronous and throws Recording is already active if a recording is running.

JavaScript
room.onGameStart = () => room.startRecording();

stopRecording()

method
room.stopRecording(): Blob | null

Stops recording and returns the file. A recording you stop yourself is returned here only: it does not fire onRecordingComplete or update lastRecording.

Returns

Blob | nullThe recording as a Blob, or null if nothing was recording.

JavaScript
import { writeFile } from 'node:fs/promises';

room.onTeamVictory = async () => {
  const blob = room.stopRecording();
  if (blob)
    await writeFile(
      `match-${Date.now()}.ball2drep`,
      Buffer.from(await blob.arrayBuffer()),
    );
};

lastRecording

property
room.lastRecording: Blob | null
readonly

The last recording the room finished on its own, for a limit, a stadium change or closing; null if there hasn't been one. Recordings returned by stopRecording() are not stored here.