Skip to content

Commit

Permalink
fix: fix bug for taking channel
Browse files Browse the repository at this point in the history
  • Loading branch information
th4s committed Dec 16, 2024
1 parent 414f973 commit 62c783c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions matchbox_socket/src/webrtc_socket/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,16 +687,22 @@ impl WebRtcSocket {
.ok_or(ChannelError::Taken)
}

/// Converts the [`WebRtcChannel`] into a [`RawPeerChannel`].
pub fn take_raw(
&mut self,
) -> Result<RawPeerChannel<impl AsyncRead, impl AsyncWrite>, ChannelError> {
let remote = self
/// Takes the [`WebRtcChannel`] of a given [`PeerId`].
pub fn take_channel_by_id(&mut self, id: PeerId) -> Result<WebRtcChannel, ChannelError> {
let pos = self
.connected_peers()
.next()
.position(|peer_id| peer_id == id)
.ok_or(ChannelError::NotFound)?;

let channel = self.take_channel(0)?;
self.take_channel(pos)
}

/// Converts the [`WebRtcChannel`] of a given [`PeerId`] into a [`RawPeerChannel`].
pub fn take_raw_by_id(
&mut self,
remote: PeerId,
) -> Result<RawPeerChannel<impl AsyncRead, impl AsyncWrite>, ChannelError> {
let channel = self.take_channel_by_id(remote)?;
let id = self.id();

let (reader, writer) = compat_read_write(remote, channel.rx, channel.tx);
Expand Down

0 comments on commit 62c783c

Please sign in to comment.