Commit 0ed404af by qlintonger xeno

对接web客户端现有数据类型成功

parent e2516425
...@@ -25,7 +25,7 @@ pub(crate) async fn handle_client( ...@@ -25,7 +25,7 @@ pub(crate) async fn handle_client(
center_to_client_sender: Sender<ClientMessage>, center_to_client_sender: Sender<ClientMessage>,
mut center_to_client_receiver: Receiver<ClientMessage>, mut center_to_client_receiver: Receiver<ClientMessage>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let must_existed_params = ["deviceId", "fromId", "wsPwd"]; let must_existed_params = ["deviceID", "fromID", "wsPwd"];
let mut connection_params = None; let mut connection_params = None;
let ws_stream = match accept_hdr_async(stream, |req: &Request, resp| { let ws_stream = match accept_hdr_async(stream, |req: &Request, resp| {
...@@ -58,7 +58,7 @@ pub(crate) async fn handle_client( ...@@ -58,7 +58,7 @@ pub(crate) async fn handle_client(
let mut last_heartbeat_time = Instant::now(); // 包装为 Arc<Mutex<Instant>> let mut last_heartbeat_time = Instant::now(); // 包装为 Arc<Mutex<Instant>>
if let Some(params) = connection_params { if let Some(params) = connection_params {
if let Some(from_id) = params.get("fromId") { if let Some(from_id) = params.get("fromID") {
let from_id = from_id.clone(); let from_id = from_id.clone();
// 注册客户端到事件中心 // 注册客户端到事件中心
......
pub const STATIC_WS_PWD: &str = "Q8kFm5LzJ2Ab"; pub const STATIC_WS_PWD: &str = "7ahU8LVba_mbpn_ZX6wyE";
pub const STATIC_ADDR: &str = "0.0.0.0:12345"; pub const STATIC_ADDR: &str = "0.0.0.0:12345";
pub const REDIS_ADDR: &str = "redis://127.0.0.1/"; pub const REDIS_ADDR: &str = "redis://127.0.0.1/";
...@@ -7,7 +7,7 @@ pub fn handle_ws_msg( ...@@ -7,7 +7,7 @@ pub fn handle_ws_msg(
event_sender: UnboundedSender<Event>, event_sender: UnboundedSender<Event>,
) { ) {
match msg_type.as_str() { match msg_type.as_str() {
"GetOnlineUserList" => { "GetCompanyUserList" => {
println!("收到客户端获取在线用户列表 {}", &from_id); println!("收到客户端获取在线用户列表 {}", &from_id);
}, },
_ => { _ => {
......
...@@ -17,6 +17,8 @@ pub(crate) fn handle_handshake( ...@@ -17,6 +17,8 @@ pub(crate) fn handle_handshake(
} }
}; };
println!("连接参数: {:?}", connection_params);
let not_existed = must_existed_params let not_existed = must_existed_params
.iter() .iter()
.find(|param| !connection_params.contains_key(&param.to_string())); .find(|param| !connection_params.contains_key(&param.to_string()));
...@@ -32,5 +34,7 @@ pub(crate) fn handle_handshake( ...@@ -32,5 +34,7 @@ pub(crate) fn handle_handshake(
return Err("wsPwd不正确!".to_string()); return Err("wsPwd不正确!".to_string());
} }
println!("握手成功!");
Ok(connection_params) Ok(connection_params)
} }
...@@ -50,7 +50,7 @@ pub async fn send_online_users_and_send( ...@@ -50,7 +50,7 @@ pub async fn send_online_users_and_send(
.await .await
.map_err(|e| Error::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?; .map_err(|e| Error::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?;
let json_message = serde_json::to_string(&ServerOnlineUserMessage { let json_message = serde_json::to_string(&ServerOnlineUserMessage {
msg_type: "CmdUpdateOnlineUsers".to_string(), msg_type: "CmdUpdateUserList".to_string(),
from_name: "Server".to_string(), from_name: "Server".to_string(),
from_id: "0".to_string(), from_id: "0".to_string(),
to_id: from_id.to_string(), to_id: from_id.to_string(),
......
...@@ -5,10 +5,12 @@ use serde::{Deserialize, Serialize}; ...@@ -5,10 +5,12 @@ use serde::{Deserialize, Serialize};
pub struct ClientMessageData { pub struct ClientMessageData {
#[serde(rename = "msgType")] #[serde(rename = "msgType")]
pub msg_type: String, pub msg_type: String,
#[serde(rename = "fromId")] #[serde(rename = "fromID")]
pub from_id: String, pub from_id: String,
#[serde(rename = "fromName")] #[serde(rename = "fromName")]
pub from_name: String, pub from_name: String,
#[serde(rename = "msgData")] #[serde(rename = "msgData")]
pub msg_data: serde_json::Value, pub msg_data: serde_json::Value,
#[serde(rename = "toID")]
pub to_id: String
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment