pub struct Peer {
pub peer_id: PeerId,
pub direction: PeerDirection,
pub created_at: Instant,
pub connected_at: Option<Instant>,
pub data_channel: Arc<Mutex<Option<Arc<RTCDataChannel>>>>,
pub pending_requests: Arc<Mutex<HashMap<String, PendingRequest>>>,
/* private fields */
}Expand description
WebRTC peer connection with data channel protocol
Fields§
§peer_id: PeerId§direction: PeerDirection§created_at: Instant§connected_at: Option<Instant>§data_channel: Arc<Mutex<Option<Arc<RTCDataChannel>>>>Data channel - can be set from callback when receiving channel from peer
pending_requests: Arc<Mutex<HashMap<String, PendingRequest>>>Implementations§
Source§impl Peer
impl Peer
Sourcepub async fn new(
peer_id: PeerId,
direction: PeerDirection,
my_peer_id: PeerId,
signaling_tx: Sender<SignalingMessage>,
stun_servers: Vec<String>,
) -> Result<Self>
pub async fn new( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, ) -> Result<Self>
Create a new peer connection
Sourcepub async fn new_with_store(
peer_id: PeerId,
direction: PeerDirection,
my_peer_id: PeerId,
signaling_tx: Sender<SignalingMessage>,
stun_servers: Vec<String>,
store: Option<Arc<dyn ContentStore>>,
) -> Result<Self>
pub async fn new_with_store( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, store: Option<Arc<dyn ContentStore>>, ) -> Result<Self>
Create a new peer connection with content store
Sourcepub async fn new_with_store_and_events(
peer_id: PeerId,
direction: PeerDirection,
my_peer_id: PeerId,
signaling_tx: Sender<SignalingMessage>,
stun_servers: Vec<String>,
store: Option<Arc<dyn ContentStore>>,
state_event_tx: Option<Sender<PeerStateEvent>>,
nostr_relay: Option<Arc<NostrRelay>>,
) -> Result<Self>
pub async fn new_with_store_and_events( peer_id: PeerId, direction: PeerDirection, my_peer_id: PeerId, signaling_tx: Sender<SignalingMessage>, stun_servers: Vec<String>, store: Option<Arc<dyn ContentStore>>, state_event_tx: Option<Sender<PeerStateEvent>>, nostr_relay: Option<Arc<NostrRelay>>, ) -> Result<Self>
Create a new peer connection with content store and state event channel
Sourcepub fn set_store(&mut self, store: Arc<dyn ContentStore>)
pub fn set_store(&mut self, store: Arc<dyn ContentStore>)
Set content store
Sourcepub fn state(&self) -> RTCPeerConnectionState
pub fn state(&self) -> RTCPeerConnectionState
Get connection state
Sourcepub fn signaling_state(&self) -> RTCSignalingState
pub fn signaling_state(&self) -> RTCSignalingState
Get signaling state
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected
Sourcepub async fn setup_handlers(&mut self) -> Result<()>
pub async fn setup_handlers(&mut self) -> Result<()>
Setup event handlers for the peer connection
Sourcepub async fn connect(&mut self) -> Result<Value>
pub async fn connect(&mut self) -> Result<Value>
Initiate connection (create offer) - for outbound connections
Sourcepub async fn handle_offer(&mut self, offer: Value) -> Result<Value>
pub async fn handle_offer(&mut self, offer: Value) -> Result<Value>
Handle incoming offer and create answer
Sourcepub async fn handle_answer(&mut self, answer: Value) -> Result<()>
pub async fn handle_answer(&mut self, answer: Value) -> Result<()>
Handle incoming answer
Sourcepub async fn handle_candidate(&mut self, candidate: Value) -> Result<()>
pub async fn handle_candidate(&mut self, candidate: Value) -> Result<()>
Handle incoming ICE candidate
Sourcepub fn has_data_channel(&self) -> bool
pub fn has_data_channel(&self) -> bool
Check if data channel is ready
Sourcepub async fn request(&self, hash_hex: &str) -> Result<Option<Vec<u8>>>
pub async fn request(&self, hash_hex: &str) -> Result<Option<Vec<u8>>>
Request content by hash from this peer
Sourcepub async fn send_message(&self, msg: &DataMessage) -> Result<()>
pub async fn send_message(&self, msg: &DataMessage) -> Result<()>
Send a message over the data channel
Auto Trait Implementations§
impl Freeze for Peer
impl !RefUnwindSafe for Peer
impl Send for Peer
impl Sync for Peer
impl Unpin for Peer
impl !UnwindSafe for Peer
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more