fixes for kickout

This commit is contained in:
Piyush मिश्रः 2021-05-23 00:31:27 +05:30
parent 59a9863838
commit 784b0f2017
3 changed files with 15 additions and 16 deletions

View File

@ -282,19 +282,19 @@ impl Handler<ms::pind::LeaveVayakti> for ChatPinnd {
fn handle(&mut self, msg: ms::pind::LeaveVayakti, _: &mut Self::Context) -> Self::Result { fn handle(&mut self, msg: ms::pind::LeaveVayakti, _: &mut Self::Context) -> Self::Result {
if let Some(kaksh_kunjika) = &msg.kaksh_kunjika { if let Some(kaksh_kunjika) = &msg.kaksh_kunjika {
if let Some(kaksh) = self.kaksh.get_mut(kaksh_kunjika) { if let Some(kaksh) = self.kaksh.get_mut(kaksh_kunjika) {
let name = if let Some(i) = kaksh.loog.iter().position(|x| x.addr == msg.addr) { if kaksh.loog.len() > 1 {
kaksh.loog.remove(i).name let name = if let Some(i) = kaksh.loog.iter().position(|x| x.addr == msg.addr) {
} else { "".to_owned() }; kaksh.loog.remove(i).name
} else { "".to_owned() };
if kaksh.loog.len() == 0 {
self.kaksh.remove(kaksh_kunjika);
} else {
kaksh.loog.iter().for_each(|a| { kaksh.loog.iter().for_each(|a| {
a.addr.do_send(ms::sansad::WsDisconnected { a.addr.do_send(ms::sansad::WsDisconnected {
kunjika: msg.kunjika.to_owned(), kunjika: msg.kunjika.to_owned(),
name: name.to_owned() name: name.to_owned()
}) })
}); });
} else {
self.kaksh.remove(kaksh_kunjika);
} }
} }
} }

View File

@ -35,9 +35,9 @@ const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
const CLIENT_TIMEOUT: Duration = Duration::from_secs(15); const CLIENT_TIMEOUT: Duration = Duration::from_secs(15);
/// How often heartbeat pings are sent /// How often heartbeat pings are sent
const SPECIAL_HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5 * 60); const SPECIAL_HEARTBEAT_INTERVAL: Duration = Duration::from_secs(3*60);
/// How long before lack of client response causes a timeout /// How long before lack of client response causes a timeout
const SPECIAL_CLIENT_TIMEOUT: Duration = Duration::from_secs(15 * 60); const SPECIAL_CLIENT_TIMEOUT: Duration = Duration::from_secs(15*60);
pub struct WsSansad { pub struct WsSansad {
kunjika: String, kunjika: String,
@ -66,7 +66,7 @@ impl Actor for WsSansad {
fn stopping(&mut self, _: &mut Self::Context) -> Running { fn stopping(&mut self, _: &mut Self::Context) -> Running {
tokio::runtime::Runtime::new().unwrap() tokio::runtime::Runtime::new().unwrap()
.block_on(self.leave_kaksh());// notify leaving .block_on(self.leave_kaksh());// notify leaving
Running::Stop Running::Stop
} }
} }
@ -143,6 +143,7 @@ impl WsSansad {
// don't try to send a ping // don't try to send a ping
return; return;
} }
ctx.ping(b"");
}); });
} }

View File

@ -42,15 +42,13 @@ socket.onopen = function(event) {
socket.onerror = function(event) { socket.onerror = function(event) {
$('#initerror').text('Warning: Failed to connect websocket! Refresh the '+ $('#initerror').text('Warning: Failed to connect websocket! Refresh the '+
'page and if still don\'t work upgrade Web Browser'); 'page and if still don\'t work upgrade Web Browser');
socket.close()
} }
socket.onclose = function (e) { socket.onclose = function (e) {
if(actions.has_key('leave')) return; Messages.pushStatus('Connection failed!\nRefresh page');
actions.clear(); $('[name="error_msg"]').text('Connection failed! Refresh page');
myinfo.kunjika = ''; $('[name="error_msg"]').removeClass('is-hidden');
myinfo.name = '';
State.login();
State.hideProgress();
} }
// Listen for messages // Listen for messages