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,
|
iota_id,
|
||||||
user_id,
|
user_id,
|
||||||
user_ids,
|
user_ids,
|
||||||
|
iota_ids,
|
||||||
user_state,
|
user_state,
|
||||||
user_states,
|
user_states,
|
||||||
user_pings,
|
user_pings,
|
||||||
|
|
@ -75,7 +76,7 @@ pub enum DataTypes {
|
||||||
challenge,
|
challenge,
|
||||||
community_title,
|
community_title,
|
||||||
communities,
|
communities,
|
||||||
|
rho_connections,
|
||||||
user,
|
user,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,6 +93,7 @@ impl DataTypes {
|
||||||
"iotaid" => DataTypes::iota_id,
|
"iotaid" => DataTypes::iota_id,
|
||||||
"userid" => DataTypes::user_id,
|
"userid" => DataTypes::user_id,
|
||||||
"userids" => DataTypes::user_ids,
|
"userids" => DataTypes::user_ids,
|
||||||
|
"iotaids" => DataTypes::iota_ids,
|
||||||
"userstate" => DataTypes::user_state,
|
"userstate" => DataTypes::user_state,
|
||||||
"userstates" => DataTypes::user_states,
|
"userstates" => DataTypes::user_states,
|
||||||
"userpings" => DataTypes::user_pings,
|
"userpings" => DataTypes::user_pings,
|
||||||
|
|
@ -151,7 +153,7 @@ impl DataTypes {
|
||||||
"challenge" => DataTypes::challenge,
|
"challenge" => DataTypes::challenge,
|
||||||
"communitytitle" => DataTypes::community_title,
|
"communitytitle" => DataTypes::community_title,
|
||||||
"communities" => DataTypes::communities,
|
"communities" => DataTypes::communities,
|
||||||
|
"rhoconnections" => DataTypes::rho_connections,
|
||||||
"user" => DataTypes::user,
|
"user" => DataTypes::user,
|
||||||
_ => DataTypes::error_type, // fallback if unknown
|
_ => DataTypes::error_type, // fallback if unknown
|
||||||
}
|
}
|
||||||
|
|
@ -202,8 +204,6 @@ pub enum CommunicationType {
|
||||||
pong,
|
pong,
|
||||||
add_chat,
|
add_chat,
|
||||||
send_chat,
|
send_chat,
|
||||||
iota_connected,
|
|
||||||
iota_closed,
|
|
||||||
client_changed,
|
client_changed,
|
||||||
client_connected,
|
client_connected,
|
||||||
client_disconnected,
|
client_disconnected,
|
||||||
|
|
@ -224,6 +224,13 @@ pub enum CommunicationType {
|
||||||
function,
|
function,
|
||||||
update,
|
update,
|
||||||
create_user,
|
create_user,
|
||||||
|
rho_update,
|
||||||
|
|
||||||
|
user_connected,
|
||||||
|
user_disconnected,
|
||||||
|
iota_connected,
|
||||||
|
iota_disconnected,
|
||||||
|
sync_client_iota_status,
|
||||||
}
|
}
|
||||||
impl CommunicationType {
|
impl CommunicationType {
|
||||||
pub fn parse(p0: String) -> CommunicationType {
|
pub fn parse(p0: String) -> CommunicationType {
|
||||||
|
|
@ -280,8 +287,6 @@ impl CommunicationType {
|
||||||
"pong" => CommunicationType::pong,
|
"pong" => CommunicationType::pong,
|
||||||
"addchat" => CommunicationType::add_chat,
|
"addchat" => CommunicationType::add_chat,
|
||||||
"sendchat" => CommunicationType::send_chat,
|
"sendchat" => CommunicationType::send_chat,
|
||||||
"iotaconnected" => CommunicationType::iota_connected,
|
|
||||||
"iotaclosed" => CommunicationType::iota_closed,
|
|
||||||
"clientchanged" => CommunicationType::client_changed,
|
"clientchanged" => CommunicationType::client_changed,
|
||||||
"clientconnected" => CommunicationType::client_connected,
|
"clientconnected" => CommunicationType::client_connected,
|
||||||
"clientdisconnected" => CommunicationType::client_disconnected,
|
"clientdisconnected" => CommunicationType::client_disconnected,
|
||||||
|
|
@ -292,6 +297,13 @@ impl CommunicationType {
|
||||||
"webrtcice" => CommunicationType::webrtc_ice,
|
"webrtcice" => CommunicationType::webrtc_ice,
|
||||||
"startstream" => CommunicationType::start_stream,
|
"startstream" => CommunicationType::start_stream,
|
||||||
"endstream" => CommunicationType::end_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,
|
_ => CommunicationType::error,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ impl OmikronConnection {
|
||||||
pingpong: Arc::new(Mutex::new(None)),
|
pingpong: Arc::new(Mutex::new(None)),
|
||||||
last_ping: Arc::new(Mutex::new(-1)),
|
last_ping: Arc::new(Mutex::new(-1)),
|
||||||
message_send_times: Arc::new(Mutex::new(HashMap::new())),
|
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<
|
let boxed_reader: Box<
|
||||||
dyn Stream<Item = Result<Message, tungstenite::Error>> + Send + Unpin,
|
dyn Stream<Item = Result<Message, tungstenite::Error>> + Send + Unpin,
|
||||||
|
|
@ -161,25 +161,22 @@ impl OmikronConnection {
|
||||||
ACTIVE_TASKS.lock().unwrap().push("Listener".to_string());
|
ACTIVE_TASKS.lock().unwrap().push("Listener".to_string());
|
||||||
}
|
}
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while !*SHUTDOWN.read().await {
|
while let Some(msg) = read_half.next().await {
|
||||||
if poll(Duration::from_millis(100)).unwrap() {
|
if *SHUTDOWN.read().await {
|
||||||
if let Some(msg) = read_half.next().await {
|
break;
|
||||||
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(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
ACTIVE_TASKS
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue