WebRTC module

PeerSession

Manages a WebRTC peer connection lifecycle over any signalling transport that implements SignallingInterface.

#include <icy/webrtc/peersession.h>

class PeerSession

Defined in src/webrtc/include/icy/webrtc/peersession.h:45

Works with SympleSignaller (Symple call protocol), WebSocketSignaller (plain JSON over WSS), or any custom implementation.

Media is optional. Set Config::media codecs to enable tracks. Leave codec encoders empty for data-channel-only sessions.

Public Attributes

ReturnNameDescription
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).

StateChanged

ThreadSignal< void(State)> StateChanged

Type: ThreadSignal< void(State)>

Defined in src/webrtc/include/icy/webrtc/peersession.h:125

Emitted whenever the session state changes. Parameter: new State value.


IncomingCall

ThreadSignal< void(const std::string &)> IncomingCall

Type: ThreadSignal< void(const std::string &)>

Defined in src/webrtc/include/icy/webrtc/peersession.h:129

Emitted when a remote peer initiates a call (state transitions to IncomingInit). Parameter: remote peer identifier.


DataReceived

ThreadSignal< void(rtc::message_variant)> DataReceived

Type: ThreadSignal< void(rtc::message_variant)>

Defined in src/webrtc/include/icy/webrtc/peersession.h:133

Emitted when a message arrives on the data channel. Parameter: rtc::message_variant (string or binary).

Public Methods

ReturnNameDescription
PeerSessionConstruct with any signalling implementation. The signaller must outlive this PeerSession.
~PeerSession
PeerSessionDeleted copy constructor; PeerSession owns live signalling and RTC callbacks.
PeerSession &operator=Deleted assignment operator.
voidcallInitiate an outgoing call to a remote peer. Sends a "init" control message and transitions to OutgoingInit.
voidacceptAccept an incoming call. Creates the PeerConnection, sends "accept", and transitions to Negotiating.
voidrejectReject an incoming call. Sends a "reject" control message and transitions to Ended.
voidhangupTerminate 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.
voidsendDataSend a UTF-8 string message over the data channel. Silently dropped if the data channel is not open.
voidsendDataSend raw binary data over the data channel. Silently dropped if the data channel is not open.
Statestate constCurrent session state. Thread-safe.
std::stringremotePeerId constIdentifier of the remote peer for the current or most recent call. Empty when Idle.
MediaBridge &mediaMedia bridge for this session. Valid for the lifetime of the PeerSession.
const MediaBridge &media constMedia bridge for this session. Valid for the lifetime of the PeerSession.
std::shared_ptr< rtc::PeerConnection >peerConnectionThe underlying PeerConnection, or nullptr when Idle/Ended.
std::shared_ptr< rtc::DataChannel >dataChannelThe data channel, or nullptr if none is open.

PeerSession

PeerSession(SignallingInterface & signaller, const Config & config)

Defined in src/webrtc/include/icy/webrtc/peersession.h:82

Construct with any signalling implementation. The signaller must outlive this PeerSession.


~PeerSession

~PeerSession()

Defined in src/webrtc/include/icy/webrtc/peersession.h:83


PeerSession

PeerSession(const PeerSession &) = delete

Defined in src/webrtc/include/icy/webrtc/peersession.h:86

Deleted copy constructor; PeerSession owns live signalling and RTC callbacks.


operator=

PeerSession & operator=(const PeerSession &) = delete

Defined in src/webrtc/include/icy/webrtc/peersession.h:87

Deleted assignment operator.


call

void call(const std::string & peerId)

Defined in src/webrtc/include/icy/webrtc/peersession.h:93

Initiate an outgoing call to a remote peer. Sends a "init" control message and transitions to OutgoingInit.

Parameters

ParameterTypeDescription
peerIdconst std::string &Remote peer identifier passed to the signaller.

Exceptions

ExceptionDescription
std::logic_errorif not currently in the Idle state.

accept

void accept()

Defined in src/webrtc/include/icy/webrtc/peersession.h:98

Accept an incoming call. Creates the PeerConnection, sends "accept", and transitions to Negotiating.

Exceptions

ExceptionDescription
std::logic_errorif not currently in the IncomingInit state.

reject

void reject(const std::string & reason = "declined")

Defined in src/webrtc/include/icy/webrtc/peersession.h:104

Reject an incoming call. Sends a "reject" control message and transitions to Ended.

Parameters

ParameterTypeDescription
reasonconst std::string &Human-readable reason string forwarded to the remote peer.

Exceptions

ExceptionDescription
std::logic_errorif not currently in the IncomingInit state.

hangup

void hangup(const std::string & reason = "hangup")

Defined in src/webrtc/include/icy/webrtc/peersession.h:110

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.

Parameters

ParameterTypeDescription
reasonconst std::string &Human-readable reason string forwarded to the remote peer.

sendData

void sendData(const std::string & message)

Defined in src/webrtc/include/icy/webrtc/peersession.h:115

Send a UTF-8 string message over the data channel. Silently dropped if the data channel is not open.

Parameters

ParameterTypeDescription
messageconst std::string &String to send.

sendData

void sendData(const std::byte * data, size_t size)

Defined in src/webrtc/include/icy/webrtc/peersession.h:121

Send raw binary data over the data channel. Silently dropped if the data channel is not open.

Parameters

ParameterTypeDescription
dataconst std::byte *Pointer to the byte buffer.
sizesize_tNumber of bytes to send.

state

const

State state() const

