-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.ts
More file actions
49 lines (39 loc) · 1.59 KB
/
Copy pathservice.ts
File metadata and controls
49 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { createTransport } from "./transport/factory.js";
import type { OpenclawPluginApi, PluginLogger } from "./plugin-api.js";
import type { TransportConfig, WebsocketConfig, TransportOps } from "../plugin-api.ts";
/** Shared transport instance for all tools. */
let transport: TransportOps | null = null;
/**
* The service handles connection lifecycle (connect on start, disconnect on stop).
*/
export function registerService(api: OpenclawPluginApi): void {
// Define websocket configuration with default values
const wsconfig: WebsocketConfig = {
url: "ws://localhost:9090",
reconnect: true,
reconnectInterval: 3000
};
api.registerService({
id: "ros2-transport",
async start(_ctx) {
let transportCfg: TransportConfig;
transportCfg = { "mode": "websocket", "config": wsconfig };
api.logger.info(`[hello-tool-plugin] Connecting to Node via ${transportCfg.mode} transport...`);
transport = await createTransport(transportCfg);
/*
transport.onConnection((status: string) => {
api.logger.info(`[hello-tool-plugin] transport status: ${status}`);
});
await transport.connect();
*/
api.logger.info(`[hello-tool-plugin] transport connected (mode: ${transportCfg.mode})`);
},
async stop(_ctx) {
if (transport) {
await transport.disconnect();
transport = null;
api.logger.info("[hello-tool-plugin] transport disconnected");
}
},
});
}