Skip to content

Commit

Permalink
Fix example compile errors and clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
caspark committed Dec 16, 2024
1 parent 469e694 commit 0b0dbb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions bevy_matchbox/examples/hello_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ fn start_host_socket(mut commands: Commands) {
commands.insert_resource(socket);
}

fn send_message(mut socket: ResMut<MatchboxSocket<SingleChannel>>) {
fn send_message(mut socket: ResMut<MatchboxSocket>) {
let peers: Vec<_> = socket.connected_peers().collect();

for peer in peers {
let message = "Hello, I'm the host";
info!("Sending message: {message:?} to {peer}");
socket.send(message.as_bytes().into(), peer);
socket.channel_mut(0).send(message.as_bytes().into(), peer);
}
}

fn receive_messages(mut socket: ResMut<MatchboxSocket<SingleChannel>>) {
fn receive_messages(mut socket: ResMut<MatchboxSocket>) {
for (peer, state) in socket.update_peers() {
info!("{peer}: {state:?}");
}

for (_id, message) in socket.receive() {
for (_id, message) in socket.channel_mut(0).receive() {
match std::str::from_utf8(&message) {
Ok(message) => info!("Received message: {message:?}"),
Err(e) => error!("Failed to convert message to string: {e}"),
Expand Down
10 changes: 9 additions & 1 deletion matchbox_socket/src/webrtc_socket/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
error::SignalingError,
messages::PeerSignal,
signal_peer::SignalPeer,
socket::{create_data_channels_ready_fut, new_senders_and_receivers},
socket::create_data_channels_ready_fut,
ChannelConfig, Messenger, Packet, Signaller,
},
RtcIceServerConfig,
Expand Down Expand Up @@ -314,6 +314,14 @@ impl Messenger for NativeMessenger {
}
}

fn new_senders_and_receivers<T>(
channel_configs: &[ChannelConfig],
) -> (Vec<UnboundedSender<T>>, Vec<UnboundedReceiver<T>>) {
(0..channel_configs.len())
.map(|_| futures_channel::mpsc::unbounded())
.unzip()
}

async fn complete_handshake(
trickle: Arc<CandidateTrickle>,
connection: &Arc<RTCPeerConnection>,
Expand Down
8 changes: 0 additions & 8 deletions matchbox_socket/src/webrtc_socket/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,6 @@ impl WebRtcSocket {
}
}

pub(crate) fn new_senders_and_receivers<T>(
channel_configs: &[ChannelConfig],
) -> (Vec<UnboundedSender<T>>, Vec<UnboundedReceiver<T>>) {
(0..channel_configs.len())
.map(|_| futures_channel::mpsc::unbounded())
.unzip()
}

pub(crate) fn create_data_channels_ready_fut(
channel_configs: &[ChannelConfig],
) -> (
Expand Down

0 comments on commit 0b0dbb3

Please sign in to comment.