Skip to content

Commit

Permalink
Merge pull request #101 from vectorgameexperts/socket-cleanup
Browse files Browse the repository at this point in the history
- Add cfg-if to organize `webrtc_socket/mod.rs`
- Move the socket models into a new file, `webrtc_socket/socket.rs`
- Remove `WebRtcSocket::default`, but add `WebRtcSocket::new_unreliable` and `WebRtcSocket::new_reliable`. Demos now use unreliable, since that was the prior default.
- Fix clippy lints
  • Loading branch information
johanhelsing authored Feb 23, 2023
2 parents fdd7f1a + ac22a61 commit c9d10cb
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 442 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion matchbox_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn start_matchbox_socket(mut commands: Commands, args: Res<Args>) {

let room_url = format!("{}/{}", &args.matchbox, room_id);
info!("connecting to matchbox server: {:?}", room_url);
let (socket, message_loop) = WebRtcSocket::new(room_url);
let (socket, message_loop) = WebRtcSocket::new_unreliable(room_url);

// The message loop needs to be awaited, or nothing will happen.
// We do this here using bevy's task system.
Expand Down
4 changes: 1 addition & 3 deletions matchbox_server/src/signaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ async fn handle_ws(

#[cfg(test)]
mod tests {
use crate::signaling::PeerEvent;
use crate::{signaling::PeerEvent, ws_handler, ServerState};
use axum::{routing::get, Router};
use futures::{lock::Mutex, pin_mut, SinkExt, StreamExt};
use std::{
Expand All @@ -297,8 +297,6 @@ mod tests {
use tokio::{net::TcpStream, select, time};
use tokio_tungstenite::{tungstenite::Message, MaybeTlsStream, WebSocketStream};

use super::{ws_handler, ServerState};

fn app() -> Router {
Router::new()
.route("/:room_id", get(ws_handler))
Expand Down
2 changes: 1 addition & 1 deletion matchbox_simple_demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() {

async fn async_main() {
info!("Connecting to matchbox");
let (mut socket, loop_fut) = WebRtcSocket::new("ws://localhost:3536/example_room");
let (mut socket, loop_fut) = WebRtcSocket::new_unreliable("ws://localhost:3536/example_room");

info!("my id is {:?}", socket.id());

Expand Down
1 change: 1 addition & 0 deletions matchbox_socket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
uuid = { version = "1.0", default-features = false, features = ["v4"] }
log = { version = "0.4", default-features = false }
thiserror = "1.0"
cfg-if = "1.0"

# ggrs-socket
ggrs = { version = "0.9.3", default-features = false, optional = true }
Expand Down
5 changes: 4 additions & 1 deletion matchbox_socket/src/webrtc_socket/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::webrtc_socket::messages::PeerEvent;
use futures_channel::mpsc::TrySendError;

/// An error that can occur with WebRTC signalling.
#[derive(Debug, thiserror::Error)]
pub enum SignallingError {
// Common
#[error("failed to send event to signalling server")]
Undeliverable(#[from] futures_channel::mpsc::TrySendError<super::messages::PeerEvent>),
Undeliverable(#[from] TrySendError<PeerEvent>),
#[error("The stream is exhausted")]
StreamExhausted,

Expand Down
1 change: 1 addition & 0 deletions matchbox_socket/src/webrtc_socket/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum PeerRequest {
KeepAlive,
}

/// Signals go from peer to peer
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum PeerSignal {
IceCandidate(String),
Expand Down
Loading

0 comments on commit c9d10cb

Please sign in to comment.