Skip to content

Commit

Permalink
Merge branch 'release/v3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rousan committed Jan 2, 2022
2 parents 568725a + 72684a8 commit b5c7079
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 77 deletions.
15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "routerify-websocket"
version = "1.0.0"
version = "3.0.0"
description = "The websocket support for the Routerify library."
homepage = "https://github.com/routerify/routerify-websocket"
repository = "https://github.com/routerify/routerify-websocket"
Expand All @@ -25,18 +25,17 @@ json = ["serde", "serde_json"]
[dependencies]
log = "0.4"
derive_more = "0.99"
routerify = "1.1"
hyper = "0.13"
routerify = "3.0"
hyper = "0.14"
headers = "0.3"
tokio-tungstenite = { version = "0.10", default-features = false }
tokio-tungstenite = { version = "0.16", default-features = false }
futures = { version = "0.3", default-features = false }
tokio = { version = "0.2", features = ["rt-core"] }
tokio = { version = "1.0", features = ["rt"] }

serde = { version = "1.0", optional = true }
serde_json = { version = "1.0", optional = true }

[dev-dependencies]
tokio = { version = "0.2", features = ["full"] }
stream-body = "0.1"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
tokio-tungstenite = { version = "0.10", features = ["tls"] }
tokio-tungstenite = { version = "0.16" }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Add this to your `Cargo.toml` file:

```toml
[dependencies]
routerify = "1.1"
routerify-websocket = "1.0"
routerify = "3"
routerify-websocket = "3"
```

## Example
Expand Down
15 changes: 6 additions & 9 deletions examples/test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use futures::{Sink, SinkExt, StreamExt};
use futures::{SinkExt, StreamExt};
use hyper::{Body, Request, Response, Server};
use routerify::prelude::*;
use routerify::{Middleware, Router, RouterService};
use routerify_websocket::{upgrade_ws, upgrade_ws_with_config, Message, WebSocket, WebSocketConfig};
use routerify_websocket::{upgrade_ws, WebSocket};
use serde::{Deserialize, Serialize};
use std::{convert::Infallible, net::SocketAddr};
use tokio_tungstenite::{
tungstenite::protocol::{frame::coding::CloseCode, CloseFrame, Message as ClientMessage},
WebSocketStream,
};
use tokio_tungstenite::tungstenite::protocol::Message as ClientMessage;

#[derive(Serialize, Deserialize, Debug)]
struct User {
Expand All @@ -19,7 +16,7 @@ struct User {
async fn ws_handler(ws: WebSocket) {
println!("new websocket connection: {}", ws.remote_addr());

let (mut tx, mut rx) = ws.split();
let (_tx, mut rx) = ws.split();

while let Some(msg) = rx.next().await {
let msg = msg.unwrap();
Expand Down Expand Up @@ -60,7 +57,7 @@ async fn main() {
let server = Server::bind(&addr).serve(service);

tokio::spawn(async move {
tokio::time::delay_for(tokio::time::Duration::from_secs(3)).await;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;

let (mut ws, resp) = tokio_tungstenite::connect_async("ws://127.0.0.1:3001/ws")
.await
Expand All @@ -73,7 +70,7 @@ async fn main() {

ws.close(None).await.unwrap();

tokio::time::delay_for(tokio::time::Duration::from_secs(3)).await;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
});

println!("App is running on: {}", addr);
Expand Down
55 changes: 0 additions & 55 deletions examples/test_stream_body.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use std::future::Future;
pub fn upgrade_ws_with_config<H, R, B, E>(
handler: H,
config: WebSocketConfig,
) -> impl FnMut(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
) -> impl Fn(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
where
H: Fn(WebSocket) -> R + Copy + Send + Sync + 'static,
R: Future<Output = ()> + Send + 'static,
Expand All @@ -76,7 +76,7 @@ where
}

tokio::spawn(async move {
match req.into_body().on_upgrade().await {
match hyper::upgrade::on(req).await {
Ok(upgraded) => {
handler(WebSocket::from_raw_socket(upgraded, remote_addr, config).await).await;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ where
/// ```
pub fn upgrade_ws<H, R, B, E>(
handler: H,
) -> impl FnMut(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
) -> impl Fn(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
where
H: Fn(WebSocket) -> R + Copy + Send + Sync + 'static,
R: Future<Output = ()> + Send + 'static,
Expand Down

0 comments on commit b5c7079

Please sign in to comment.