Skip to content

Commit

Permalink
docs(examples): add salvo echo examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore committed Oct 28, 2023
1 parent da6653a commit 507a64a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion examples/salvo-echo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
engineioxide = { path = "../../engineioxide", feature = ["hyper-v1"] }
engineioxide = { path = "../../engineioxide", features = [
"hyper-v1",
"tracing",
] }
salvo = { version = "0.58.2", features = ["tower-compat"] }
tokio = { version = "1.33.0", features = ["full"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
Expand Down
21 changes: 14 additions & 7 deletions examples/salvo-echo/salvo_echo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use salvo::prelude::*;
use salvo::tower_compat::TowerServiceCompat;

use std::sync::Arc;
use std::{sync::Arc, time::Duration};

use engineioxide::{
config::EngineIoConfig,
handler::EngineIoHandler,
service::EngineIoService,
layer::EngineIoLayer,
socket::{DisconnectReason, Socket},
};
use tracing::Level;
Expand Down Expand Up @@ -45,14 +45,21 @@ async fn hello() -> &'static str {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let subscriber = FmtSubscriber::builder()
.with_line_number(true)
.with_max_level(Level::DEBUG)
.with_max_level(Level::TRACE)
.finish();
tracing::subscriber::set_global_default(subscriber)?;

let svc = EngineIoService::new(MyHandler).compat();
let config = EngineIoConfig::builder()
.ping_interval(Duration::from_millis(300))
.ping_timeout(Duration::from_millis(200))
.max_payload(1e6 as u64)
.build();

let router = Router::new().get(hello);
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
let layer = EngineIoLayer::from_config(MyHandler, config).compat();

//TODO: currently the layer is never called
let router = Router::new().hoop(layer).get(hello);
let acceptor = TcpListener::new("127.0.0.1:3000").bind().await;
Server::new(acceptor).serve(router).await;

Ok(())
Expand Down

0 comments on commit 507a64a

Please sign in to comment.