Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS API code review Fixes #5

Merged
merged 11 commits into from
Oct 29, 2024
Merged
19 changes: 11 additions & 8 deletions zenoh-plugin-remote-api/EXAMPLE_CONFIG.json5
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
mode: "router",
mode: 'router',
plugins_loading: {
enabled: true,
search_dirs: ["./target/debug", "~/.zenoh/lib"],
},
enabled: true,
search_dirs: ['./target/debug', '~/.zenoh/lib']
},
plugins: {
remote_api: {
"websocket_port": "10000",
},
},
websocket_port: '10000',
secure_websocket: {
certificate_path: 'path/to/certificate_path',
private_key_path: 'path/to/private_key_path'
}
}
}
}

13 changes: 6 additions & 7 deletions zenoh-ts/examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions zenoh-ts/examples/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ async function main() {
let count = 0;
while (true) {
await sleep(1000 * 100);
console.log("Main Loop tick ", count);
console.warn("Main Loop tick ", count);
count = count + 1;
}
}

main()
.then(() => console.log("Done"))
.then(() => console.warn("Done"))
.catch((e) => {
console.log(e);
console.warn(e);
throw e;
});

Expand Down
4 changes: 2 additions & 2 deletions zenoh-ts/examples/src/z_delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import "./style.css";
import "./webpage.ts";

import { Config, Session } from "@ZettaScaleLabs/zenoh-ts";
import { Config, Session } from "@eclipse-zenoh/zenoh-ts";

export async function _delete() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));
session.delete("demo/example/zenoh-ts-delete");
await session.close();
}
20 changes: 10 additions & 10 deletions zenoh-ts/examples/src/z_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@
// ZettaScale Zenoh Team, <[email protected]>
//

import { ReplyError } from "@ZettaScaleLabs/zenoh-ts";
import { deserialize_string } from "@ZettaScaleLabs/zenoh-ts";
import { ReplyError } from "@eclipse-zenoh/zenoh-ts";
import { deserialize_string } from "@eclipse-zenoh/zenoh-ts";
import "./style.css";
import "./webpage.ts";

import { Config, Receiver, RecvErr, Reply, Sample, Session } from "@ZettaScaleLabs/zenoh-ts";
import { Config, Receiver, RecvErr, Reply, Sample, Session } from "@eclipse-zenoh/zenoh-ts";

export async function get() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));

// Callback get query
const get_callback = async function (reply: Reply): Promise<void> {
let resp = reply.result();
if (resp instanceof Sample) {
let sample: Sample = resp;
console.log(">> Received ('", sample.keyexpr(), ":", sample.payload().deserialize(deserialize_string),"')");
console.warn(">> Received ('", sample.keyexpr(), ":", sample.payload().deserialize(deserialize_string),"')");
} else {
let reply_error: ReplyError = resp;
console.log(">> Received (ERROR: '", reply_error.payload().deserialize(deserialize_string), "')");
console.warn(">> Received (ERROR: '", reply_error.payload().deserialize(deserialize_string), "')");
}
};

console.log("Start z_get")
console.warn("Start z_get")
await session.get("demo/example/**", get_callback);

// Poll receiever
Expand All @@ -46,15 +46,15 @@ export async function get() {
let reply = await receiver.receive();
while (reply != RecvErr.Disconnected) {
if (reply == RecvErr.MalformedReply) {
console.log("MalformedReply");
console.warn("MalformedReply");
} else {
let resp = reply.result();
if (resp instanceof Sample) {
let sample: Sample = resp;
console.log(">> Received ('", sample.keyexpr(), ":", sample.payload().deserialize(deserialize_string),"')");
console.warn(">> Received ('", sample.keyexpr(), ":", sample.payload().deserialize(deserialize_string),"')");
} else {
let reply_error: ReplyError = resp;
console.log(">> Received (ERROR: '{", reply_error.payload().deserialize(deserialize_string), "}')");
console.warn(">> Received (ERROR: '{", reply_error.payload().deserialize(deserialize_string), "}')");
}
}
reply = await receiver.receive();
Expand Down
10 changes: 5 additions & 5 deletions zenoh-ts/examples/src/z_ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// ZettaScale Zenoh Team, <[email protected]>
//

import { FifoChannel } from "@ZettaScaleLabs/zenoh-ts";
import { FifoChannel } from "@eclipse-zenoh/zenoh-ts";
import "./style.css";
import "./webpage.ts";

import { Encoding, CongestionControl, Config, Session } from "@ZettaScaleLabs/zenoh-ts";
import { Encoding, CongestionControl, Config, Session } from "@eclipse-zenoh/zenoh-ts";

export async function ping() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));

