Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Schleich committed Jan 7, 2025
2 parents 18add8e + 6be3474 commit 2357228
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 36 deletions.
54 changes: 27 additions & 27 deletions Cargo.lock

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

30 changes: 29 additions & 1 deletion zenoh-plugin-remote-api/src/handle_control_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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<String> = session_info
.peers_zid()
.await
.map(|x| x.to_string())
.collect();
let z_routers: Vec<String> = 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;
Expand Down
5 changes: 4 additions & 1 deletion zenoh-plugin-remote-api/src/handle_data_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
15 changes: 15 additions & 0 deletions zenoh-plugin-remote-api/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub z_peers: Vec<String>,
}

#[derive(TS)]
#[ts(export)]
#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -121,6 +133,9 @@ pub enum ControlMsg {
Session(Uuid),
NewTimestamp,

//
SessionInfo,

// Session Action Messages
Get {
#[ts(as = "OwnedKeyExprWrapper")]
Expand Down
1 change: 0 additions & 1 deletion zenoh-ts/.npmrc

This file was deleted.

44 changes: 44 additions & 0 deletions zenoh-ts/examples/deno/src/z_info.ts
Original file line number Diff line number Diff line change
@@ -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, <[email protected]>
//

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()
Loading

0 comments on commit 2357228

Please sign in to comment.