[WIP] Client connections
This commit is contained in:
parent
5716ed1aa2
commit
84bdcab0d1
4 changed files with 7 additions and 7 deletions
|
|
@ -60,7 +60,7 @@ async fn main() {
|
||||||
let mut path: String = "/".to_string();
|
let mut path: String = "/".to_string();
|
||||||
|
|
||||||
let callback = |req: &Request, response: Response| {
|
let callback = |req: &Request, response: Response| {
|
||||||
path = req.uri().path().to_string(); // Extract URI path
|
path = req.uri().path().to_string();
|
||||||
Ok(response)
|
Ok(response)
|
||||||
};
|
};
|
||||||
let ws_stream = match accept_hdr_async(stream.compat(), callback).await {
|
let ws_stream = match accept_hdr_async(stream.compat(), callback).await {
|
||||||
|
|
@ -71,7 +71,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let (sender, receiver) = ws_stream.split();
|
let (sender, receiver) = ws_stream.split();
|
||||||
if path == "/ws/client/" {
|
if path.starts_with("/ws/client") {
|
||||||
log_in!(0, PrintType::Client, "New Client connection");
|
log_in!(0, PrintType::Client, "New Client connection");
|
||||||
let client_conn: Arc<ClientConnection> =
|
let client_conn: Arc<ClientConnection> =
|
||||||
Arc::from(ClientConnection::new(sender, receiver));
|
Arc::from(ClientConnection::new(sender, receiver));
|
||||||
|
|
@ -117,7 +117,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if path == "/ws/anonymous_client/" {
|
} else if path.starts_with("/ws/anonymous_client") {
|
||||||
log_in!(0, PrintType::Client, "New Anonymous Client connection");
|
log_in!(0, PrintType::Client, "New Anonymous Client connection");
|
||||||
let client_conn: Arc<AnonymousClientConnection> =
|
let client_conn: Arc<AnonymousClientConnection> =
|
||||||
Arc::from(AnonymousClientConnection::new(sender, receiver));
|
Arc::from(AnonymousClientConnection::new(sender, receiver));
|
||||||
|
|
@ -176,7 +176,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if path == "/ws/iota/" {
|
} else if path.starts_with("/ws/iota") {
|
||||||
log_in!(0, PrintType::Iota, "New Iota connection");
|
log_in!(0, PrintType::Iota, "New Iota connection");
|
||||||
let iota_conn: Arc<IotaConnection> =
|
let iota_conn: Arc<IotaConnection> =
|
||||||
Arc::from(IotaConnection::new(sender, receiver));
|
Arc::from(IotaConnection::new(sender, receiver));
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ impl OmegaConnection {
|
||||||
match msg {
|
match msg {
|
||||||
Some(Ok(Message::Text(msg))) => {
|
Some(Ok(Message::Text(msg))) => {
|
||||||
let cv = CommunicationValue::from_json(&msg);
|
let cv = CommunicationValue::from_json(&msg);
|
||||||
if cv.is_type(CommunicationType::pong) {
|
if cv.is_type(CommunicationType::pong) || cv.is_type(CommunicationType::ping) {
|
||||||
self.handle_pong(&cv, true).await;
|
self.handle_pong(&cv, true).await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ impl ClientConnection {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if !cv.is_type(CommunicationType::pong) {
|
if !cv.is_type(CommunicationType::pong) && !cv.is_type(CommunicationType::ping) {
|
||||||
log_out!(
|
log_out!(
|
||||||
self.get_user_id().await,
|
self.get_user_id().await,
|
||||||
PrintType::Client,
|
PrintType::Client,
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ impl IotaConnection {
|
||||||
pub async fn handle_message(self: Arc<Self>, message: Utf8Bytes) {
|
pub async fn handle_message(self: Arc<Self>, message: Utf8Bytes) {
|
||||||
let cv = CommunicationValue::from_json(&message);
|
let cv = CommunicationValue::from_json(&message);
|
||||||
// Handle ping
|
// Handle ping
|
||||||
if cv.is_type(CommunicationType::ping) {
|
if cv.is_type(CommunicationType::ping) || cv.is_type(CommunicationType::pong) {
|
||||||
self.handle_ping(cv).await;
|
self.handle_ping(cv).await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue