Skip to content

Commit d559109

Browse files
authored
Add connection status on client entries (#1688)
1 parent 93a21e5 commit d559109

File tree

8 files changed

+54
-15
lines changed

8 files changed

+54
-15
lines changed

alvr/dashboard/src/dashboard/components/connections.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
theme::{self, log_colors},
44
};
55
use alvr_packets::ClientListAction;
6-
use alvr_session::{ClientConnectionConfig, SessionConfig};
6+
use alvr_session::{ClientConnectionConfig, ConnectionState, SessionConfig};
77
use eframe::{
88
egui::{Frame, Grid, Layout, RichText, TextEdit, Ui, Window},
99
emath::{Align, Align2},
@@ -127,6 +127,11 @@ impl ConnectionsTab {
127127
.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
128128
data.display_name
129129
));
130+
if data.connection_state == ConnectionState::Disconnected {
131+
ui.colored_label(Color32::GRAY, "Disconnected");
132+
} else {
133+
ui.colored_label(theme::OK_GREEN, "Streaming");
134+
}
130135
});
131136
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
132137
if ui.button("Remove").clicked() {

alvr/dashboard/src/dashboard/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ impl eframe::App for Dashboard {
249249
ui.with_layout(
250250
Layout::bottom_up(Align::Center).with_cross_justify(true),
251251
|ui| {
252-
use eframe::epaint::Color32;
253-
254252
ui.add_space(5.0);
255253

256254
if connected_to_server {
@@ -263,12 +261,12 @@ impl eframe::App for Dashboard {
263261

264262
ui.horizontal(|ui| {
265263
ui.add_space(5.0);
266-
ui.label("Streamer:");
264+
ui.label("SteamVR:");
267265
ui.add_space(-10.0);
268266
if connected_to_server {
269-
ui.label(RichText::new("Connected").color(Color32::GREEN));
267+
ui.label(RichText::new("Connected").color(theme::OK_GREEN));
270268
} else {
271-
ui.label(RichText::new("Disconnected").color(Color32::RED));
269+
ui.label(RichText::new("Disconnected").color(theme::KO_RED));
272270
}
273271
})
274272
},

alvr/dashboard/src/data_sources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl DataSources {
175175
| ServerRequest::InsertIdr
176176
| ServerRequest::StartRecording
177177
| ServerRequest::StopRecording => {
178-
warn!("Cannot perform action, streamer is not connected.")
178+
warn!("Cannot perform action, streamer (SteamVR) is not connected.")
179179
}
180180
ServerRequest::RestartSteamvr | ServerRequest::ShutdownSteamvr => {
181181
warn!("SteamVR not launched")

alvr/dashboard/src/theme.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub const SELECTED: Color32 = Color32::from_rgb(120, 174, 237);
1010
pub const FG: Color32 = Color32::from_rgb(250, 250, 250);
1111

1212
pub const OK_GREEN: Color32 = Color32::GREEN;
13+
pub const KO_RED: Color32 = Color32::RED;
1314

1415
pub mod log_colors {
1516
use super::ACCENT;

alvr/packets/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alvr_common::{
22
glam::{UVec2, Vec2},
33
DeviceMotion, Fov, LogEntry, LogSeverity, Pose,
44
};
5-
use alvr_session::{CodecType, SessionConfig};
5+
use alvr_session::{CodecType, ConnectionState, SessionConfig};
66
use serde::{Deserialize, Serialize};
77
use std::{
88
fmt::{self, Debug},
@@ -193,6 +193,7 @@ pub enum ClientListAction {
193193
SetManualIps(Vec<IpAddr>),
194194
RemoveEntry,
195195
UpdateCurrentIp(Option<IpAddr>),
196+
SetConnectionState(ConnectionState),
196197
}
197198

198199
#[derive(Serialize, Deserialize, Default, Clone)]

alvr/server/src/connection.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use alvr_packets::{
2424
ButtonValue, ClientConnectionResult, ClientControlPacket, ClientListAction, ClientStatistics,
2525
ServerControlPacket, StreamConfigPacket, Tracking, AUDIO, HAPTICS, STATISTICS, TRACKING, VIDEO,
2626
};
27-
use alvr_session::{CodecType, ControllersEmulationMode, FrameSize, OpenvrConfig};
27+
use alvr_session::{CodecType, ConnectionState, ControllersEmulationMode, FrameSize, OpenvrConfig};
2828
use alvr_sockets::{
2929
spawn_cancelable, ControlSocketReceiver, ControlSocketSender, PeerType, ProtoControlSocket,
3030
StreamSocketBuilder, KEEPALIVE_INTERVAL,
@@ -506,11 +506,19 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> IntResult {
506506
}
507507

508508
// close stream on Drop (manual disconnection or execution canceling)
509-
struct StreamCloseGuard(Arc<RelaxedAtomic>);
509+
struct StreamCloseGuard {
510+
is_streaming: Arc<RelaxedAtomic>,
511+
streaming_hostname: String,
512+
}
510513

511514
impl Drop for StreamCloseGuard {
512515
fn drop(&mut self) {
513-
self.0.set(false);
516+
self.is_streaming.set(false);
517+
518+
SERVER_DATA_MANAGER.write().update_client_list(
519+
self.streaming_hostname.clone(),
520+
ClientListAction::SetConnectionState(ConnectionState::Disconnected),
521+
);
514522

515523
*VIDEO_RECORDING_FILE.lock() = None;
516524

@@ -611,7 +619,15 @@ async fn connection_pipeline(
611619
unsafe { crate::InitializeStreaming() };
612620

613621
let is_streaming = Arc::new(RelaxedAtomic::new(true));
614-
let _stream_guard = StreamCloseGuard(Arc::clone(&is_streaming));
622+
let _stream_guard = StreamCloseGuard {
623+
is_streaming: Arc::clone(&is_streaming),
624+
streaming_hostname: client_hostname.clone(),
625+
};
626+
627+
SERVER_DATA_MANAGER.write().update_client_list(
628+
client_hostname.clone(),
629+
ClientListAction::SetConnectionState(ConnectionState::Streaming),
630+
);
615631

616632
let game_audio_loop: BoxFuture<_> = if let Switch::Enabled(config) = settings.audio.game_audio {
617633
let sender = stream_socket.request_stream(AUDIO).await?;

alvr/server_io/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use openvrpaths::*;
99
use alvr_common::prelude::*;
1010
use alvr_events::EventType;
1111
use alvr_packets::{AudioDevicesList, ClientListAction, GpuVendor, PathSegment, PathValuePair};
12-
use alvr_session::{ClientConnectionConfig, SessionConfig, Settings};
12+
use alvr_session::{ClientConnectionConfig, ConnectionState, SessionConfig, Settings};
1313
use cpal::traits::{DeviceTrait, HostTrait};
1414
use serde_json as json;
1515
use std::{
@@ -216,10 +216,11 @@ impl ServerDataManager {
216216
} => {
217217
if let Entry::Vacant(new_entry) = maybe_client_entry {
218218
let client_connection_desc = ClientConnectionConfig {
219-
trusted,
219+
display_name: "Unknown".into(),
220220
current_ip: None,
221221
manual_ips: manual_ips.into_iter().collect(),
222-
display_name: "Unknown".into(),
222+
trusted,
223+
connection_state: ConnectionState::Disconnected,
223224
};
224225
new_entry.insert(client_connection_desc);
225226

@@ -259,6 +260,15 @@ impl ServerDataManager {
259260
if entry.get().current_ip != current_ip {
260261
entry.get_mut().current_ip = current_ip;
261262

263+
updated = true;
264+
}
265+
}
266+
}
267+
ClientListAction::SetConnectionState(state) => {
268+
if let Entry::Occupied(mut entry) = maybe_client_entry {
269+
if entry.get().connection_state != state {
270+
entry.get_mut().connection_state = state;
271+
262272
updated = true;
263273
}
264274
}

alvr/session/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,20 @@ pub struct OpenvrConfig {
9696
pub amd_bitrate_corruption_fix: bool,
9797
}
9898

99+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
100+
pub enum ConnectionState {
101+
Disconnected,
102+
Connected,
103+
Streaming,
104+
}
105+
99106
#[derive(Serialize, Deserialize, Clone, Debug)]
100107
pub struct ClientConnectionConfig {
101108
pub display_name: String,
102109
pub current_ip: Option<IpAddr>,
103110
pub manual_ips: HashSet<IpAddr>,
104111
pub trusted: bool,
112+
pub connection_state: ConnectionState,
105113
}
106114

107115
#[derive(Serialize, Deserialize, Clone, Debug)]

0 commit comments

Comments
 (0)