Skip to main content

Action Replay Stream & Time-Lapse 🎬

Fuderu includes a serializable Operation Log & Action Replay engine. Every user interaction (brush strokes, flood fills, shapes, text, selections, transforms, and clipboard paste) is captured as a lightweight, serializable JSON action object.

This enables:

  • Animated Time-Lapse Playback: Replay an artist's creation process at 1x, 2x, or instant speed.
  • Collaborative Sync: Broadcast actions over WebSockets for multiplayer collaborative canvases.
  • Automated Testing & Bug Reports: Replay an exact sequence of user actions to reproduce visual bugs.

1. Recording Actions​

Fuderu automatically records actions into an internal session log:

// Inspect all actions performed in this session
const actions = painter.getActionLog();
console.log(`Recorded ${actions.length} actions so far.`);

Listening to Real-Time Action Events​

// Fires whenever a high-level action (fill, shape, clear, paste, transform) completes
painter.on("action:record", (action) => {
console.log("Action recorded:", action.type);
// Example: broadcast over WebSocket to other users
socket.emit("canvas:action", action);
});

// Fires for every interpolated stylus point during a brush stroke
painter.on("stroke:record", (point) => {
// Low-latency stroke streaming
});


2. Programmatic Replay​

You can replay any recorded action log on any Canvas instance.

Starting from a Clean Slate (resetArtwork)​

Before beginning a replay, reset the canvas to a clean background layer without losing your recorded history using resetArtwork():

// 1. Grab all recorded actions
const actions = painter.getActionLog();

// 2. Reset the artwork layers without clearing the recorded action log
painter.resetArtwork();

// 3. Replay with animated playback and live progress reporting
await painter.replay(actions, {
speed: 2, // 2x playback speed (0 = instant synchronous render)
onAction: (action, index, total) => {
// Keep layer list or sidebar UI in sync when layers are created/modified
if (action.type === "createLayer" || action.type === "deleteLayer") {
updateLayerSidebar();
}
},
onProgress: (progress, current, total) => {
const percent = Math.round(progress * 100);
progressBar.style.width = `${percent}%`;
statusText.textContent = `Replaying ${current}/${total} (${percent}%)...`;
},
});

3. Replaying Single Actions​

If you are receiving actions one-by-one from a server or multiplayer room:

socket.on("remote_canvas_action", async (action) => {
await painter.replayAction(action);
});

4. Replay Reliability Guarantees (v1.5.3)​

  • Preserved Base Layer ID: resetArtwork() resets layers while retaining the canvas's original base layer ID (initialBaseLayerId), preventing ID mismatches when replaying strokes.
  • Synchronous Point Draining: Brush.flush() is automatically awaited during stroke replay, ensuring all points and single-dot taps render completely before proceeding.
  • Mismatched Layer Fallback: If an action specifies a layer ID that does not exist on the canvas, the action automatically falls back to canvas.getActiveLayer() instead of being discarded.