Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JS timeline control and callback APIs #8673

Merged
merged 9 commits into from
Jan 15, 2025
Merged

Conversation

jprochazk
Copy link
Member

@jprochazk jprochazk commented Jan 13, 2025

Related

What

Adds the following methods to WebViewer:

get_active_recording_id(): string | null;
set_active_recording_id(value: string): void;
get_playing(recording_id: string): boolean;
set_playing(recording_id: string, value: boolean): void;
get_current_time(recording_id: string, timeline: string): number;
set_current_time(recording_id: string, timeline: string, time: number): void;
get_active_timeline(recording_id: string): string | null;
set_active_timeline(recording_id: string, timeline: string): void;
get_time_range(recording_id: string, timeline: string): { min: number; max: number; } | null;

As well as the following events:

interface Events {
  timelinechange: [timeline: string, time: number];
  timeupdate: number;
  play: void;
  pause: void;
}

The event names are somewhat inspired by HTMLMediaElement, e.g. timeupdate.

See https://github.com/rerun-io/web-viewer-example/blob/jan/temp-timeline-controls-example/src/main.ts#L15 for an example usage of these new APIs.


For the time being, I only added what I thought was necessary to implement an "external timeline". I ended up making all the new methods very explicit in which recording and timeline they deal with, but it's not too verbose to work with. I don't feel strongly about any of the names, they are fully open to bikeshedding 🙂.

All event callbacks are called from TimeControl::update. Time updates are not throttled in any way, but they don't seem to be frequent enough to show up in any profiles or noticeably slow down the viewer. That is, unless you put a lot of JS code in them.

Copy link

github-actions bot commented Jan 13, 2025

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link Manifest
c160fc7 https://rerun.io/viewer/pr/8673 +nightly +main

Note: This comment is updated whenever you push a commit.

@jprochazk jprochazk added enhancement New feature or request 🕸️ web regarding running the viewer in a browser include in changelog labels Jan 13, 2025
@jprochazk
Copy link
Member Author

jprochazk commented Jan 13, 2025

(drafted because I'm waiting for lints)

@jprochazk jprochazk marked this pull request as ready for review January 13, 2025 19:52
@emilk emilk self-requested a review January 14, 2025 13:33
crates/viewer/re_viewer/src/app_state.rs Outdated Show resolved Hide resolved
crates/viewer/re_viewer_context/src/time_control.rs Outdated Show resolved Hide resolved
rerun_js/web-viewer/index.ts Outdated Show resolved Hide resolved
@jprochazk jprochazk merged commit d0a7d1f into main Jan 15, 2025
31 checks passed
@jprochazk jprochazk deleted the jan/timeline-control branch January 15, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request include in changelog 🕸️ web regarding running the viewer in a browser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time selection control javascript API
2 participants