Migrate from actix-web-actor to actix-ws
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
use crate::actors::vnc_actor::VNCActor;
|
||||
use crate::actors::vnc_handler;
|
||||
use crate::actors::vnc_tokens_actor::VNCTokensManager;
|
||||
use crate::controllers::{HttpResult, LibVirtReq};
|
||||
use crate::libvirt_lib_structures::domain::DomainState;
|
||||
use crate::libvirt_lib_structures::XMLUuid;
|
||||
use crate::libvirt_rest_structures::vm::VMInfo;
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use actix_web_actors::ws;
|
||||
use actix_web::{rt, web, HttpRequest, HttpResponse};
|
||||
use std::path::Path;
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct VMInfoAndState {
|
||||
@ -324,5 +325,19 @@ pub async fn vnc(
|
||||
};
|
||||
|
||||
log::info!("Start VNC connection on socket {socket_path}");
|
||||
Ok(ws::start(VNCActor::new(&socket_path).await?, &req, stream)?)
|
||||
|
||||
let socket_path = Path::new(&socket_path);
|
||||
if !socket_path.exists() {
|
||||
log::error!("VNC socket path {socket_path:?} does not exist!");
|
||||
return Ok(HttpResponse::ServiceUnavailable().json("VNC socket path does not exists!"));
|
||||
}
|
||||
|
||||
let socket = UnixStream::connect(socket_path).await?;
|
||||
|
||||
let (res, session, msg_stream) = actix_ws::handle(&req, stream)?;
|
||||
|
||||
// spawn websocket handler (and don't await it) so that the response is returned immediately
|
||||
rt::spawn(vnc_handler::handle(session, msg_stream, socket));
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
Reference in New Issue
Block a user