WebSocket handshake and start `MyWebSocket` actor.
(req: HttpRequest, stream: web::Payload)
| 15 | |
| 16 | /// WebSocket handshake and start `MyWebSocket` actor. |
| 17 | async fn echo_ws(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> { |
| 18 | let (res, session, stream) = actix_ws::handle(&req, stream)?; |
| 19 | |
| 20 | let (actor, _handle) = Actor::spawn(None, MyWebSocket, session).await.unwrap(); |
| 21 | |
| 22 | actix_web::rt::spawn(async move { |
| 23 | let mut stream = stream.aggregate_continuations(); |
| 24 | |
| 25 | while let Some(Ok(msg)) = stream.recv().await { |
| 26 | actor.send_message(WsMessage::Ws(msg)).unwrap(); |
| 27 | } |
| 28 | }); |
| 29 | |
| 30 | Ok(res) |
| 31 | } |
| 32 | |
| 33 | // the actor-based WebSocket examples REQUIRE `actix_web::main` for actor support |
| 34 | #[actix_web::main] |
nothing calls this directly
no test coverage detected