WASM compatibilty
This commit is contained in:
parent
f59c28d966
commit
e4186a7ec0
@ -3,26 +3,26 @@
|
|||||||
//! This example demonstrates how to use the connector without TLS dependencies
|
//! This example demonstrates how to use the connector without TLS dependencies
|
||||||
//! for WebAssembly builds.
|
//! for WebAssembly builds.
|
||||||
|
|
||||||
use socktop_connector::{connect_to_socktop_agent, ConnectorConfig, AgentRequest};
|
use socktop_connector::{AgentRequest, ConnectorConfig, connect_to_socktop_agent};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("WASM-compatible socktop connector example");
|
println!("WASM-compatible socktop connector example");
|
||||||
|
|
||||||
// For WASM builds, use ws:// (not wss://) to avoid TLS dependencies
|
// For WASM builds, use ws:// (not wss://) to avoid TLS dependencies
|
||||||
let url = "ws://localhost:3000/ws";
|
let url = "ws://localhost:3000/ws";
|
||||||
|
|
||||||
// Method 1: Simple connection (recommended for most use cases)
|
// Method 1: Simple connection (recommended for most use cases)
|
||||||
let mut connector = connect_to_socktop_agent(url).await?;
|
let mut connector = connect_to_socktop_agent(url).await?;
|
||||||
|
|
||||||
// Method 2: With custom WebSocket configuration
|
// Method 2: With custom WebSocket configuration
|
||||||
let config = ConnectorConfig::new(url)
|
let config = ConnectorConfig::new(url)
|
||||||
.with_protocols(vec!["socktop".to_string()])
|
.with_protocols(vec!["socktop".to_string()])
|
||||||
.with_version("13".to_string());
|
.with_version("13".to_string());
|
||||||
|
|
||||||
let mut connector_custom = socktop_connector::SocktopConnector::new(config);
|
let mut connector_custom = socktop_connector::SocktopConnector::new(config);
|
||||||
connector_custom.connect().await?;
|
connector_custom.connect().await?;
|
||||||
|
|
||||||
// Make a request to get metrics
|
// Make a request to get metrics
|
||||||
match connector.request(AgentRequest::Metrics).await {
|
match connector.request(AgentRequest::Metrics).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("Request failed: {}", e);
|
println!("Request failed: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("WASM example completed successfully!");
|
println!("WASM example completed successfully!");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,8 @@ use prost::Message as _;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tokio_tungstenite::{
|
use tokio_tungstenite::{
|
||||||
MaybeTlsStream, WebSocketStream, connect_async,
|
MaybeTlsStream, WebSocketStream, connect_async, tungstenite::Message,
|
||||||
tungstenite::Message, tungstenite::client::IntoClientRequest,
|
tungstenite::client::IntoClientRequest,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user