node-oar
v1.0.1
Published
nodejs oar client library
Downloads
5
Readme
Simple client to interact with the OAR hub websocket api
Installation
npm install node-oar
Usage
import {
OARClient,
OARClientOptions,
Message,
ServiceInfoResponse,
} from "node-oar";
const serviceInfo: ServiceInfoResponse = {
name: "My Own Server",
description: "This server can run command inside linux terminal",
actions: [
{
action: "executeCommand",
description: "Execute command inside linux terminal",
params: ["ls -l"],
},
{
action: "sum",
description: "Sum numbers",
params: [1, 2, 3],
},
],
};
const options: OARClientOptions = {
url: "ws://localhost:8765",
apiKey: "my-api-key",
serviceInfo,
};
const client = new OARClient(options);
client.on("open", () => {
console.log("Custom handler: Connection opened");
});
client.on("message", (message: Message, resolve) => {
console.log("Custom handler: Message received", message);
// Custom message handling logic
console.log("Send to server: ", { response: "success" });
resolve({ message: "success" });
});
client.on("error", (error: Error) => {
console.error("Custom handler: Error", error);
});
client.on("close", (code: number, reason: string) => {
console.log(`Custom handler: Connection closed ${code} - ${reason}`);
});