Skip to content

Commit

Permalink
refactor(examples): split examples between libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore committed Oct 28, 2023
1 parent 0eb3b2b commit da6653a
Show file tree
Hide file tree
Showing 13 changed files with 811 additions and 241 deletions.
724 changes: 690 additions & 34 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions examples/axum-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "axum-echo"
version = "0.6.0"
edition = "2021"

[dependencies]
socketioxide = { path = "../../socketioxide" }
axum = { version = "0.6.20" }
tokio = { version = "1.33.0", features = ["full"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing = "0.1.37"
serde = "1.0.188"
serde_json = "1.0.107"
futures = "0.3.28"

[[bin]]
name = "axum-echo"
path = "axum_echo.rs"
File renamed without changes.
32 changes: 0 additions & 32 deletions examples/engineio-echo/Cargo.toml

This file was deleted.

52 changes: 0 additions & 52 deletions examples/engineio-echo/src/axum_echo.rs

This file was deleted.

52 changes: 0 additions & 52 deletions examples/engineio-echo/src/hyper_echo.rs

This file was deleted.

56 changes: 0 additions & 56 deletions examples/engineio-echo/src/warp_echo.rs

This file was deleted.

20 changes: 20 additions & 0 deletions examples/hyper-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "hyper-echo"
version = "0.6.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
socketioxide = { path = "../../socketioxide" }
hyper = { version = "0.14.27" }
tokio = { version = "1.33.0", features = ["full"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing = "0.1.37"
serde = "1.0.188"
serde_json = "1.0.107"
futures = "0.3.28"

[[bin]]
name = "hyper-echo"
path = "hyper_echo.rs"
File renamed without changes.
20 changes: 20 additions & 0 deletions examples/salvo-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "salvo-echo"
version = "0.6.0"
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"] }
salvo = { version = "0.58.2", features = ["tower-compat"] }
tokio = { version = "1.33.0", features = ["full"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing = "0.1.37"
serde = "1.0.188"
serde_json = "1.0.107"
futures = "0.3.28"

[[bin]]
name = "salvo-echo"
path = "salvo_echo.rs"
59 changes: 59 additions & 0 deletions examples/salvo-echo/salvo_echo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use salvo::prelude::*;
use salvo::tower_compat::TowerServiceCompat;

use std::sync::Arc;

use engineioxide::{
handler::EngineIoHandler,
service::EngineIoService,
socket::{DisconnectReason, Socket},
};
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

#[derive(Debug, Clone)]
struct MyHandler;

#[engineioxide::async_trait]
impl EngineIoHandler for MyHandler {
type Data = ();

fn on_connect(&self, socket: Arc<Socket<Self::Data>>) {
println!("socket connect {}", socket.id);
}
fn on_disconnect(&self, socket: Arc<Socket<Self::Data>>, reason: DisconnectReason) {
println!("socket disconnect {}: {:?}", socket.id, reason);
}

fn on_message(&self, msg: String, socket: Arc<Socket<Self::Data>>) {
println!("Ping pong message {:?}", msg);
socket.emit(msg).ok();
}

fn on_binary(&self, data: Vec<u8>, socket: Arc<Socket<Self::Data>>) {
println!("Ping pong binary message {:?}", data);
socket.emit_binary(data).ok();
}
}

#[handler]
async fn hello() -> &'static str {
"Hello World"
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let subscriber = FmtSubscriber::builder()
.with_line_number(true)
.with_max_level(Level::DEBUG)
.finish();
tracing::subscriber::set_global_default(subscriber)?;

let svc = EngineIoService::new(MyHandler).compat();

let router = Router::new().get(hello);
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
Server::new(acceptor).serve(router).await;

Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
[package]
name = "socketio-echo"
name = "engineio-echo"
version = "0.6.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
socketioxide = { path = "../../socketioxide" }
axum = { version = "0.6.20" }
warp = { version = "0.3.6" }
hyper = { version = "0.14.27" }
tokio = { version = "1.33.0", features = ["full"] }
tower = { version = "0.4.13" }
tower-http = { version = "0.4.4", features = ["cors"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tracing = "0.1.37"
serde = "1.0.188"
serde_json = "1.0.107"
futures = "0.3.28"

[[example]]
name = "socketio-axum-echo"
path = "src/axum_echo.rs"

[[example]]
name = "socketio-hyper-echo"
path = "src/hyper_echo.rs"

[[example]]
name = "socketio-warp-echo"
path = "src/warp_echo.rs"
[[bin]]
name = "warp-echo"
path = "warp_echo.rs"
File renamed without changes.

0 comments on commit da6653a

Please sign in to comment.