Stable Connection
This commit is contained in:
parent
d2dc472d02
commit
343687a31b
2 changed files with 33 additions and 24 deletions
|
|
@ -16,6 +16,7 @@ pub enum DataTypes {
|
|||
iota_id,
|
||||
user_id,
|
||||
user_ids,
|
||||
iota_ids,
|
||||
user_state,
|
||||
user_states,
|
||||
user_pings,
|
||||
|
|
@ -75,7 +76,7 @@ pub enum DataTypes {
|
|||
challenge,
|
||||
community_title,
|
||||
communities,
|
||||
|
||||
rho_connections,
|
||||
user,
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +93,7 @@ impl DataTypes {
|
|||
"iotaid" => DataTypes::iota_id,
|
||||
"userid" => DataTypes::user_id,
|
||||
"userids" => DataTypes::user_ids,
|
||||
"iotaids" => DataTypes::iota_ids,
|
||||
"userstate" => DataTypes::user_state,
|
||||
"userstates" => DataTypes::user_states,
|
||||
"userpings" => DataTypes::user_pings,
|
||||
|
|
@ -151,7 +153,7 @@ impl DataTypes {
|
|||
"challenge" => DataTypes::challenge,
|
||||
"communitytitle" => DataTypes::community_title,
|
||||
"communities" => DataTypes::communities,
|
||||
|
||||
"rhoconnections" => DataTypes::rho_connections,
|
||||
"user" => DataTypes::user,
|
||||
_ => DataTypes::error_type, // fallback if unknown
|
||||
}
|
||||
|
|
@ -202,8 +204,6 @@ pub enum CommunicationType {
|
|||
pong,
|
||||
add_chat,
|
||||
send_chat,
|
||||
iota_connected,
|
||||
iota_closed,
|
||||
client_changed,
|
||||
client_connected,
|
||||
client_disconnected,
|
||||
|
|
@ -224,6 +224,13 @@ pub enum CommunicationType {
|
|||
function,
|
||||
update,
|
||||
create_user,
|
||||
rho_update,
|
||||
|
||||
user_connected,
|
||||
user_disconnected,
|
||||
iota_connected,
|
||||
iota_disconnected,
|
||||
sync_client_iota_status,
|
||||
}
|
||||
impl CommunicationType {
|
||||
pub fn parse(p0: String) -> CommunicationType {
|
||||
|
|
@ -280,8 +287,6 @@ impl CommunicationType {
|
|||
"pong" => CommunicationType::pong,
|
||||
"addchat" => CommunicationType::add_chat,
|
||||
"sendchat" => CommunicationType::send_chat,
|
||||
"iotaconnected" => CommunicationType::iota_connected,
|
||||
"iotaclosed" => CommunicationType::iota_closed,
|
||||
"clientchanged" => CommunicationType::client_changed,
|
||||
"clientconnected" => CommunicationType::client_connected,
|
||||
"clientdisconnected" => CommunicationType::client_disconnected,
|
||||
|
|
@ -292,6 +297,13 @@ impl CommunicationType {
|
|||
"webrtcice" => CommunicationType::webrtc_ice,
|
||||
"startstream" => CommunicationType::start_stream,
|
||||
"endstream" => CommunicationType::end_stream,
|
||||
"rhoupdate" => CommunicationType::rho_update,
|
||||
|
||||
"iotaconnected" => CommunicationType::iota_connected,
|
||||
"iotadisconnected" => CommunicationType::iota_disconnected,
|
||||
"userconnected" => CommunicationType::user_connected,
|
||||
"userdisconnected" => CommunicationType::user_disconnected,
|
||||
"syncclientiotastatus" => CommunicationType::sync_client_iota_status,
|
||||
|
||||
_ => CommunicationType::error,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ impl OmikronConnection {
|
|||
pingpong: Arc::new(Mutex::new(None)),
|
||||
last_ping: Arc::new(Mutex::new(-1)),
|
||||
message_send_times: Arc::new(Mutex::new(HashMap::new())),
|
||||
is_connected: Arc::new(Mutex::new(false)),
|
||||
is_connected: Arc::new(Mutex::new(true)),
|
||||
});
|
||||
let boxed_reader: Box<
|
||||
dyn Stream<Item = Result<Message, tungstenite::Error>> + Send + Unpin,
|
||||
|
|
@ -161,25 +161,22 @@ impl OmikronConnection {
|
|||
ACTIVE_TASKS.lock().unwrap().push("Listener".to_string());
|
||||
}
|
||||
tokio::spawn(async move {
|
||||
while !*SHUTDOWN.read().await {
|
||||
if poll(Duration::from_millis(100)).unwrap() {
|
||||
if let Some(msg) = read_half.next().await {
|
||||
if *is_connected_out.lock().await == false {
|
||||
log_message("Disconnected, not handeling incomming");
|
||||
break;
|
||||
}
|
||||
Self::handle_message(
|
||||
msg,
|
||||
waiting_out.clone(),
|
||||
writer_out.clone(),
|
||||
is_connected_out.clone(),
|
||||
sel_out.clone(),
|
||||
variant.clone(),
|
||||
sel_arc_out.clone(),
|
||||
);
|
||||
}
|
||||
while let Some(msg) = read_half.next().await {
|
||||
if *SHUTDOWN.read().await {
|
||||
break;
|
||||
}
|
||||
Self::handle_message(
|
||||
msg,
|
||||
waiting_out.clone(),
|
||||
writer_out.clone(),
|
||||
is_connected_out.clone(),
|
||||
sel_out.clone(),
|
||||
variant.clone(),
|
||||
sel_arc_out.clone(),
|
||||
);
|
||||
}
|
||||
*is_connected_out.lock().await = false;
|
||||
log_message("Connection closed.");
|
||||
});
|
||||
{
|
||||
ACTIVE_TASKS
|
||||
|
|
|
|||
Loading…
Reference in a new issue