Skip to content

Docs for webrtc_socket/messages.rs#543

Open
Craig-Macomber wants to merge 2 commits intojohanhelsing:mainfrom
Craig-Macomber:messages-docs
Open

Docs for webrtc_socket/messages.rs#543
Craig-Macomber wants to merge 2 commits intojohanhelsing:mainfrom
Craig-Macomber:messages-docs

Conversation

@Craig-Macomber
Copy link
Copy Markdown
Contributor

Previously it was not particularly clear that nothing in messages.ts was used for actual peer to peer messages, and its specific to signaling. I have added some top level docs to make this clear, and filling in the lower level docs to make it clear what the content of the various strings are.

These details were determined by inspecting the code. If there is an intention for this to be more general than how the current native and wasm implementation use them, then these detail might be wrong, but I think the intention is that these always contain the strings as I have described them.

Copy link
Copy Markdown
Owner

@johanhelsing johanhelsing left a comment

Choose a reason for hiding this comment

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

Thanks, getting the protocol well-documented is important in order to make the project approachable for newcomers.

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.

Comment on lines +32 to +33
/// safety and clarity at this layer. It may be preferable to instead include the structured
/// data here as more specific Rust types, but this would be a breaking protocol change, and
Copy link
Copy Markdown
Owner

@johanhelsing johanhelsing Feb 21, 2026

Choose a reason for hiding this comment

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

This looks it should probably be an regular (implementation) comment and not a doc comment.

The reason for using string was that most documentation for webrtc state that you should treat this payload black boxes. I was thinking that trying to parse it would only lead to maintanance burden for no benefit.

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.

most documentation for webrtc state that you should treat this payload black boxes

That can't apply here, where we have to encode and parse this string in both the native and wasm socket implementations. It makes sense for the server however (which doesn't use this type).
What can (and should be opaque here) is the candidate string and stuff like that. The object that contains that property however doesn't really seem like something that needs to be opaque on the socket end.

That said, when I wrote this, I intended the audience to be maintainers of the wasm and native socket implementations (as thats the code interfacing with this type), and thus this being a doc comment makes sense. I missed that these types are exported from the crate for use in custom signalers which also should treat this as opaque.

Because of that making this structured data likely doesn't make sense and some other solution should be done to dedupe the logic between wasm and native, and provide them with stronger typing to keep them aligned. I have adjusted the comment accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants