mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-28 15:40:54 +03:00
release capture if emulation disabled on target
This commit is contained in:
@@ -224,27 +224,41 @@ impl ClientManager {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn set_active_addr(&self, handle: u64, addr: Option<SocketAddr>) {
|
||||
pub(crate) fn set_active_addr(&self, handle: ClientHandle, addr: Option<SocketAddr>) {
|
||||
if let Some((_, s)) = self.clients.borrow_mut().get_mut(handle as usize) {
|
||||
s.active_addr = addr;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn active_addr(&self, handle: u64) -> Option<SocketAddr> {
|
||||
pub(crate) fn set_alive(&self, handle: ClientHandle, alive: bool) {
|
||||
if let Some((_, s)) = self.clients.borrow_mut().get_mut(handle as usize) {
|
||||
s.alive = alive;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn active_addr(&self, handle: ClientHandle) -> Option<SocketAddr> {
|
||||
self.clients
|
||||
.borrow()
|
||||
.get(handle as usize)
|
||||
.and_then(|(_, s)| s.active_addr)
|
||||
}
|
||||
|
||||
pub(crate) fn get_port(&self, handle: u64) -> Option<u16> {
|
||||
pub(crate) fn alive(&self, handle: ClientHandle) -> bool {
|
||||
self.clients
|
||||
.borrow()
|
||||
.get(handle as usize)
|
||||
.map(|(_, s)| s.alive)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub(crate) fn get_port(&self, handle: ClientHandle) -> Option<u16> {
|
||||
self.clients
|
||||
.borrow()
|
||||
.get(handle as usize)
|
||||
.map(|(c, _)| c.port)
|
||||
}
|
||||
|
||||
pub(crate) fn get_ips(&self, handle: u64) -> Option<HashSet<IpAddr>> {
|
||||
pub(crate) fn get_ips(&self, handle: ClientHandle) -> Option<HashSet<IpAddr>> {
|
||||
self.clients
|
||||
.borrow()
|
||||
.get(handle as usize)
|
||||
|
||||
@@ -33,6 +33,8 @@ pub(crate) enum LanMouseConnectionError {
|
||||
Webrtc(#[from] webrtc_util::Error),
|
||||
#[error("not connected")]
|
||||
NotConnected,
|
||||
#[error("emulation is disabled on the target device")]
|
||||
TargetEmulationDisabled,
|
||||
}
|
||||
|
||||
async fn connect(
|
||||
@@ -104,6 +106,9 @@ impl LanMouseConnection {
|
||||
conns.get(&addr).cloned()
|
||||
};
|
||||
if let Some(conn) = conn {
|
||||
if !self.server.client_manager.alive(handle) {
|
||||
return Err(LanMouseConnectionError::TargetEmulationDisabled);
|
||||
}
|
||||
log::trace!("{event} >->->->->- {addr}");
|
||||
match conn.send(buf).await {
|
||||
Ok(_) => return Ok(()),
|
||||
@@ -220,7 +225,10 @@ async fn receive_loop(
|
||||
while let Ok(_) = conn.recv(&mut buf).await {
|
||||
if let Ok(event) = buf.try_into() {
|
||||
match event {
|
||||
ProtoEvent::Pong => server.client_manager.set_active_addr(handle, Some(addr)),
|
||||
ProtoEvent::Pong(b) => {
|
||||
server.client_manager.set_active_addr(handle, Some(addr));
|
||||
server.client_manager.set_alive(handle, b);
|
||||
}
|
||||
event => tx.send((handle, event)).expect("channel closed"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Emulation {
|
||||
listener.reply(addr, ProtoEvent::Ack(0)).await;
|
||||
}
|
||||
ProtoEvent::Input(event) => emulation_proxy.consume(event, addr),
|
||||
ProtoEvent::Ping => listener.reply(addr, ProtoEvent::Pong).await,
|
||||
ProtoEvent::Ping => listener.reply(addr, ProtoEvent::Pong(server.emulation_status.get() == Status::Enabled)).await,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user