Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connection): 🐛 Try localhost if broadcast fails, fixes wifi being required for cabled #1962

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const INITIAL_MESSAGE: &str = concat!(
"Open ALVR on your PC then click \"Trust\"\n",
"next to the client entry",
);
const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the internet";
const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the streamer.\nNetwork error.";
const SUCCESS_CONNECT_MESSAGE: &str = "Successful connection!\nPlease wait...";
const LOCAL_TRY_MESSAGE: &str = "Trying to connect to localhost...";
// const INCOMPATIBLE_VERSIONS_MESSAGE: &str = concat!(
// "Streamer and client have\n",
// "incompatible types.\n",
Expand Down Expand Up @@ -135,24 +137,32 @@ fn connection_pipeline(
return Ok(());
}

if let Err(e) = announcer_socket.broadcast() {
warn!("Broadcast error: {e:?}");
let mut is_broadcast_ok = false;
if let Err(e) = announcer_socket.announce_broadcast() {
debug!("Couldn't announce to localhost, retrying on local... {e:}");

set_hud_message(NETWORK_UNREACHABLE_MESSAGE);

thread::sleep(RETRY_CONNECT_MIN_INTERVAL);

set_hud_message(INITIAL_MESSAGE);

return Ok(());
set_hud_message(LOCAL_TRY_MESSAGE);
} else {
is_broadcast_ok = true;
}

if let Ok(pair) = ProtoControlSocket::connect_to(
DISCOVERY_RETRY_PAUSE,
PeerType::Server(&listener_socket),
) {
set_hud_message(SUCCESS_CONNECT_MESSAGE);
break pair;
}

if !is_broadcast_ok {
warn!("Couldn't announce to network or connect to localhost.");
set_hud_message(NETWORK_UNREACHABLE_MESSAGE);

thread::sleep(RETRY_CONNECT_MIN_INTERVAL);

set_hud_message(INITIAL_MESSAGE);
return Ok(());
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion alvr/client_core/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl AnnouncerSocket {
Ok(Self { socket, packet })
}

pub fn broadcast(&self) -> Result<()> {
pub fn announce_broadcast(&self) -> Result<()> {
self.socket
.send_to(&self.packet, (Ipv4Addr::BROADCAST, CONTROL_PORT))?;

Expand Down
1 change: 0 additions & 1 deletion wiki/Use-ALVR-through-a-USB-connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

* If your headset is detected, click "Trust." Click "Edit", "Add new" and change the IP address to `127.0.0.1`.
* If your headset is not detected, click "Add client manually" and use the IP address `127.0.0.1`. Use the hostname displayed on your headset screen.
* Turn off client discovery in Settings > Connection.
* Switch the connection streaming protocol to TCP in Settings > Connection.

## Letting your PC communicate with your HMD
Expand Down
Loading