Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ jobs:
- name: Check async-std-runtime, async-tls, async-native-tls
run: cargo check --features async-std-runtime,async-tls,async-native-tls

- name: Check smol-runtime, async-tls
run: cargo check --features smol-runtime,async-tls

- name: Check smol-runtime, async-native-tls
run: cargo check --features smol-runtime,async-native-tls

- name: Check smol-runtime, async-tls, async-native-tls
run: cargo check --features smol-runtime,async-tls,async-native-tls

- name: Check tokio-runtime, tokio-native-tls
run: cargo check --features tokio-runtime,tokio-native-tls

Expand Down
16 changes: 15 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default = ["handshake", "futures-03-sink"]
futures-03-sink = ["futures-util"]
handshake = ["tungstenite/handshake"]
async-std-runtime = ["async-std", "handshake"]
smol-runtime = ["async-net", "handshake"]
tokio-runtime = ["tokio", "handshake"]
gio-runtime = ["gio", "glib", "handshake"]
async-tls = ["real-async-tls", "handshake"]
Expand All @@ -34,7 +35,7 @@ url = ["tungstenite/url"]
__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "rustls-pki-types", "tungstenite/__rustls-tls"]

[package.metadata.docs.rs]
features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]
features = ["async-std-runtime", "smol-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"]

[dependencies]
log = "0.4"
Expand All @@ -58,6 +59,10 @@ default-features = false
optional = true
version = "1.0"

[dependencies.async-net]
optional = true
version = "2.0"

[dependencies.real-tokio-openssl]
optional = true
version = "0.6"
Expand Down Expand Up @@ -136,6 +141,11 @@ http-body-util = "0.1"
version = "0.28"
features = ["url"]

# For smol examples
[dependencies.smol]
optional = true
version = "2.0"

[[example]]
name = "autobahn-client"
required-features = ["async-std-runtime"]
Expand All @@ -144,6 +154,10 @@ required-features = ["async-std-runtime"]
name = "async-std-echo"
required-features = ["async-std-runtime"]

[[example]]
name = "smol-echo"
required-features = ["smol-runtime", "smol"]

[[example]]
name = "client"
required-features = ["async-std-runtime"]
Expand Down
30 changes: 30 additions & 0 deletions examples/smol-echo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use async_tungstenite::{smol::connect_async, tungstenite::Message};
use futures::prelude::*;

async fn run() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(any(feature = "async-tls", feature = "async-native-tls"))]
let url = "wss://echo.websocket.org/.ws";
#[cfg(not(any(feature = "async-tls", feature = "async-native-tls")))]
let url = "ws://echo.websocket.org/.ws";

println!("Connecting: \"{}\"", url);
let (mut ws_stream, _) = connect_async(url).await?;

let msg = ws_stream.next().await.ok_or("didn't receive anything")??;
println!("Received: {:?}", msg);

let text = "Hello, World!";

println!("Sending: \"{}\"", text);
ws_stream.send(Message::text(text)).await?;

let msg = ws_stream.next().await.ok_or("didn't receive anything")??;

println!("Received: {:?}", msg);

Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
smol::block_on(run())
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub mod async_std;
pub mod async_tls;
#[cfg(feature = "gio-runtime")]
pub mod gio;
#[cfg(feature = "smol-runtime")]
pub mod smol;
#[cfg(feature = "tokio-runtime")]
pub mod tokio;

Expand Down Expand Up @@ -747,6 +749,7 @@ impl<S> Shared<S> {
#[cfg(any(
feature = "async-tls",
feature = "async-std-runtime",
feature = "smol-runtime",
feature = "tokio-runtime",
feature = "gio-runtime"
))]
Expand Down Expand Up @@ -779,6 +782,7 @@ pub(crate) fn domain(

#[cfg(any(
feature = "async-std-runtime",
feature = "smol-runtime",
feature = "tokio-runtime",
feature = "gio-runtime"
))]
Expand All @@ -805,6 +809,7 @@ mod tests {
#[cfg(any(
feature = "async-tls",
feature = "async-std-runtime",
feature = "smol-runtime",
feature = "tokio-runtime",
feature = "gio-runtime"
))]
Expand Down
Loading
Loading