Skip to content

Request life cycle ​

What happens between a client sending a byte and a plugin seeing a message, and back. This is a map for reading the code; follow the file names for detail.

A Janus API request ​

  1. A listener accepts it. HTTP (janus/src/http_listener.rs, on hyper), WebSockets (ws_listener.rs, tungstenite), or the MQTT, RabbitMQ, Unix-socket and nanomsg listeners. Each does only what its C transport does: framing, routing the path to ids, CORS, ACLs, replying.
  2. The core dispatches it. janus_core::api validates the JSON the way janus.c does, in the same order (so the same error code comes out for the same mistake), finds the session and handle, and checks apisecret or the token.
  3. A plugin handles it. For message, the core calls Plugin::handle_message with the body and JSEP. The plugin answers at once (the reply becomes success) or says it will answer later, and the core sends ack. Later answers go through PluginCallbacks::push_event.
  4. The reply goes back to the transport the session came from; for HTTP it waits in the session's queue until a long poll takes it.

Replies and events keep the order the C server gives them: the ack of a message always precedes its event (PARITY_LOG.md has the decision).

Media ​

  1. The JSEP offer and answer pass through the core, which merges them with the plugin's SDP as sdp.c does and starts an ICE agent for the handle.
  2. The binary binds the UDP sockets (janus/src/ice_socket.rs) and feeds packets to the sans-IO janus-ice agent, then janus-dtls for the handshake, which yields the SRTP keys for janus-srtp.
  3. Decrypted RTP and RTCP go to the plugin through Plugin::incoming_rtp and incoming_rtcp. A plugin does not send packets. It returns a list of relay decisions, each naming a target handle and a packet (ADR-0005); the core performs them, protects them and sends them.
  4. Data channels run SCTP over the same DTLS (janus-sctp), and plugins see incoming_data and call relay_data.

Why this shape ​

Sockets live in one place, so every state machine can be tested with plain byte arrays, and the replay harness can drive the whole server over HTTP. The cost is that some paths cross several layers; the C line numbers in comments are how to find the counterpart in the original.

GPL-3.0-or-later, like the Janus gateway it ports.