Crate str0m

source ·
Expand description

str0m

A WebRTC implementation in Rust.

This is a Sans I/O implementation meaning the Rtc instance itself is not doing any network talking. Furthermore it has no internal threads or async tasks. All operations are synchronously happening from the calls of the public API.

Output from the instance can be grouped into three kinds.

  1. Events (such as receiving media or data channel data).
  2. Network output. Data to be sent, typically from a UDP socket.
  3. Timeouts. When the instance expects a time input.

Input to the Rtc instance is:

  1. User operations (such as sending media or data channel data).
  2. Network input. Typically read from a UDP socket.
  3. Timeouts. As obtained from the output above.

The correct use can be described like below (or seen in the examples). The TODO lines is where the user would fill in their code.

let mut rtc = Rtc::new();

loop {
    let timeout = match rtc.poll_output().unwrap() {
        Output::Timeout(v) => v,
        Output::Transmit(t) => {
            // TODO: Send data to remote peer.
            continue; // poll again
        }
        Output::Event(e) => {
            // TODO: Handle event.
            continue; // poll again
        }
    };

    // TODO: Wait for one of two events, reaching `timeout`
    //       or receiving network input. Both are encapsualted
    //       in the Input enum.
    let input: Input = todo!();

    rtc.handle_input(input).unwrap();
}

Modules

Data channel related types.
Various error types.
Media (audio/video) related content.
Network related types to get socket data in/out of Rtc.
Statistics data carried by Event.

Structs

SDP answer. Answers can be serialized via serde.
ICE candidates are network addresses used to connect to a peer.
Changes to apply to the m-lines of the WebRTC session.
SDP offer. Offers can be serialized via serde.
Changes waiting to be applied to the Rtc.
Instance that does WebRTC. Main struct of the entire library.
Customised config for creating an Rtc instance.

Enums

Events produced by Rtc::poll_output().
States the ICE connection can be in.
Input as expected by Rtc::handle_input(). Either network data or a timeout.
Output produced by Rtc::poll_output()
Errors for the whole Rtc engine.