**A high-performance, frontend-focused ROS bag playback library for JavaScript and TypeScript.**
npm install rosbag-rxA high-performance, frontend-focused ROS bag playback library for JavaScript and TypeScript.
---
``bash`
npm install rosbag-rx
rosbag-rx brings the simplicity of rosbag play to the browser and modern frontend environments.
It removes the need to manually handle .bag file parsing, message decoding, or timing synchronization โ allowing you to focus on building robotics tools instead of reinventing playback logic.
With just a few lines of code, you can load a .bag file, extract metadata, and stream messages efficiently in real time โ with zero playback delay.
- ๐ฏ Simulates rosbag play in browser/JavaScriptplay()
- ๐ Real-time playback with accurate timing
- ๐ , pause(), seek() and looping support
- โก Zero-delay streaming via RxJS observables
- ๐ง Automatic memory and subscription management
- ๐ Easily toggle topic streams
- ๐งน Built-in cleanup mechanism
The RosbagManager class is the main interface for high-level bag playback. It handles state management, playback, message streaming, and cleanup โ all through a clean RxJS-based API.
You can reuse the same RosbagManager instance for multiple files. It will automatically reset internal state when a new file is loaded.
---
`ts
import { RosbagManager } from "rosbag-rx";
const rosbagManager = new RosbagManager();
`
---
You should subscribe to state$ before calling loadFile().
This stream includes bag metadata, playback state, and current playback time.
No need to manually unsubscribe โ everything is cleaned up automatically when destroyInstance() is called.
`ts`
rosbagManager.state$.subscribe({
next: (state) => {
console.log(state);
// {
// currentTime: { sec, nsec },
// bagMetadata: {
// startTime: { sec, nsec },
// endTime: { sec, nsec },
// connections: Map(...),
// chunksInfo: [...]
// },
// options: {
// prefetch: 10,
// playbackSpeed: 1,
// loop: true
// },
// isPlaying: false
// }
},
});
---
You can subscribe to error$ to receive well-explained errors such as:
- Corrupted bag file
- Parsing issues
- Unsupported or malformed message structures
`ts`
rosbagManager.error$.subscribe({
next: (error) => {
console.error("Bag error:", error);
},
});
---
You will receive an array of messages for the currently active time slice, filtered by the topics youโve toggled using showConnectionMsgs.
`ts`
rosbagManager.messages$.subscribe({
next: (messages) => {
console.log("Received messages:", messages);
},
});
---
`ts
rosbagManager.loadFile(file);
rosbagManager.play();
rosbagManager.pause();
rosbagManager.seek({ sec: 0, nsec: 0 }); // Seek to start
`
---
`ts`
rosbagManager.updateOptions({
playbackSpeed: 5, // Default is 1
prefetch: 1, // Default is 10 seconds (recommended)
loop: false, // Default is true
});
---
By default, all topics are disabled. To receive messages, you must explicitly enable them.
#### Show a topic:
`ts`
rosbagManager.showConnectionMsgs("/odom");
#### Hide a topic:
`ts`
rosbagManager.hideConnectionMsgs("/odom");
---
To prevent memory leaks and stop all internal observables, call:
`ts``
rosbagManager.destroyInstance();
This will:
- Unsubscribe from all internal streams
- Reset internal state
- Release all resources