PeerSession
PeerSession
#include <icy/webrtc/peersession.h>class PeerSessionDefined in src/webrtc/include/icy/webrtc/peersession.h:45
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.
List of all members
| Name | Kind | Owner |
|---|---|---|
StateChanged | variable | Declared here |
IncomingCall | variable | Declared here |
DataReceived | variable | Declared here |
PeerSession | function | Declared here |
~PeerSession | function | Declared here |
PeerSession | function | Declared here |
operator= | function | Declared here |
call | function | Declared here |
accept | function | Declared here |
reject | function | Declared here |
hangup | function | Declared here |
sendData | function | Declared here |
sendData | function | Declared here |
state | function | Declared here |
remotePeerId | function | Declared here |
media | function | Declared here |
media | function | Declared here |
peerConnection | function | Declared here |
dataChannel | function | Declared here |
State | enum | Declared here |
_signaller | variable | Declared here |
_config | variable | Declared here |
_media | variable | Declared here |
_state | variable | Declared here |
_remotePeerId | variable | Declared here |
_pc | variable | Declared here |
_dc | variable | Declared here |
_callbackGuard | variable | Declared here |
_remoteDescriptionSet | variable | Declared here |
_pendingRemoteCandidates | variable | Declared here |
_callbackSync | variable | Declared here |
_pendingCallbacks | variable | Declared here |
_callbackMutex | variable | Declared here |
_mutex | variable | Declared here |
onSdpReceived | function | Declared here |
onCandidateReceived | function | Declared here |
onControlReceived | function | Declared here |
createPeerConnection | function | Declared here |
setupPeerConnectionCallbacks | function | Declared here |
beginEndCall | function | Declared here |
finishEndCall | function | Declared here |
transitionEndedToIdle | function | Declared here |
enqueueCallback | function | Declared here |
drainCallbacks | function | Declared here |
Public Attributes
| 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). |
StateChanged
ThreadSignal< void(State)> StateChangedDefined 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 &)> IncomingCallDefined 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)> DataReceivedDefined 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
| 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
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(const PeerSession &) = deleteDefined in src/webrtc/include/icy/webrtc/peersession.h:86
Deleted copy constructor; PeerSession owns live signalling and RTC callbacks.
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
peerIdRemote peer identifier passed to the signaller.
Exceptions
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
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
reasonHuman-readable reason string forwarded to the remote peer.
Exceptions
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
reasonHuman-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
messageString 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
dataPointer to the byte buffer.sizeNumber of bytes to send.
state
const
State state() constDefined in src/webrtc/include/icy/webrtc/peersession.h:136
Current session state. Thread-safe.
remotePeerId
const
std::string remotePeerId() constDefined 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() constDefined 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
| Name | Description |
|---|---|
State | High-level lifecycle phases for a single peer-to-peer call session. |
State
enum StateDefined in src/webrtc/include/icy/webrtc/peersession.h:49
High-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) |
Private Attributes
| 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 |
_signaller
SignallingInterface & _signallerDefined in src/webrtc/include/icy/webrtc/peersession.h:181
_config
Config _configDefined in src/webrtc/include/icy/webrtc/peersession.h:182
_media
MediaBridge _mediaDefined in src/webrtc/include/icy/webrtc/peersession.h:183
_state
State _state = Defined in src/webrtc/include/icy/webrtc/peersession.h:184
_remotePeerId
std::string _remotePeerIdDefined in src/webrtc/include/icy/webrtc/peersession.h:185
_pc
std::shared_ptr< rtc::PeerConnection > _pcDefined in src/webrtc/include/icy/webrtc/peersession.h:186
_dc
std::shared_ptr< rtc::DataChannel > _dcDefined in src/webrtc/include/icy/webrtc/peersession.h:187
_callbackGuard
std::shared_ptr< CallbackGuard > _callbackGuard = std::make_shared<CallbackGuard>()Defined in src/webrtc/include/icy/webrtc/peersession.h:188
_remoteDescriptionSet
bool _remoteDescriptionSet = falseDefined in src/webrtc/include/icy/webrtc/peersession.h:189
_pendingRemoteCandidates
std::vector< PendingCandidate > _pendingRemoteCandidatesDefined in src/webrtc/include/icy/webrtc/peersession.h:190
_callbackSync
Synchronizer _callbackSyncDefined in src/webrtc/include/icy/webrtc/peersession.h:191
_pendingCallbacks
std::deque< std::function< void()> > _pendingCallbacksDefined in src/webrtc/include/icy/webrtc/peersession.h:192
_callbackMutex
std::mutex _callbackMutexDefined in src/webrtc/include/icy/webrtc/peersession.h:193
_mutex
std::mutex _mutexDefined in src/webrtc/include/icy/webrtc/peersession.h:194
Private Methods
| 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 |
onSdpReceived
void onSdpReceived(const std::string & peerId, const std::string & type, const std::string & sdp)Defined in src/webrtc/include/icy/webrtc/peersession.h:165
onCandidateReceived
void onCandidateReceived(const std::string & peerId, const std::string & candidate, const std::string & mid)Defined in src/webrtc/include/icy/webrtc/peersession.h:166
onControlReceived
void onControlReceived(const std::string & peerId, const std::string & type, const std::string & reason)Defined in src/webrtc/include/icy/webrtc/peersession.h:167
createPeerConnection
std::shared_ptr< rtc::PeerConnection > createPeerConnection(bool createDataChannel, const MediaBridge::Options * mediaOpts = nullptr)Defined in src/webrtc/include/icy/webrtc/peersession.h:169
setupPeerConnectionCallbacks
void setupPeerConnectionCallbacks(const std::shared_ptr< rtc::PeerConnection > & pc)Defined in src/webrtc/include/icy/webrtc/peersession.h:172
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:173
finishEndCall
void finishEndCall()Defined in src/webrtc/include/icy/webrtc/peersession.h:176
transitionEndedToIdle
void transitionEndedToIdle()Defined in src/webrtc/include/icy/webrtc/peersession.h:177
enqueueCallback
void enqueueCallback(std::function< void()> callback)Defined in src/webrtc/include/icy/webrtc/peersession.h:178
drainCallbacks
void drainCallbacks()