Skip to content

Commit 7d29053

Browse files
authored
Merge pull request #1 from JdeRobot/update-tools
Update to include the tools
2 parents ad9a872 + 460b2df commit 7d29053

File tree

11 files changed

+72
-36
lines changed

11 files changed

+72
-36
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
dist/
1+
dist/
2+
node_modules/

node_modules/.package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"name": "jderobot-commsmanager",
3-
"version": "0.1.6",
3+
"version": "1.0.0",
44
"main": "dist/main.js",
55
"typings": "dist/index.d.ts",
66
"scripts": {
77
"test": "echo \"Error: no test specified\"",
88
"build": "webpack --mode development --config webpack.config.js",
9-
"postbuild": "cp package.json dist"
9+
"postbuild": "cp package.json dist",
10+
"format": "prettier --write src/**/*.{ts,tsx}"
1011
},
11-
"files": ["dist"],
12+
"files": [
13+
"dist"
14+
],
1215
"keywords": [],
1316
"author": "",
1417
"license": "ISC",
@@ -17,8 +20,9 @@
1720
"uuid": "^11.1.0"
1821
},
1922
"devDependencies": {
23+
"prettier": "^3.6.1",
2024
"ts-loader": "^9.5.2",
2125
"typescript": "^5.8.3",
2226
"webpack-cli": "^5.1.4"
2327
}
24-
}
28+
}

src/components/CommsManager.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { v4 as uuidv4 } from "uuid";
22
import { publish } from "../utils";
3-
import { Events, events, ManagerMsg, PromiseHandlers, UniverseConfig } from "../types";
4-
3+
import {
4+
Events,
5+
events,
6+
ManagerMsg,
7+
PromiseHandlers,
8+
UniverseConfig,
9+
} from "../types";
510

611
export default class CommsManager {
712
private static instance: CommsManager | undefined;
@@ -53,7 +58,7 @@ export default class CommsManager {
5358
this.ws.onclose = (e) => {
5459
if (e.wasClean) {
5560
console.log(
56-
`Connection with ${address} closed, all suscribers cleared`
61+
`Connection with ${address} closed, all suscribers cleared`,
5762
);
5863
} else {
5964
console.log(`Connection with ${address} interrupted`);
@@ -100,7 +105,7 @@ export default class CommsManager {
100105
for (let i = 0, length = events.length; i < length; i++) {
101106
this.observers[events[i]] = this.observers[events[i]] || [];
102107
this.observers[events[i]].splice(
103-
this.observers[events[i]].indexOf(callback)
108+
this.observers[events[i]].indexOf(callback),
104109
);
105110
}
106111
};
@@ -136,10 +141,10 @@ export default class CommsManager {
136141
}
137142

138143
private setManagerState(msg: ManagerMsg) {
139-
publish("CommsManagerStateChange", {state: msg.data.state})
144+
publish("CommsManagerStateChange", { state: msg.data.state });
140145
CommsManager.state = msg.data.state;
141146
if (msg.data.state === "connected") {
142-
CommsManager.universe = undefined
147+
CommsManager.universe = undefined;
143148
}
144149
}
145150

@@ -165,25 +170,22 @@ export default class CommsManager {
165170
}
166171

167172
public launchWorld(cfg: UniverseConfig) {
168-
CommsManager.universe = cfg.name
173+
CommsManager.universe = cfg.name;
169174
return this.send("launch_world", cfg);
170175
}
171176

172-
public prepareVisualization(
173-
visualization_type: string,
174-
visualization_config: string | null
175-
) {
176-
if (visualization_config === null || visualization_config === undefined) {
177-
visualization_config = "None";
177+
public prepareTools(tools: string[], tools_config: Object) {
178+
if (tools_config === null || tools_config === undefined) {
179+
tools_config = "None";
178180
}
179-
return this.send("prepare_visualization", {
180-
type: visualization_type,
181-
file: visualization_config,
181+
return this.send("prepare_tools", {
182+
tools: tools,
183+
config: tools_config,
182184
});
183185
}
184186

185-
public run(cfg: Object) {
186-
return this.send("run_application", cfg);
187+
public run(entrypoint: string, code: string) {
188+
return this.send("run_application", { entrypoint: entrypoint, code: code });
187189
}
188190

189191
public stop() {
@@ -236,4 +238,4 @@ export default class CommsManager {
236238
public code_autocomplete(code: string, line: number, col: number) {
237239
return this.send("code_autocomplete", { code: code, line: line, col: col });
238240
}
239-
}
241+
}

src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {default as CommsManager} from './CommsManager'
1+
export { default as CommsManager } from "./CommsManager";

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './components'
2-
export * from './types'
1+
export * from "./components";
2+
export * from "./types";

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export type {
66
UniverseConfig,
77
Events,
88
} from "./types";
9-
export {events, states} from './types'
9+
export { events, states } from "./types";

src/types/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export type PromiseHandlers = {
32
resolve: (value?: any) => void;
43
reject: (reason?: any) => void;
@@ -22,7 +21,6 @@ export interface RobotConfig {
2221
name: string | null;
2322
launch_file_path: string | null;
2423
ros_version: string | null;
25-
visualization: string | null;
2624
world: string | null;
2725
start_pose: string | null;
2826
}
@@ -49,7 +47,7 @@ export const states = {
4947
IDLE: "idle",
5048
CONNECTED: "connected",
5149
WORLD_READY: "world_ready",
52-
VISUALIZATION_READY: "visualization_ready",
50+
TOOLS_READY: "tools_ready",
5351
RUNNING: "application_running",
5452
PAUSED: "paused",
55-
};
53+
};

src/utils/events.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export function subscribe(eventName: string, listener: (e:any) => void) {
1+
export function subscribe(eventName: string, listener: (e: any) => void) {
22
document.addEventListener(eventName, listener);
33
}
44

55
export function unsubscribe(eventName: string, listener: () => void) {
66
document.removeEventListener(eventName, listener);
77
}
88

9-
export function publish(eventName:string, extra: any = undefined) {
10-
const event = new CustomEvent(eventName, {detail: extra});
9+
export function publish(eventName: string, extra: any = undefined) {
10+
const event = new CustomEvent(eventName, { detail: extra });
1111
document.dispatchEvent(event);
1212
}

0 commit comments

Comments
 (0)