RTC Peer Connection Component — sgcWebRTC | eSeGeCe

RTC Peer Connection

TsgcRTCPeerConnection — the one component behind sgcWebRTC: ICE/TURN connectivity, manual SDP offer/answer signaling (RFC 8829 JSEP), DTLS-SRTP encrypted transport, SCTP data channels (RFC 8831/8832) and RTP audio/video tracks, in Delphi and C++ Builder.

TsgcRTCPeerConnection

Set RTCOptions, hook the SDP and ICE events, then either drive the offer/answer exchange yourself or open a data channel and let CreateOffer do it. Built on the same ICE/DTLS transport as the base component in sgcWebSockets Enterprise.

Component class

TsgcRTCPeerConnection

Unit

sgcP2P (re-exports sgcP2P_RTCPeerConnection)

Standards

RFC 8445, 8489, 8656, 8827, 5764, 8831, 8832, 3550, 3711, 8829

Languages

Delphi, C++ Builder

Add a Video Track and Offer It

Attach a track with AddTrack, hook the SDP events, then call CreateOffer. Send aSDP to the remote peer over your own signaling channel and feed its answer back through SetRemoteDescription.

uses
  sgcP2P;

var
  oRTC: TsgcRTCPeerConnection;
  oTrack: TsgcRTCTrack;
begin
  oRTC := TsgcRTCPeerConnection.Create(nil);
  oRTC.RTCOptions.ICEServers.AddURL('stun:stun.l.google.com:19302');
  oRTC.OnLocalDescription      := OnLocalDescriptionHandler;
  oRTC.OnICECandidate          := OnICECandidateHandler;
  oRTC.OnConnectionStateChange := OnConnectionStateChangeHandler;
  oRTC.OnTrack                 := OnTrackHandler;

  oTrack := oRTC.AddTrack(rtctkVideo, cctVideoH264);
  oTrack.OnEncodedFrame := OnEncodedFrameHandler;   // remote frames, once negotiated

  oRTC.CreateOffer;   // gathers ICE candidates, builds the SDP offer, fires OnLocalDescription
end;

procedure TForm1.OnLocalDescriptionHandler(Sender: TObject;
  const aType, aSDP: string);
begin
  // send { type: aType, sdp: aSDP } to the remote peer
end;

// once the remote answer arrives over your signaling channel:
oRTC.SetRemoteDescription('answer', vRemoteSDP);

// and for every remote ICE candidate it sends:
oRTC.AddIceCandidate(vCandidate, vSdpMid, vSdpMLineIndex);
// includes: sgcP2P.hpp

TsgcRTCPeerConnection *oRTC = new TsgcRTCPeerConnection(NULL);
oRTC->RTCOptions->ICEServers->AddURL("stun:stun.l.google.com:19302");
oRTC->OnLocalDescription      = OnLocalDescriptionHandler;
oRTC->OnICECandidate          = OnICECandidateHandler;
oRTC->OnConnectionStateChange = OnConnectionStateChangeHandler;
oRTC->OnTrack                 = OnTrackHandler;

TsgcRTCTrack *oTrack = oRTC->AddTrack(rtctkVideo, cctVideoH264);
oTrack->OnEncodedFrame = OnEncodedFrameHandler;    // remote frames, once negotiated

oRTC->CreateOffer();   // gathers ICE candidates, builds the SDP offer, fires OnLocalDescription

void __fastcall TForm1::OnLocalDescriptionHandler(TObject *Sender,
  const String aType, const String aSDP)
{
  // send { type: aType, sdp: aSDP } to the remote peer
}

// once the remote answer arrives over your signaling channel:
oRTC->SetRemoteDescription("answer", vRemoteSDP);

// and for every remote ICE candidate it sends:
oRTC->AddIceCandidate(vCandidate, vSdpMid, vSdpMLineIndex);

Key properties, methods & events

The members you reach for most often. See the feature matrix for the full breakdown by capability.

Configuration

RTCOptions holds ICE, ICEServers, DTLS / DTLSOptions, Media (congestion control, FEC, pacing, RTX) and the legacy WebSocket signaling settings.

Signaling

CreateOffer, CreateAnswer, SetLocalDescription, SetRemoteDescription, AddIceCandidate, RestartIce, Close.

State

ConnectionState, SignalingState, LocalDescription, RemoteDescription, Renegotiating, NegotiationNeeded, Polite, TrickleICE.

Data channels

CreateDataChannel, DataChannelCount, DataChannels[i], OnDataChannel.

Media tracks

AddTrack, RemoveTrack, TrackCount, Tracks[i], OnTrack.

Events

OnLocalDescription, OnICECandidate, OnConnectionStateChange, OnNegotiationNeeded, OnError, plus the legacy OnRTCConnect / OnRTCCandidatePairNominated / OnRTCException family.

Keep exploring

Online HelpFull API reference and usage guide for TsgcRTCPeerConnection.
Full Feature MatrixAudio, video, data channels, screen share, SRTP and bandwidth estimation.
Download Free TrialRun the peer connection against a browser or another native peer.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and open a peer connection from Delphi or C++ Builder.