let sub = await session.declare_subscriber("test/pong", new FifoChannel(256));
let pub = session.declare_publisher(
Expand All @@ -31,7 +31,7 @@ export async function ping() {
);

// Warm up
console.log("Warming up for 5 seconds...");
console.warn("Warming up for 5 seconds...");

let startTime = new Date();
let data = [122, 101, 110, 111, 104];
Expand All @@ -52,7 +52,7 @@ export async function ping() {

for (let i = 0; i < samples_out.length; i++) {
let rtt = samples_out[i];
console.log(
console.warn(
data.length +
"bytes: seq=" +
i +
Expand Down
4 changes: 2 additions & 2 deletions zenoh-ts/examples/src/z_pong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import "./style.css";
import "./webpage.ts";

import { Encoding, CongestionControl, Sample, Config, Session } from "@ZettaScaleLabs/zenoh-ts";
import { Encoding, CongestionControl, Sample, Config, Session } from "@eclipse-zenoh/zenoh-ts";

export async function pong() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));

let pub = await session.declare_publisher(
"test/ping",
Expand Down
10 changes: 5 additions & 5 deletions zenoh-ts/examples/src/z_pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import "./style.css";
import "./webpage.ts";

import { Priority, Reliability, Encoding, CongestionControl, Config, KeyExpr, Publisher, Session } from "@ZettaScaleLabs/zenoh-ts";
import { Priority, Reliability, Encoding, CongestionControl, Config, KeyExpr, Publisher, Session } from "@eclipse-zenoh/zenoh-ts";

export async function pub() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));

let key_expr = KeyExpr.new("demo/example/zenoh-ts-pub");
let key_expr = new KeyExpr("demo/example/zenoh-ts-pub");
let publisher: Publisher = session.declare_publisher(
key_expr,
{
Expand All @@ -37,8 +37,8 @@ export async function pub() {
for (let idx = 0; idx < Number.MAX_VALUE; idx++) {
let buf = `[${idx}] ${payload}`;

console.log("Block statement execution no : " + idx);
console.log(`Putting Data ('${key_expr}': '${buf}')...`);
console.warn("Block statement execution no : " + idx);
console.warn(`Putting Data ('${key_expr}': '${buf}')...`);
publisher.put(buf, Encoding.TEXT_PLAIN, "attachment");
await sleep(1000);

Expand Down
6 changes: 3 additions & 3 deletions zenoh-ts/examples/src/z_put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import "./style.css";
import "./webpage.ts";
import { Config, Session } from "@ZettaScaleLabs/zenoh-ts";
import { Config, Session } from "@eclipse-zenoh/zenoh-ts";

export async function put() {
console.log('Running Zenoh Put !');
console.warn('Running Zenoh Put !');

const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));
session.put("demo/example/zenoh-ts-put", "Put from Typescript!");
}
20 changes: 10 additions & 10 deletions zenoh-ts/examples/src/z_queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import "./style.css";
import "./webpage.ts";

import { Config, KeyExpr, Query, Queryable, Session, ZBytes } from "@ZettaScaleLabs/zenoh-ts";
import { Config, KeyExpr, Query, Queryable, Session, ZBytes } from "@eclipse-zenoh/zenoh-ts";


export async function queryable() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
let key_expr = KeyExpr.new("demo/example/zenoh-ts-queryable");
console.log("Declare Queryable on KeyExpr:", key_expr.toString());
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));
let key_expr = new KeyExpr("demo/example/zenoh-ts-queryable");
console.warn("Declare Queryable on KeyExpr:", key_expr.toString());

const payload = [122, 101, 110, 111, 104];

Expand All @@ -30,14 +30,14 @@ export async function queryable() {
let zbytes: ZBytes | undefined = query.payload();

if (zbytes == null) {
console.log!(`>> [Queryable ] Received Query ${query.selector()}`);
console.warn!(`>> [Queryable ] Received Query ${query.selector()}`);
} else {
console.log!(
console.warn!(
`>> [Queryable ] Received Query ${query.selector()} with payload '${zbytes}'`,
);
}

console.log(
console.warn(
`>> [Queryable ] Responding ${key_expr.toString()} with payload '${payload}'`,
);
query.reply(key_expr, payload);
Expand All @@ -62,14 +62,14 @@ export async function queryable() {
let zbytes: ZBytes | undefined = query.payload();

if (zbytes == null) {
console.log!(`>> [Queryable ] Received Query ${query.selector().toString()}`);
console.warn!(`>> [Queryable ] Received Query ${query.selector().toString()}`);
} else {
console.log!(
console.warn!(
`>> [Queryable ] Received Query ${query.selector()} with payload '${zbytes.buffer()}'`,
);
}

console.log(
console.warn(
`>> [Queryable ] Responding ${key_expr.toString()} with payload '${payload}'`,
);
query.reply(key_expr, payload);
Expand Down
14 changes: 7 additions & 7 deletions zenoh-ts/examples/src/z_sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ import "./webpage.ts";

import {
RingChannel, deserialize_string, Sample, Config, Subscriber, Session, KeyExpr
} from "@ZettaScaleLabs/zenoh-ts";
} from "@eclipse-zenoh/zenoh-ts";

export async function sub() {
const session = await Session.open(Config.new("ws/127.0.0.1:10000"));
const session = await Session.open(new Config ("ws/127.0.0.1:10000"));

const callback = async function (sample: Sample): Promise<void> {
console.log!(
console.warn!(
">> [Subscriber] Received " +
sample.kind() + " ('" +
sample.keyexpr() + "': '" +
sample.payload().deserialize(deserialize_string) + "')",
);
};

let key_expr = KeyExpr.new("demo/example/zenoh-ts-sub");
console.log("Declare Subscriber ", key_expr.toString());
let key_expr = new KeyExpr("demo/example/zenoh-ts-sub");
console.warn("Declare Subscriber ", key_expr.toString());
// Callback Subscriber take a callback which will be called upon every sample received.
let callback_subscriber: Subscriber = await session.declare_subscriber(
key_expr,
Expand All @@ -41,15 +41,15 @@ export async function sub() {

await sleep(1000 * 3);
callback_subscriber.undeclare();
console.log("Undeclare callback_subscriber");
console.warn("Undeclare callback_subscriber");

// Poll Subscribers will only consume data on calls to receieve()
// This means that interally the FIFO queue will fill up to the point that new values will be dropped
// The dropping of these values occurs in the Remote-API Plugin
let poll_subscriber: Subscriber = await session.declare_subscriber("demo/example/zenoh-ts-sub", new RingChannel(10));
let sample = await poll_subscriber.receive();
while (sample != undefined) {
console.log!(
console.warn!(
">> [Subscriber] Received " +
sample.kind() + " ('" +
sample.keyexpr() + "': '" +
Expand Down
12 changes: 6 additions & 6 deletions zenoh-ts/examples/src/z_sub_thr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import "./style.css";
import "./webpage.ts";

import { Config, Session, Sample } from "@ZettaScaleLabs/zenoh-ts";
import { Config, Session, Sample } from "@eclipse-zenoh/zenoh-ts";

// Throughput test
class Stats {
Expand Down Expand Up @@ -52,19 +52,19 @@ class Stats {
print_round() {
let elapsed_ms = Date.now() - this.round_start;
let throughput = (this.round_size) / (elapsed_ms / 1000);
console.log(throughput, " msg/s");
console.warn(throughput, " msg/s");
}
}

export async function thr() {
console.log("Open Session");
const session : Session = await Session.open(Config.new("ws/127.0.0.1:10000"));
console.warn("Open Session");
const session : Session = await Session.open(new Config ("ws/127.0.0.1:10000"));
let stats = new Stats(100000);
const subscriber_callback = async function (_sample: Sample): Promise<void> {
stats.increment();
};

console.log("Declare subscriber");
console.warn("Declare subscriber");
await session.declare_subscriber(
"test/thr",
subscriber_callback,
Expand All @@ -74,7 +74,7 @@ export async function thr() {
while (true) {
var seconds = 100;
await sleep(1000 * seconds);
console.log("Main Loop ? ", count);
console.warn("Main Loop ? ", count);
count = count + 1;
}
}
Expand Down
Loading
Loading