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.
|
||||
|
||||
@ -6,18 +6,16 @@
|
||||
|
||||
[![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)
|
||||
![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)
|
||||
[![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 -->
|
||||
|
||||
## Documentation & 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
|
||||
|
||||
## Usage
|
||||
## Example
|
||||
|
||||
```rust
|
||||
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
|
||||
|
||||
This project is licensed under either of
|
||||
|
@ -16,18 +16,19 @@ use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use tokio::sync::mpsc::channel;
|
||||
|
||||
mod aggregated;
|
||||
mod fut;
|
||||
mod session;
|
||||
mod stream;
|
||||
|
||||
pub use self::{
|
||||
aggregated::{AggregatedMessage, AggregatedMessageStream},
|
||||
fut::{MessageStream, StreamingBody},
|
||||
session::{Closed, Session},
|
||||
stream::{MessageStream, StreamingBody},
|
||||
};
|
||||
|
||||
/// Begin handling websocket traffic
|
||||
///
|
||||
/// ```no_run
|
||||
/// use std::io;
|
||||
/// use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Responder};
|
||||
/// use actix_ws::Message;
|
||||
/// use futures_util::StreamExt as _;
|
||||
@ -43,6 +44,7 @@ pub use self::{
|
||||
/// return;
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// Message::Text(msg) => println!("Got text: {msg}"),
|
||||
/// _ => break,
|
||||
/// }
|
||||
@ -55,17 +57,15 @@ pub use self::{
|
||||
/// }
|
||||
///
|
||||
/// #[tokio::main(flavor = "current_thread")]
|
||||
/// async fn main() -> std::io::Result<()> {
|
||||
/// async fn main() -> io::Result<()> {
|
||||
/// HttpServer::new(move || {
|
||||
/// App::new()
|
||||
/// .wrap(Logger::default())
|
||||
/// .route("/ws", web::get().to(ws))
|
||||
/// .wrap(Logger::default())
|
||||
/// })
|
||||
/// .bind("127.0.0.1:8080")?
|
||||
/// .bind(("127.0.0.1", 8080))?
|
||||
/// .run()
|
||||
/// .await?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// .await
|
||||
/// }
|
||||
/// ```
|
||||
pub fn handle(
|
||||
|
@ -21,10 +21,9 @@ use tokio::sync::mpsc::Receiver;
|
||||
|
||||
use crate::AggregatedMessageStream;
|
||||
|
||||
/// A response body for Websocket HTTP Requests
|
||||
/// Response body for a WebSocket.
|
||||
pub struct StreamingBody {
|
||||
session_rx: Receiver<Message>,
|
||||
|
||||
messages: VecDeque<Message>,
|
||||
buf: BytesMut,
|
||||
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 {
|
||||
payload: Payload,
|
||||
|
2
justfile
2
justfile
@ -29,8 +29,8 @@ fmt: update-readmes
|
||||
[group("lint")]
|
||||
update-readmes:
|
||||
cd ./actix-cors && cargo rdme --force
|
||||
cd ./actix-session && cargo rdme --force
|
||||
cd ./actix-identity && cargo rdme --force
|
||||
cd ./actix-session && cargo rdme --force
|
||||
fd README.md --exec-batch npx -y prettier --write
|
||||
|
||||
# Test workspace code.
|
||||
|
Loading…
Reference in New Issue
Block a user