mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 15:51:06 +01:00
docs(ws): update readme
This commit is contained in:
parent
b0d2947a4a
commit
24f3985eab
@ -1,4 +1,4 @@
|
|||||||
# Actix WS (Next Gen)
|
# `actix-ws`
|
||||||
|
|
||||||
> WebSockets for Actix Web, without actors.
|
> WebSockets for Actix Web, without actors.
|
||||||
|
|
||||||
@ -6,18 +6,16 @@
|
|||||||
|
|
||||||
[![crates.io](https://img.shields.io/crates/v/actix-ws?label=latest)](https://crates.io/crates/actix-ws)
|
[![crates.io](https://img.shields.io/crates/v/actix-ws?label=latest)](https://crates.io/crates/actix-ws)
|
||||||
[![Documentation](https://docs.rs/actix-ws/badge.svg?version=0.2.0)](https://docs.rs/actix-ws/0.2.0)
|
[![Documentation](https://docs.rs/actix-ws/badge.svg?version=0.2.0)](https://docs.rs/actix-ws/0.2.0)
|
||||||
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-ws)
|
![Version](https://img.shields.io/badge/rustc-1.75+-ab6000.svg)
|
||||||
|
![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-ws.svg)
|
||||||
|
<br />
|
||||||
[![Dependency Status](https://deps.rs/crate/actix-ws/0.2.0/status.svg)](https://deps.rs/crate/actix-ws/0.2.0)
|
[![Dependency Status](https://deps.rs/crate/actix-ws/0.2.0/status.svg)](https://deps.rs/crate/actix-ws/0.2.0)
|
||||||
|
[![Download](https://img.shields.io/crates/d/actix-ws.svg)](https://crates.io/crates/actix-ws)
|
||||||
|
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
## Example
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-ws)
|
|
||||||
- [Example Chat Project](https://github.com/actix/examples/tree/master/websockets/chat-actorless)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.75
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Responder};
|
use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Responder};
|
||||||
@ -60,6 +58,12 @@ async fn main() -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
- [API Documentation](https://docs.rs/actix-ws)
|
||||||
|
- [Example Chat Project](https://github.com/actix/examples/tree/master/websockets/chat-actorless)
|
||||||
|
- Minimum Supported Rust Version (MSRV): 1.75
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under either of
|
This project is licensed under either of
|
||||||
|
@ -16,18 +16,19 @@ use actix_web::{web, HttpRequest, HttpResponse};
|
|||||||
use tokio::sync::mpsc::channel;
|
use tokio::sync::mpsc::channel;
|
||||||
|
|
||||||
mod aggregated;
|
mod aggregated;
|
||||||
mod fut;
|
|
||||||
mod session;
|
mod session;
|
||||||
|
mod stream;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
aggregated::{AggregatedMessage, AggregatedMessageStream},
|
aggregated::{AggregatedMessage, AggregatedMessageStream},
|
||||||
fut::{MessageStream, StreamingBody},
|
|
||||||
session::{Closed, Session},
|
session::{Closed, Session},
|
||||||
|
stream::{MessageStream, StreamingBody},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Begin handling websocket traffic
|
/// Begin handling websocket traffic
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
|
/// use std::io;
|
||||||
/// use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Responder};
|
/// use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Responder};
|
||||||
/// use actix_ws::Message;
|
/// use actix_ws::Message;
|
||||||
/// use futures_util::StreamExt as _;
|
/// use futures_util::StreamExt as _;
|
||||||
@ -43,6 +44,7 @@ pub use self::{
|
|||||||
/// return;
|
/// return;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
|
///
|
||||||
/// Message::Text(msg) => println!("Got text: {msg}"),
|
/// Message::Text(msg) => println!("Got text: {msg}"),
|
||||||
/// _ => break,
|
/// _ => break,
|
||||||
/// }
|
/// }
|
||||||
@ -55,17 +57,15 @@ pub use self::{
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// #[tokio::main(flavor = "current_thread")]
|
/// #[tokio::main(flavor = "current_thread")]
|
||||||
/// async fn main() -> std::io::Result<()> {
|
/// async fn main() -> io::Result<()> {
|
||||||
/// HttpServer::new(move || {
|
/// HttpServer::new(move || {
|
||||||
/// App::new()
|
/// App::new()
|
||||||
/// .wrap(Logger::default())
|
|
||||||
/// .route("/ws", web::get().to(ws))
|
/// .route("/ws", web::get().to(ws))
|
||||||
|
/// .wrap(Logger::default())
|
||||||
/// })
|
/// })
|
||||||
/// .bind("127.0.0.1:8080")?
|
/// .bind(("127.0.0.1", 8080))?
|
||||||
/// .run()
|
/// .run()
|
||||||
/// .await?;
|
/// .await
|
||||||
///
|
|
||||||
/// Ok(())
|
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn handle(
|
pub fn handle(
|
||||||
|
@ -21,10 +21,9 @@ use tokio::sync::mpsc::Receiver;
|
|||||||
|
|
||||||
use crate::AggregatedMessageStream;
|
use crate::AggregatedMessageStream;
|
||||||
|
|
||||||
/// A response body for Websocket HTTP Requests
|
/// Response body for a WebSocket.
|
||||||
pub struct StreamingBody {
|
pub struct StreamingBody {
|
||||||
session_rx: Receiver<Message>,
|
session_rx: Receiver<Message>,
|
||||||
|
|
||||||
messages: VecDeque<Message>,
|
messages: VecDeque<Message>,
|
||||||
buf: BytesMut,
|
buf: BytesMut,
|
||||||
codec: Codec,
|
codec: Codec,
|
||||||
@ -43,7 +42,7 @@ impl StreamingBody {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stream of Messages from a websocket client.
|
/// Stream of messages from a WebSocket client.
|
||||||
pub struct MessageStream {
|
pub struct MessageStream {
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
|
|
2
justfile
2
justfile
@ -29,8 +29,8 @@ fmt: update-readmes
|
|||||||
[group("lint")]
|
[group("lint")]
|
||||||
update-readmes:
|
update-readmes:
|
||||||
cd ./actix-cors && cargo rdme --force
|
cd ./actix-cors && cargo rdme --force
|
||||||
cd ./actix-session && cargo rdme --force
|
|
||||||
cd ./actix-identity && cargo rdme --force
|
cd ./actix-identity && cargo rdme --force
|
||||||
|
cd ./actix-session && cargo rdme --force
|
||||||
fd README.md --exec-batch npx -y prettier --write
|
fd README.md --exec-batch npx -y prettier --write
|
||||||
|
|
||||||
# Test workspace code.
|
# Test workspace code.
|
||||||
|
Loading…
Reference in New Issue
Block a user