Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "roslib",
"homepage": "https://robotwebtools.github.io",
"description": "The standard ROS Javascript Library",
"version": "2.0.0-alpha5",
"version": "2.0.0-alpha6",
"license": "BSD-2-Clause",
"files": [
"dist"
Expand Down
8 changes: 4 additions & 4 deletions src/core/Ros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export interface TypeDefDict {
* Manages connection to the rosbridge server and all interactions with ROS.
*
* Emits the following events:
* * 'open' - Connected to the rosbridge server.
* * 'connection' - Connected to the rosbridge server.
* * 'close' - Disconnected to the rosbridge server.
* * 'error' - There was an error with ROS.
* * <topicName> - A message came from rosbridge with the given topic name.
* * <serviceID> - A service response came from rosbridge with the given ID.
*/
export default class Ros extends EventEmitter<
{
open: [TransportEvent];
connection: [TransportEvent];
close: [TransportEvent];
error: [TransportEvent];
// Any dynamically-named event should correspond to a rosbridge protocol message
Expand Down Expand Up @@ -101,7 +101,7 @@ export default class Ros extends EventEmitter<

transport.on("open", (event: TransportEvent) => {
this.#isConnected = true;
this.emit("open", event);
this.emit("connection", event);
});

transport.on("close", (event: TransportEvent) => {
Expand Down Expand Up @@ -191,7 +191,7 @@ export default class Ros extends EventEmitter<
if (this.isConnected()) {
this.transport?.send(message);
} else {
this.once("open", () => {
this.once("connection", () => {
this.transport?.send(message);
});
}
Expand Down
5 changes: 4 additions & 1 deletion test/ros.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ describe("Ros", function () {
const rosOnceSpy = vi.spyOn(ros, "once");
ros.callOnConnection({ op: "set_level", level: "info" });

expect(rosOnceSpy).toHaveBeenCalledWith("open", expect.any(Function));
expect(rosOnceSpy).toHaveBeenCalledWith(
"connection",
expect.any(Function),
);
expect(mockTransport.send).not.toHaveBeenCalled();

// Once connected, the message is sent
Expand Down
2 changes: 1 addition & 1 deletion test/setup/ros-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function waitForRosConnection(ros: Ros, timeout = 5000) {
reject(new Error("Timeout waiting for ROS connection"));
}, timeout);

ros.on("open", () => {
ros.on("connection", () => {
clearTimeout(timeoutId);
resolve();
});
Expand Down
Loading