|
|
@@ -31,16 +31,16 @@ pub struct AbstractWsMode {}
|
|
|
|
|
|
impl AbstractWsMode {
|
|
|
pub async fn ws_connected<T, PI, PO, F, B, Future>(write_to_socket_rx_arc: Arc<Mutex<UnboundedReceiver<Message>>>,
|
|
|
- is_first_login: bool,
|
|
|
- label: String,
|
|
|
- is_shutdown_arc: Arc<AtomicBool>,
|
|
|
- handle_function: &F,
|
|
|
- subscribe_array: Vec<String>,
|
|
|
- ws_stream: WebSocketStream<MaybeTlsStream<TcpStream>>,
|
|
|
- message_text: T,
|
|
|
- message_ping: PI,
|
|
|
- message_pong: PO,
|
|
|
- message_binary: B)
|
|
|
+ is_first_login: bool,
|
|
|
+ label: String,
|
|
|
+ is_shutdown_arc: Arc<AtomicBool>,
|
|
|
+ handle_function: &F,
|
|
|
+ subscribe_array: Vec<String>,
|
|
|
+ ws_stream: WebSocketStream<MaybeTlsStream<TcpStream>>,
|
|
|
+ message_text: T,
|
|
|
+ message_ping: PI,
|
|
|
+ message_pong: PO,
|
|
|
+ message_binary: B)
|
|
|
where T: Fn(String) -> Option<ResponseData> + Copy,
|
|
|
PI: Fn(Vec<u8>) -> Option<ResponseData> + Copy,
|
|
|
PO: Fn(Vec<u8>) -> Option<ResponseData> + Copy,
|
|
|
@@ -86,13 +86,13 @@ impl AbstractWsMode {
|
|
|
|
|
|
let code = data.code.clone();
|
|
|
|
|
|
- if code == 200 {
|
|
|
- let mut data_c = data.clone();
|
|
|
- data_c.ins = Instant::now();
|
|
|
- data_c.time = Utc::now().timestamp_millis();
|
|
|
-
|
|
|
- handle_function(data_c).await;
|
|
|
- }
|
|
|
+ // if code == 200 {
|
|
|
+ // let mut data_c = data.clone();
|
|
|
+ // data_c.ins = Instant::now();
|
|
|
+ // data_c.time = Utc::now().timestamp_millis();
|
|
|
+ //
|
|
|
+ // handle_function(data_c).await;
|
|
|
+ // }
|
|
|
|
|
|
/*
|
|
|
200 -正确返回
|
|
|
@@ -103,6 +103,13 @@ impl AbstractWsMode {
|
|
|
-302 -客户端收到服务器心跳自定义,需要响应自定义
|
|
|
*/
|
|
|
match code {
|
|
|
+ 200 => {
|
|
|
+ let mut data_c = data.clone();
|
|
|
+ data_c.ins = Instant::now();
|
|
|
+ data_c.time = Utc::now().timestamp_millis();
|
|
|
+
|
|
|
+ handle_function(data_c).await;
|
|
|
+ }
|
|
|
-200 => {
|
|
|
//登录成功
|
|
|
info!("ws登录成功:{:?}", data);
|
|
|
@@ -158,16 +165,16 @@ impl AbstractWsMode {
|
|
|
|
|
|
//创建链接
|
|
|
pub async fn ws_connect_async<T, PI, PO, F, B, Future>(is_shutdown_arc: Arc<AtomicBool>,
|
|
|
- handle_function: F,
|
|
|
- address_url: String,
|
|
|
- is_first_login: bool,
|
|
|
- label: String,
|
|
|
- subscribe_array: Vec<String>,
|
|
|
- write_to_socket_rx_arc: Arc<Mutex<UnboundedReceiver<Message>>>,
|
|
|
- message_text: T,
|
|
|
- message_ping: PI,
|
|
|
- message_pong: PO,
|
|
|
- message_binary: B)
|
|
|
+ handle_function: F,
|
|
|
+ address_url: String,
|
|
|
+ is_first_login: bool,
|
|
|
+ label: String,
|
|
|
+ subscribe_array: Vec<String>,
|
|
|
+ write_to_socket_rx_arc: Arc<Mutex<UnboundedReceiver<Message>>>,
|
|
|
+ message_text: T,
|
|
|
+ message_ping: PI,
|
|
|
+ message_pong: PO,
|
|
|
+ message_binary: B)
|
|
|
where T: Fn(String) -> Option<ResponseData> + Copy,
|
|
|
PI: Fn(Vec<u8>) -> Option<ResponseData> + Copy,
|
|
|
PO: Fn(Vec<u8>) -> Option<ResponseData> + Copy,
|
|
|
@@ -233,10 +240,10 @@ impl AbstractWsMode {
|
|
|
}
|
|
|
//数据解析
|
|
|
pub fn analysis_message<T, PI, PO, B>(message: Result<Message, Error>,
|
|
|
- message_text: T,
|
|
|
- message_ping: PI,
|
|
|
- message_pong: PO,
|
|
|
- message_binary: B) -> Option<ResponseData>
|
|
|
+ message_text: T,
|
|
|
+ message_ping: PI,
|
|
|
+ message_pong: PO,
|
|
|
+ message_binary: B) -> Option<ResponseData>
|
|
|
where T: Fn(String) -> Option<ResponseData>,
|
|
|
PI: Fn(Vec<u8>) -> Option<ResponseData>,
|
|
|
PO: Fn(Vec<u8>) -> Option<ResponseData>,
|