Defined in src/webrtc/include/icy/webrtc/peersession.h:136

Current session state. Thread-safe.


remotePeerId

const

std::string remotePeerId() const

Defined in src/webrtc/include/icy/webrtc/peersession.h:140

Identifier of the remote peer for the current or most recent call. Empty when Idle.


media

MediaBridge & media()

Defined in src/webrtc/include/icy/webrtc/peersession.h:143

Media bridge for this session. Valid for the lifetime of the PeerSession.


media

const

const MediaBridge & media() const

Defined in src/webrtc/include/icy/webrtc/peersession.h:145

Media bridge for this session. Valid for the lifetime of the PeerSession.


peerConnection

std::shared_ptr< rtc::PeerConnection > peerConnection()

Defined in src/webrtc/include/icy/webrtc/peersession.h:148

The underlying PeerConnection, or nullptr when Idle/Ended.


dataChannel

std::shared_ptr< rtc::DataChannel > dataChannel()

Defined in src/webrtc/include/icy/webrtc/peersession.h:151

The data channel, or nullptr if none is open.

Public Types

NameDescription
StateHigh-level lifecycle phases for a single peer-to-peer call session.

State

enum State

Defined in src/webrtc/include/icy/webrtc/peersession.h:49

High-level lifecycle phases for a single peer-to-peer call session.

ValueDescription
IdleNo active call.
OutgoingInitOutgoing call announced, waiting for accept/reject.
IncomingInitIncoming call announced, waiting for accept/reject.
NegotiatingPeerConnection exists and SDP/ICE negotiation is in progress.
ActiveMedia or data is flowing.
EndingLocal teardown is in progress.
EndedCall ended (transient; auto-resets to Idle)

Private Attributes

ReturnNameDescription
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

_signaller

SignallingInterface & _signaller

Type: SignallingInterface &

Defined in src/webrtc/include/icy/webrtc/peersession.h:185


_config

Config _config

Type: Config

Defined in src/webrtc/include/icy/webrtc/peersession.h:186


_media

MediaBridge _media

Type: MediaBridge

Defined in src/webrtc/include/icy/webrtc/peersession.h:187


_state

State _state = State::Idle

Type: State

Defined in src/webrtc/include/icy/webrtc/peersession.h:188


_remotePeerId

std::string _remotePeerId

Defined in src/webrtc/include/icy/webrtc/peersession.h:189


_pc

std::shared_ptr< rtc::PeerConnection > _pc

Defined in src/webrtc/include/icy/webrtc/peersession.h:190


_dc

std::shared_ptr< rtc::DataChannel > _dc

Defined in src/webrtc/include/icy/webrtc/peersession.h:191


_callbackGuard

std::shared_ptr< CallbackGuard > _callbackGuard = std::make_shared<CallbackGuard>()

Defined in src/webrtc/include/icy/webrtc/peersession.h:192


_remoteDescriptionSet

bool _remoteDescriptionSet = false

Defined in src/webrtc/include/icy/webrtc/peersession.h:193


_pendingRemoteCandidates

std::vector< PendingCandidate > _pendingRemoteCandidates

Defined in src/webrtc/include/icy/webrtc/peersession.h:194


_callbackSync

Synchronizer _callbackSync

Type: Synchronizer

Defined in src/webrtc/include/icy/webrtc/peersession.h:195


_pendingCallbacks

std::deque< std::function< void()> > _pendingCallbacks

Defined in src/webrtc/include/icy/webrtc/peersession.h:196


_callbackMutex

std::mutex _callbackMutex

Defined in src/webrtc/include/icy/webrtc/peersession.h:197


_mutex

std::mutex _mutex

Defined in src/webrtc/include/icy/webrtc/peersession.h:198

Private Methods


onSdpReceived

void onSdpReceived(const std::string & peerId, const std::string & type, const std::string & sdp)

Defined in src/webrtc/include/icy/webrtc/peersession.h:169


onCandidateReceived

void onCandidateReceived(const std::string & peerId, const std::string & candidate, const std::string & mid)

Defined in src/webrtc/include/icy/webrtc/peersession.h:170


onControlReceived

void onControlReceived(const std::string & peerId, const std::string & type, const std::string & reason)

Defined in src/webrtc/include/icy/webrtc/peersession.h:171


createPeerConnection

std::shared_ptr< rtc::PeerConnection > createPeerConnection(bool createDataChannel, const MediaBridge::Options * mediaOpts = nullptr)

Defined in src/webrtc/include/icy/webrtc/peersession.h:173


setupPeerConnectionCallbacks

void setupPeerConnectionCallbacks(const std::shared_ptr< rtc::PeerConnection > & pc)

Defined in src/webrtc/include/icy/webrtc/peersession.h:176


beginEndCall

void beginEndCall(const std::string & reason, std::shared_ptr< rtc::PeerConnection > & pc, std::shared_ptr< rtc::DataChannel > & dc)

Defined in src/webrtc/include/icy/webrtc/peersession.h:177


finishEndCall

void finishEndCall()

Defined in src/webrtc/include/icy/webrtc/peersession.h:180


transitionEndedToIdle

void transitionEndedToIdle()

Defined in src/webrtc/include/icy/webrtc/peersession.h:181


enqueueCallback

void enqueueCallback(std::function< void()> callback)

Defined in src/webrtc/include/icy/webrtc/peersession.h:182


drainCallbacks

void drainCallbacks()

Defined in src/webrtc/include/icy/webrtc/peersession.h:183