#include <icy/webrtc/peersession.h>Manages a WebRTC peer connection lifecycle over any signalling transport that implements SignallingInterface.
Works with SympleSignaller (Symple call protocol), WebSocketSignaller (plain JSON over WSS), or any custom implementation.
Media is optional. Set [Config::media](icy-wrtc-PeerSession-Config.html#media-2) codecs to enable tracks. Leave codec encoders empty for data-channel-only sessions.
| Return | Name | Description |
|---|---|---|
ThreadSignal< void(State)> | StateChanged | Emitted whenever the session state changes. Parameter: new State value. |
ThreadSignal< void(const std::string &)> | IncomingCall | Emitted when a remote peer initiates a call (state transitions to IncomingInit). Parameter: remote peer identifier. |
ThreadSignal< void(rtc::message_variant)> | DataReceived | Emitted when a message arrives on the data channel. Parameter: rtc::message_variant (string or binary). |
ThreadSignal< void(State)> StateChangedEmitted whenever the session state changes. Parameter: new State value.
ThreadSignal< void(const std::string &)> IncomingCallEmitted when a remote peer initiates a call (state transitions to IncomingInit). Parameter: remote peer identifier.
ThreadSignal< void(rtc::message_variant)> DataReceivedEmitted when a message arrives on the data channel. Parameter: rtc::message_variant (string or binary).
| Return | Name | Description |
|---|---|---|
PeerSession | Construct with any signalling implementation. The signaller must outlive this PeerSession. | |
PeerSession | Deleted copy constructor; PeerSession owns live signalling and RTC callbacks. | |
void | call | Initiate an outgoing call to a remote peer. Sends a "init" control message and transitions to OutgoingInit. |
void | accept | Accept an incoming call. Creates the PeerConnection, sends "accept", and transitions to Negotiating. |
void | reject | Reject an incoming call. Sends a "reject" control message and transitions to Ended. |
void | hangup | Terminate any non-idle call phase. Sends a "hangup" control message, closes the PeerConnection, and transitions to Ended. Safe to call from any non-Idle/Ended state. |
void | sendData | Send a UTF-8 string message over the data channel. Silently dropped if the data channel is not open. |
void | sendData | Send raw binary data over the data channel. Silently dropped if the data channel is not open. |
State | state const | Current session state. Thread-safe. |
std::string | remotePeerId const | Identifier of the remote peer for the current or most recent call. Empty when Idle. |
MediaBridge & | media | Media bridge for this session. Valid for the lifetime of the PeerSession. |
const MediaBridge & | media const | Media bridge for this session. Valid for the lifetime of the PeerSession. |
std::shared_ptr< rtc::PeerConnection > | peerConnection | The underlying PeerConnection, or nullptr when Idle/Ended. |
std::shared_ptr< rtc::DataChannel > | dataChannel | The data channel, or nullptr if none is open. |
PeerSession(SignallingInterface & signaller, const Config & config)Construct with any signalling implementation. The signaller must outlive this PeerSession.
PeerSession(const PeerSession &) = deleteDeleted copy constructor; PeerSession owns live signalling and RTC callbacks.
void call(const std::string & peerId)Initiate an outgoing call to a remote peer. Sends a "init" control message and transitions to OutgoingInit.
peerId Remote peer identifier passed to the signaller.std::logic_error if not currently in the Idle state.void accept()Accept an incoming call. Creates the PeerConnection, sends "accept", and transitions to Negotiating.
std::logic_error if not currently in the IncomingInit state.void reject(const std::string & reason)Reject an incoming call. Sends a "reject" control message and transitions to Ended.
reason Human-readable reason string forwarded to the remote peer.std::logic_error if not currently in the IncomingInit state.void hangup(const std::string & reason)Terminate any non-idle call phase. Sends a "hangup" control message, closes the PeerConnection, and transitions to Ended. Safe to call from any non-Idle/Ended state.
reason Human-readable reason string forwarded to the remote peer.void sendData(const std::string & message)Send a UTF-8 string message over the data channel. Silently dropped if the data channel is not open.
message String to send.void sendData(const std::byte * data, size_t size)Send raw binary data over the data channel. Silently dropped if the data channel is not open.
data Pointer to the byte buffer.
size Number of bytes to send.
const
State state() constCurrent session state. Thread-safe.
const
std::string remotePeerId() constIdentifier of the remote peer for the current or most recent call. Empty when Idle.
MediaBridge & media()Media bridge for this session. Valid for the lifetime of the PeerSession.
const
const MediaBridge & media() constMedia bridge for this session. Valid for the lifetime of the PeerSession.
std::shared_ptr< rtc::PeerConnection > peerConnection()The underlying PeerConnection, or nullptr when Idle/Ended.
std::shared_ptr< rtc::DataChannel > dataChannel()The data channel, or nullptr if none is open.
| Name | Description |
|---|---|
State | High-level lifecycle phases for a single peer-to-peer call session. |
enum StateHigh-level lifecycle phases for a single peer-to-peer call session.
| Value | Description |
|---|---|
Idle | No active call. |
OutgoingInit | Outgoing call announced, waiting for accept/reject. |
IncomingInit | Incoming call announced, waiting for accept/reject. |
Negotiating | PeerConnection exists and SDP/ICE negotiation is in progress. |
Active | Media or data is flowing. |
Ending | Local teardown is in progress. |
Ended | Call ended (transient; auto-resets to Idle) |
| Return | Name | Description |
|---|---|---|
SignallingInterface & | _signaller | |
Config | _config | |
MediaBridge | _media | |
State | _state | |
std::string | _remotePeerId | |
std::shared_ptr< rtc::PeerConnection > | _pc | |
std::shared_ptr< rtc::DataChannel > | _dc | |
std::shared_ptr< CallbackGuard > | _callbackGuard | |
bool | _remoteDescriptionSet | |
std::vector< PendingCandidate > | _pendingRemoteCandidates | |
Synchronizer | _callbackSync | |
std::deque< std::function< void()> > | _pendingCallbacks | |
std::mutex | _callbackMutex | |
std::mutex | _mutex |
SignallingInterface & _signallerConfig _configMediaBridge _mediaState _state = std::string _remotePeerIdstd::shared_ptr< rtc::PeerConnection > _pcstd::shared_ptr< rtc::DataChannel > _dcstd::shared_ptr< CallbackGuard > _callbackGuard = std::make_shared<CallbackGuard>()bool _remoteDescriptionSet = falsestd::vector< PendingCandidate > _pendingRemoteCandidatesSynchronizer _callbackSyncstd::deque< std::function< void()> > _pendingCallbacksstd::mutex _callbackMutexstd::mutex _mutex| Return | Name | Description |
|---|---|---|
void | onSdpReceived | |
void | onCandidateReceived | |
void | onControlReceived | |
std::shared_ptr< rtc::PeerConnection > | createPeerConnection | |
void | setupPeerConnectionCallbacks | |
void | beginEndCall | |
void | finishEndCall | |
void | transitionEndedToIdle | |
void | enqueueCallback | |
void | drainCallbacks |
void onSdpReceived(const std::string & peerId, const std::string & type, const std::string & sdp)void onCandidateReceived(const std::string & peerId, const std::string & candidate, const std::string & mid)void onControlReceived(const std::string & peerId, const std::string & type, const std::string & reason)std::shared_ptr< rtc::PeerConnection > createPeerConnection(bool createDataChannel, const MediaBridge::Options * mediaOpts)void setupPeerConnectionCallbacks(const std::shared_ptr< rtc::PeerConnection > & pc)void beginEndCall(const std::string & reason, std::shared_ptr< rtc::PeerConnection > & pc, std::shared_ptr< rtc::DataChannel > & dc)void finishEndCall()void transitionEndedToIdle()void enqueueCallback(std::function< void()> callback)void drainCallbacks()