diff --git a/Cargo.lock b/Cargo.lock index c464be3..3058ef4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2852,7 +2852,7 @@ dependencies = [ [[package]] name = "zenoh" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "ahash", "async-trait", @@ -2899,7 +2899,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "zenoh-collections", ] @@ -2907,7 +2907,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "tracing", "uhlc", @@ -2918,12 +2918,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" [[package]] name = "zenoh-config" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "json5", "num_cpus", @@ -2945,7 +2945,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "lazy_static", "tokio", @@ -2956,7 +2956,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "aes", "hmac", @@ -2969,7 +2969,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "bincode", @@ -2988,7 +2988,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "hashbrown", "keyed-set", @@ -3002,7 +3002,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "zenoh-config", "zenoh-link-commons", @@ -3019,7 +3019,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "flume", @@ -3043,7 +3043,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "base64 0.22.1", @@ -3070,7 +3070,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "socket2", @@ -3087,7 +3087,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "base64 0.22.1", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "socket2", @@ -3135,7 +3135,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "nix", @@ -3153,7 +3153,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "futures-util", @@ -3173,7 +3173,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "proc-macro2", "quote", @@ -3215,7 +3215,7 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "git-version", "libloading", @@ -3231,7 +3231,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "const_format", "rand", @@ -3245,7 +3245,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "anyhow", ] @@ -3253,7 +3253,7 @@ dependencies = [ [[package]] name = "zenoh-runtime" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "lazy_static", "ron", @@ -3266,7 +3266,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "event-listener", "futures", @@ -3279,7 +3279,7 @@ dependencies = [ [[package]] name = "zenoh-task" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "futures", "tokio", @@ -3292,7 +3292,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "crossbeam-utils", @@ -3325,7 +3325,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "const_format", @@ -3350,7 +3350,7 @@ dependencies = [ [[package]] name = "zenoh_backend_traits" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#a6bc509b5997c922a56253455149858af715edfa" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#de8e257d7baeb1d6afd0d8d42712018f2a4e8136" dependencies = [ "async-trait", "const_format", diff --git a/zenoh-plugin-remote-api/src/handle_control_message.rs b/zenoh-plugin-remote-api/src/handle_control_message.rs index eb1c2fe..7b4f114 100644 --- a/zenoh-plugin-remote-api/src/handle_control_message.rs +++ b/zenoh-plugin-remote-api/src/handle_control_message.rs @@ -27,7 +27,7 @@ use zenoh::{ use crate::{ interface::{ B64String, ControlMsg, DataMsg, HandlerChannel, LivelinessMsg, QueryWS, QueryableMsg, - RemoteAPIMsg, ReplyWS, SampleWS, + RemoteAPIMsg, ReplyWS, SampleWS, SessionInfo, }, spawn_future, RemoteState, StateMap, }; @@ -65,11 +65,39 @@ pub(crate) async fn handle_control_message( return Ok(()); } }; + // Handle Control Message match ctrl_msg { ControlMsg::OpenSession => { return Ok(()); } + ControlMsg::SessionInfo => { + let session_info = state_map.session.info(); + + let zid = session_info.zid().await.to_string(); + let z_peers: Vec = session_info + .peers_zid() + .await + .map(|x| x.to_string()) + .collect(); + let z_routers: Vec = session_info + .routers_zid() + .await + .map(|x| x.to_string()) + .collect(); + + let session_info = SessionInfo { + zid, + z_routers, + z_peers, + }; + + let remote_api_message = RemoteAPIMsg::Data(DataMsg::SessionInfo(session_info)); + + if let Err(e) = state_map.websocket_tx.send(remote_api_message) { + error!("Forward Sample Channel error: {e}"); + }; + } ControlMsg::CloseSession => { if let Some(state_map) = state_writer.remove(&sock_addr) { state_map.cleanup().await; diff --git a/zenoh-plugin-remote-api/src/handle_data_message.rs b/zenoh-plugin-remote-api/src/handle_data_message.rs index d0a177a..6c46dbf 100644 --- a/zenoh-plugin-remote-api/src/handle_data_message.rs +++ b/zenoh-plugin-remote-api/src/handle_data_message.rs @@ -147,7 +147,10 @@ pub async fn handle_data_message( warn!("Plugin should not receive Query from Client, This should go via Get API"); } }, - DataMsg::Sample(_, _) | DataMsg::GetReply(_) | DataMsg::NewTimestamp(_) => { + DataMsg::Sample(_, _) + | DataMsg::GetReply(_) + | DataMsg::NewTimestamp(_) + | DataMsg::SessionInfo(_) => { error!("Server Should not recieved a {data_msg:?} Variant from client"); } } diff --git a/zenoh-plugin-remote-api/src/interface/mod.rs b/zenoh-plugin-remote-api/src/interface/mod.rs index 94a8a8b..4d0c5d9 100644 --- a/zenoh-plugin-remote-api/src/interface/mod.rs +++ b/zenoh-plugin-remote-api/src/interface/mod.rs @@ -85,11 +85,23 @@ pub enum DataMsg { Sample(SampleWS, Uuid), // GetReply GetReply(ReplyWS), + // + SessionInfo(SessionInfo), + // Bidirectional Queryable(QueryableMsg), NewTimestamp(String), } +#[derive(TS)] +#[ts(export)] +#[derive(Debug, Serialize, Deserialize)] +pub struct SessionInfo { + pub zid: String, + pub z_routers: Vec, + pub z_peers: Vec, +} + #[derive(TS)] #[ts(export)] #[derive(Debug, Serialize, Deserialize)] @@ -121,6 +133,9 @@ pub enum ControlMsg { Session(Uuid), NewTimestamp, + // + SessionInfo, + // Session Action Messages Get { #[ts(as = "OwnedKeyExprWrapper")] diff --git a/zenoh-ts/.npmrc b/zenoh-ts/.npmrc deleted file mode 100644 index a43f271..0000000 --- a/zenoh-ts/.npmrc +++ /dev/null @@ -1 +0,0 @@ -@eclipse-zenoh:registry=https://registry.npmjs.com/ \ No newline at end of file diff --git a/zenoh-ts/examples/deno/src/z_info.ts b/zenoh-ts/examples/deno/src/z_info.ts new file mode 100644 index 0000000..889f0f8 --- /dev/null +++ b/zenoh-ts/examples/deno/src/z_info.ts @@ -0,0 +1,44 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +import { + SessionInfo, Config, Session +} from "@eclipse-zenoh/zenoh-ts"; + +export async function main() { + console.log!("Opening session..."); + const session = await Session.open(new Config("ws/127.0.0.1:10000")); + + console.log!("Get Info..."); + let info: SessionInfo = await session.info(); + + console.log!("zid: {}", info.zid()); + + console.log!( + "routers zid: {:?}", + info.routers_zid() + ); + + console.log!( + "peers zid: {:?}", + info.peers_zid() + ); + +} + +function sleep(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +main() \ No newline at end of file diff --git a/zenoh-ts/src/index.ts b/zenoh-ts/src/index.ts index 68a20f0..421763c 100644 --- a/zenoh-ts/src/index.ts +++ b/zenoh-ts/src/index.ts @@ -18,7 +18,7 @@ import { ZBytes, IntoZBytes, deserialize_bool, deserialize_uint, deserialize_int import { CongestionControl, ConsolidationMode, Priority, Reliability, Sample, SampleKind } from "./sample.js"; import { Publisher, Subscriber, FifoChannel, RingChannel } from "./pubsub.js"; import { IntoSelector, Parameters, IntoParameters, Query, Queryable, Reply, ReplyError, Selector } from "./query.js"; -import { Session, RecvErr, Receiver, DeleteOptions, PutOptions, GetOptions, QueryableOptions, PublisherOptions } from "./session.js"; +import { Session, RecvErr, Receiver, DeleteOptions, PutOptions, GetOptions, QueryableOptions, PublisherOptions, ZenohId, SessionInfo } from "./session.js"; import { Config } from "./config.js"; import { Encoding, IntoEncoding } from "./encoding.js"; import { Liveliness, LivelinessToken } from "./liveliness.js"; @@ -27,13 +27,14 @@ import { Querier, QueryTarget, Locality, ReplyKeyExpr, QuerierOptions, QuerierGe // Re-export duration external library import { Duration } from 'typed-duration' + // Exports export { KeyExpr, IntoKeyExpr }; export { ZBytes, IntoZBytes, deserialize_bool, deserialize_uint, deserialize_int, deserialize_float, deserialize_string }; export { CongestionControl, ConsolidationMode, Priority, Reliability, Sample, SampleKind }; export { Publisher, Subscriber, FifoChannel, RingChannel }; export { IntoSelector, Parameters, IntoParameters, Query, Queryable, Reply, ReplyError, Selector }; -export { Session, RecvErr, Receiver, DeleteOptions as DeleteOpts, PutOptions, GetOptions, QueryableOptions, PublisherOptions }; +export { Session, RecvErr, Receiver, DeleteOptions as DeleteOpts, PutOptions, GetOptions, QueryableOptions, PublisherOptions, ZenohId, SessionInfo}; export { Config }; export { Encoding, IntoEncoding }; export { Liveliness, LivelinessToken }; diff --git a/zenoh-ts/src/remote_api/interface/ControlMsg.ts b/zenoh-ts/src/remote_api/interface/ControlMsg.ts index 1e31117..8bb8888 100644 --- a/zenoh-ts/src/remote_api/interface/ControlMsg.ts +++ b/zenoh-ts/src/remote_api/interface/ControlMsg.ts @@ -4,4 +4,4 @@ import type { HandlerChannel } from "./HandlerChannel.js"; import type { LivelinessMsg } from "./LivelinessMsg.js"; import type { OwnedKeyExprWrapper } from "./OwnedKeyExprWrapper.js"; -export type ControlMsg = "OpenSession" | "CloseSession" | { "Session": string } | "NewTimestamp" | { "Get": { key_expr: OwnedKeyExprWrapper, parameters: string | null, handler: HandlerChannel, id: string, consolidation: number | undefined, timeout: number | undefined, congestion_control: number | undefined, priority: number | undefined, target: number | undefined, express: boolean | undefined, encoding: string | undefined, payload: string | undefined, attachment: string | undefined, } } | { "GetFinished": { id: string, } } | { "Put": { key_expr: OwnedKeyExprWrapper, payload: B64String, encoding: string | undefined, congestion_control: number | undefined, priority: number | undefined, express: boolean | undefined, attachment: string | undefined, } } | { "Delete": { key_expr: OwnedKeyExprWrapper, congestion_control: number | undefined, priority: number | undefined, express: boolean | undefined, attachment: string | undefined, } } | { "DeclareSubscriber": { key_expr: OwnedKeyExprWrapper, handler: HandlerChannel, id: string, } } | { "Subscriber": string } | { "UndeclareSubscriber": string } | { "DeclarePublisher": { key_expr: OwnedKeyExprWrapper, encoding: string | undefined, congestion_control: number | undefined, priority: number | undefined, reliability: number | undefined, express: boolean | undefined, id: string, } } | { "UndeclarePublisher": string } | { "DeclareQueryable": { key_expr: OwnedKeyExprWrapper, id: string, complete: boolean, handler: HandlerChannel, } } | { "UndeclareQueryable": string } | { "DeclareQuerier": { id: string, key_expr: OwnedKeyExprWrapper, target: number | undefined, timeout: number | undefined, accept_replies: number | undefined, allowed_destination: number | undefined, congestion_control: number | undefined, priority: number | undefined, consolidation: number | undefined, express: boolean | undefined, } } | { "UndeclareQuerier": string } | { "QuerierGet": { querier_id: string, get_id: string, encoding: string | undefined, payload: string | undefined, attachment: string | undefined, } } | { "Liveliness": LivelinessMsg }; +export type ControlMsg = "OpenSession" | "CloseSession" | { "Session": string } | "NewTimestamp" | "SessionInfo" | { "Get": { key_expr: OwnedKeyExprWrapper, parameters: string | null, handler: HandlerChannel, id: string, consolidation: number | undefined, timeout: number | undefined, congestion_control: number | undefined, priority: number | undefined, target: number | undefined, express: boolean | undefined, encoding: string | undefined, payload: string | undefined, attachment: string | undefined, } } | { "GetFinished": { id: string, } } | { "Put": { key_expr: OwnedKeyExprWrapper, payload: B64String, encoding: string | undefined, congestion_control: number | undefined, priority: number | undefined, express: boolean | undefined, attachment: string | undefined, } } | { "Delete": { key_expr: OwnedKeyExprWrapper, congestion_control: number | undefined, priority: number | undefined, express: boolean | undefined, attachment: string | undefined, } } | { "DeclareSubscriber": { key_expr: OwnedKeyExprWrapper, handler: HandlerChannel, id: string, } } | { "Subscriber": string } | { "UndeclareSubscriber": string } | { "DeclarePublisher": { key_expr: OwnedKeyExprWrapper, encoding: string | undefined, congestion_control: number | undefined, priority: number | undefined, reliability: number | undefined, express: boolean | undefined, id: string, } } | { "UndeclarePublisher": string } | { "DeclareQueryable": { key_expr: OwnedKeyExprWrapper, id: string, complete: boolean, handler: HandlerChannel, } } | { "UndeclareQueryable": string } | { "DeclareQuerier": { id: string, key_expr: OwnedKeyExprWrapper, target: number | undefined, timeout: number | undefined, accept_replies: number | undefined, allowed_destination: number | undefined, congestion_control: number | undefined, priority: number | undefined, consolidation: number | undefined, express: boolean | undefined, } } | { "UndeclareQuerier": string } | { "QuerierGet": { querier_id: string, get_id: string, encoding: string | undefined, payload: string | undefined, attachment: string | undefined, } } | { "Liveliness": LivelinessMsg }; diff --git a/zenoh-ts/src/remote_api/interface/DataMsg.ts b/zenoh-ts/src/remote_api/interface/DataMsg.ts index bae3e7a..e7b9124 100644 --- a/zenoh-ts/src/remote_api/interface/DataMsg.ts +++ b/zenoh-ts/src/remote_api/interface/DataMsg.ts @@ -3,5 +3,6 @@ import type { B64String } from "./B64String.js"; import type { QueryableMsg } from "./QueryableMsg.js"; import type { ReplyWS } from "./ReplyWS.js"; import type { SampleWS } from "./SampleWS.js"; +import type { SessionInfo } from "./SessionInfo.js"; -export type DataMsg = { "PublisherPut": { id: string, payload: B64String, attachment: B64String | null, encoding: string | null, } } | { "PublisherDelete": { id: string, attachment: B64String | null, timestamp: string | null, } } | { "Sample": [SampleWS, string] } | { "GetReply": ReplyWS } | { "Queryable": QueryableMsg } | { "NewTimestamp": string }; +export type DataMsg = { "PublisherPut": { id: string, payload: B64String, attachment: B64String | null, encoding: string | null, } } | { "PublisherDelete": { id: string, attachment: B64String | null, timestamp: string | null, } } | { "Sample": [SampleWS, string] } | { "GetReply": ReplyWS } | { "SessionInfo": SessionInfo } | { "Queryable": QueryableMsg } | { "NewTimestamp": string }; diff --git a/zenoh-ts/src/remote_api/session.ts b/zenoh-ts/src/remote_api/session.ts index cff6078..c3005de 100644 --- a/zenoh-ts/src/remote_api/session.ts +++ b/zenoh-ts/src/remote_api/session.ts @@ -32,8 +32,10 @@ import { ReplyWS } from "./interface/ReplyWS.js"; import { QueryableMsg } from "./interface/QueryableMsg.js"; import { QueryReplyWS } from "./interface/QueryReplyWS.js"; import { HandlerChannel } from "./interface/HandlerChannel.js"; +import { SessionInfo as SessionInfoIface } from "./interface/SessionInfo.js"; import { RemoteQuerier } from "./querier.js" + // ██████ ███████ ███ ███ ██████ ████████ ███████ ███████ ███████ ███████ ███████ ██ ██████ ███ ██ // ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ // ██████ █████ ██ ████ ██ ██ ██ ██ █████ ███████ █████ ███████ ███████ ██ ██ ██ ██ ██ ██ @@ -60,6 +62,7 @@ export class RemoteSession { get_receiver: Map>; liveliness_subscribers: Map>; liveliness_get_receiver: Map>; + session_info: SessionInfoIface | null; private constructor(ws: WebSocket, ws_channel: SimpleChannel) { this.ws = ws; @@ -70,6 +73,7 @@ export class RemoteSession { this.get_receiver = new Map>(); this.liveliness_subscribers = new Map>(); this.liveliness_get_receiver = new Map>(); + this.session_info = null; } // @@ -136,6 +140,19 @@ export class RemoteSession { // // Zenoh Session Functions // + // Info + async info(): Promise { + let ctrl_message: ControlMsg = "SessionInfo"; + this.session_info = null; + this.send_ctrl_message(ctrl_message); + + while (this.session_info === null) { + await sleep(10); + } + + return this.session_info; + } + // Put put(key_expr: string, payload: Array, @@ -152,7 +169,7 @@ export class RemoteSession { opt_attachment = b64_str_from_bytes(new Uint8Array(attachment)) } - let data_message: ControlMsg = { + let ctrl_message: ControlMsg = { Put: { key_expr: owned_keyexpr, payload: b64_str_from_bytes(new Uint8Array(payload)), @@ -163,7 +180,7 @@ export class RemoteSession { attachment: opt_attachment, }, }; - this.send_ctrl_message(data_message); + this.send_ctrl_message(ctrl_message); } // get @@ -436,6 +453,7 @@ export class RemoteSession { return channel; } + // // Sending Messages // @@ -546,12 +564,20 @@ export class RemoteSession { } else { console.warn("Queryable message Variant not recognized"); } + } else if ("SessionInfo" in data_msg) { + + let session_info: SessionInfoIface = data_msg["SessionInfo"]; + this.session_info = session_info; + } else { console.warn("Data Message not recognized Expected Variant", data_msg); } } } + + + function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } diff --git a/zenoh-ts/src/session.ts b/zenoh-ts/src/session.ts index 1bf57c2..96e9c0c 100644 --- a/zenoh-ts/src/session.ts +++ b/zenoh-ts/src/session.ts @@ -52,6 +52,7 @@ import { Config } from "./config.js"; import { Encoding } from "./encoding.js"; import { QueryReplyWS } from "./remote_api/interface/QueryReplyWS.js"; import { HandlerChannel } from "./remote_api/interface/HandlerChannel.js"; +import { SessionInfo as SessionInfoIface } from "./remote_api/interface/SessionInfo.js"; // External deps import { Duration, TimeDuration } from 'typed-duration' import { SimpleChannel } from "channel-ts"; @@ -250,6 +251,23 @@ export class Session { ); } + /** + * Returns the Zenoh SessionInfo Object + * + * @returns SessionInfo + */ + async info(): Promise { + let session_info_iface: SessionInfoIface = await this.remote_session.info(); + + let zid = new ZenohId(session_info_iface.zid); + let z_peers = session_info_iface.z_peers.map(x => new ZenohId(x)); + let z_routers = session_info_iface.z_routers.map(x => new ZenohId(x)); + + let session_info = new SessionInfo(zid, z_peers, z_routers); + + return session_info; + } + /** * Executes a Delete on a session, for a specific key expression KeyExpr * @@ -750,3 +768,44 @@ export class Receiver { export function open(config: Config): Promise { return Session.open(config); } + +/** + * Struct to expose Info for your Zenoh Session + */ +export class SessionInfo { + private _zid: ZenohId + private _routers: ZenohId[] + private _peers: ZenohId[] + + constructor( + zid: ZenohId, + peers: ZenohId[], + routers: ZenohId[], + ) { + this._zid = zid; + this._routers = routers; + this._peers = peers; + } + + zid(): ZenohId { + return this._zid; + } + routers_zid(): ZenohId[] { + return this._routers; + } + peers_zid(): ZenohId[] { + return this._peers; + } +} + +export class ZenohId { + private zid: string + + constructor(zid: string) { + this.zid = zid; + } + + toString(): string { + return this.zid; + } +} \ No newline at end of file