pub struct Client { /* private fields */ }
Expand description
Wrap json_client send request between nodes or browsers.
Implementations§
source§impl Client
impl Client
sourcepub fn new(endpoint_url: &str, delegated_sk: Option<SessionSk>) -> Self
pub fn new(endpoint_url: &str, delegated_sk: Option<SessionSk>) -> Self
Creates a new Client instance with the specified endpoint URL
sourcepub async fn connect_peer_via_http(&mut self, http_url: &str) -> Result<String>
pub async fn connect_peer_via_http(&mut self, http_url: &str) -> Result<String>
Establishes a WebRTC connection with a remote peer using HTTP as the signaling channel.
This function allows two peers to establish a WebRTC connection using HTTP, which can be useful in scenarios where a direct peer-to-peer connection is not possible due to firewall restrictions or other network issues. The function sends ICE candidates and Session Description Protocol (SDP) messages over HTTP as a form of signaling to establish the connection.
Takes a URL for an HTTP server that will be used as the signaling channel to exchange ICE candidates and SDP with the remote peer. Returns a Did that can be used to refer to this connection in subsequent WebRTC operations.
sourcepub async fn connect_with_seed(&mut self, seeds: &[Value]) -> Result<()>
pub async fn connect_with_seed(&mut self, seeds: &[Value]) -> Result<()>
Attempts to connect to a peer using a seed file located at the specified source path.
sourcepub async fn connect_with_did(&mut self, did: &str) -> Result<()>
pub async fn connect_with_did(&mut self, did: &str) -> Result<()>
Attempts to connect to a peer using a DID stored in a Distributed Hash Table (DHT).
sourcepub async fn list_peers(&mut self) -> Result<Vec<Peer>>
pub async fn list_peers(&mut self) -> Result<Vec<Peer>>
Lists all connected peers and their status.
Returns an Output containing a formatted string representation of the list of peers if successful, or an anyhow::Error if an error occurred.
sourcepub async fn disconnect(&mut self, did: &str) -> Result<()>
pub async fn disconnect(&mut self, did: &str) -> Result<()>
Disconnects from the peer with the specified DID.
sourcepub async fn send_message(
&self,
did: &str,
text: &str
) -> Result<SendMessageResponse>
pub async fn send_message( &self, did: &str, text: &str ) -> Result<SendMessageResponse>
Sends a message to the specified peer.
sourcepub async fn send_custom_message(
&self,
did: &str,
message_type: u16,
data: &str
) -> Result<SendMessageResponse>
pub async fn send_custom_message( &self, did: &str, message_type: u16, data: &str ) -> Result<SendMessageResponse>
Sends a custom message to the specified peer.
sourcepub async fn send_http_request_message(
&self,
did: &str,
name: &str,
method: Method,
url: &str,
timeout: Timeout,
headers: &[(&str, &str)],
body: Option<String>
) -> Result<SendMessageResponse>
pub async fn send_http_request_message( &self, did: &str, name: &str, method: Method, url: &str, timeout: Timeout, headers: &[(&str, &str)], body: Option<String> ) -> Result<SendMessageResponse>
Sends an HTTP request message to the specified peer.
sourcepub async fn send_simple_text_message(
&self,
did: &str,
text: &str
) -> Result<SendMessageResponse>
pub async fn send_simple_text_message( &self, did: &str, text: &str ) -> Result<SendMessageResponse>
Sends a simple text message to the specified peer.
sourcepub async fn register_service(&self, name: &str) -> Result<()>
pub async fn register_service(&self, name: &str) -> Result<()>
Registers a new service with the given name.
sourcepub async fn lookup_service(&self, name: &str) -> Result<Vec<String>>
pub async fn lookup_service(&self, name: &str) -> Result<Vec<String>>
Looks up the DIDs of services registered with the given name.
sourcepub async fn publish_message_to_topic(
&self,
topic: &str,
data: &str
) -> Result<()>
pub async fn publish_message_to_topic( &self, topic: &str, data: &str ) -> Result<()>
Publishes a message to the specified topic.