Skip to content
Open
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
37 changes: 31 additions & 6 deletions matchbox_socket/src/webrtc_socket/messages.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
//! Messages involved in the "signaling" process.
//!
//! These messages involve the signaling server and are used to establish the direct peer to peer
//! connections.
//! The direct peer to peer messages do not use these types: they use [`crate::Packet`].

use serde::{Deserialize, Serialize};

/// Events go from signaling server to peer
/// Events which go from signaling server to peer.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the wording was intentional here to make it clear that events always go from server to peer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my phrasing, at least to me, this says that a "PeerEvent" is a kind of event which goes from server to peer, and I think thats accurate. There are lots of other kinds of events (For example RTCDataChannelEvent) and this sentence is clarifying that those other events are not PeerEvents.

I think the old phrasing seems like its trying to define the english word event with a really narrow definition, or clarify the server is able to pass events to the peer without stating that those events are PeerEvents.

I do think this would make sense:

PeerEvents go from signaling server to peer.

Given that additional justification, would you prefer that, what I have in the PR, or the original phrasing?

I'm happy to update this and the one below to match based on your preference.

pub type PeerEvent = matchbox_protocol::PeerEvent<PeerSignal>;

/// Requests go from peer to signaling server
/// Requests which go from peer to signaling server.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, vice versa.

pub type PeerRequest = matchbox_protocol::PeerRequest<PeerSignal>;

/// Signals go from peer to peer via the signaling server
/// Signals which go from peer to peer via the signaling server.
///
/// Wrapped by [`PeerRequest::Signal`] on the way to the signaling server,
/// and [`PeerEvent::Signal`] on the from the signalizing server the other peer.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub enum PeerSignal {
/// Ice Candidate
/// [Ice (Interactive Connectivity Establishment) Candidate](https://en.wikipedia.org/wiki/Interactive_Connectivity_Establishment).
// JSON encoding of an [`RTCIceCandidate`](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate).
//
// Note that while [`RTCIceCandidate`](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/RTCIceCandidate)'s
// constructor accepts a string for legacy purposes, that is not how this is being used: this
// is instead a
// [JSON encoding of the of the `RTCIceCandidate`](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/toJSON).
//
// When PeerSignal itself is JSON serialized, that results in JSON data as a string inside of
// another JSON string: this is inefficient (but negligibly so) and reduces type safety.
// It may be preferable refactor the abstraction implemented by the native and wasm sockets to
// have a with a more specific type instead of this to deduplicate their encoding logic
// and help ensure they are well aligned and can interoperate.
IceCandidate(String),
/// Offer
/// Offer a handshake.
///
/// The contained string is the [`sdp`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createOffer#sdp).
Offer(String),
/// Answer
/// Answer accepting a handshake.
///
/// The contained string is the [`sdp`](https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription/sdp).
Answer(String),
}
Loading