Delphi RTCPeerConnection

Talk WebRTC from Delphi/C++Builder — ICE for connectivity, DTLS for the keying handshake, SRTP for media, SCTP-over-DTLS for DataChannels. No browser required.

TsgcRTCPeerConnection

Native Delphi WebRTC peer — mirrors the W3C RTCPeerConnection surface (CreateOffer / CreateAnswer / SetRemoteDescription / AddIceCandidate / DataChannel) backed by the bundled ICE, DTLS, SRTP and SCTP stacks.

Component class

TsgcRTCPeerConnection

Protocol

WebRTC (W3C)

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise for the component, plus the sgcWebRTC pack for offer and answer, DataChannels and tracks. Both ship in All-Access.

The Enterprise block of sgcVer.inc defines SGC_ICE, SGC_DTLS, SGC_RTCPEERCONNECTION and SGC_TURN, which is what puts TsgcRTCPeerConnection on the palette and gives it an ICE and TURN transport. The offer and answer methods, the DataChannel API and the media API sit inside SGC_SDP, SGC_DATACHANNEL and SGC_RTP, and only SGC_PACK_WEBRTC defines those. They need the sgcWebRTC pack on top of Enterprise, or All-Access, which enables the pack for you.

Offer / Answer / Connect

Fill RTCOptions.ICEServers, call CreateOffer, send the SDP that OnLocalDescription hands you to the remote peer over your signalling channel, set the answer that comes back, and the data path lights up.

uses
  sgcP2P, sgcP2P_DataChannel;

// TFormPeer holds FPeer, FChannel, FIncoming: TStringList and the handlers

procedure TFormPeer.CreatePeer;
begin
  FPeer := TsgcRTCPeerConnection.Create(nil);
  FPeer.RTCOptions.ICEServers.AddURL('stun:stun.l.google.com:19302');
  FPeer.RTCOptions.ICE.TURN := False;  // no TURN server yet

  FPeer.OnLocalDescription := OnLocalDescription;
  FPeer.OnDataChannel      := OnDataChannel;

  // outbound side. CreateDataChannel turns RTCOptions.DTLS on
  FChannel := FPeer.CreateDataChannel('chat');
  FChannel.OnMessage := OnChannelMessage;
  FPeer.CreateOffer;
end;

procedure TFormPeer.OnLocalDescription(Sender: TObject;
  const aType, aSDP: string);
begin
  // aType is 'offer' or 'answer'
  SignalToPeer(aType, aSDP); // over your WebSocket signalling channel
end;

procedure TFormPeer.OnDataChannel(Sender: TObject;
  aChannel: TsgcRTCDataChannel);
begin
  FChannel := aChannel;
  FChannel.OnMessage := OnChannelMessage;
end;

procedure TFormPeer.OnChannelMessage(Sender: TObject;
  const aText: string);
begin
  // fires on a worker thread, marshal before you touch a control
  FIncoming.Add(aText);
end;
// includes: sgcP2P.hpp, sgcP2P_DataChannel.hpp

TsgcRTCPeerConnection *Peer = new TsgcRTCPeerConnection(this);
Peer->RTCOptions->ICEServers->AddURL("stun:stun.l.google.com:19302");
Peer->RTCOptions->ICE->TURN = false;  // no TURN server yet

Peer->OnLocalDescription = OnLocalDescription;
Peer->OnDataChannel      = OnDataChannel;

TsgcRTCDataChannel *Channel = Peer->CreateDataChannel("chat");
Peer->CreateOffer();

void __fastcall TFormPeer::OnLocalDescription(TObject *Sender,
  const String aType, const String aSDP)
{
  SignalToPeer(aType, aSDP);  // over your WebSocket signalling channel
}

void __fastcall TFormPeer::OnDataChannel(TObject *Sender,
  TsgcRTCDataChannel *aChannel)
{
  aChannel->OnMessage = OnChannelMessage;
}

Worked example: two Delphi applications, end to end

What's inside

A native WebRTC peer that bundles ICE, DTLS, SRTP and SCTP into a single component — mirroring the W3C RTCPeerConnection API.

SDP Offer / Answer

CreateOffer and CreateAnswer generate RFC 8866 SDP with the right ICE-UFRAG / ICE-PWD / FINGERPRINT / SETUP attributes; SetRemoteDescription ingests the peer's SDP.

ICE-driven connectivity

Uses TsgcICEClient internally for candidate gathering and connectivity checks; AddIceCandidate feeds remote candidates as they trickle in from signalling.

DTLS keying

Once the selected ICE pair becomes writable the component runs a DTLS handshake (RFC 6347) and exports the SRTP keying material with the RFC 5764 EXTRACTOR-dtls_srtp label. RTCOptions.DTLS defaults to False, and CreateDataChannel turns it on for you.

DataChannels (SCTP-over-DTLS)

CreateDataChannel opens an SCTP stream multiplexed over DTLS — reliable / partial-reliable, ordered / unordered, with backpressure via BufferedAmount.

Media tracks

AddTrack publishes an audio or video track and OnTrack receives the remote one, both over SRTP. The companion TsgcWSPServer_RTCPeerConnection is the WebSocket signalling broker: it pairs a caller with a callee and relays their SDP and their candidates.

Browser-compatible

Interops with browser RTCPeerConnection — tested against Chromium / Firefox / Safari. Same SDP semantics, same ICE candidates, same DataChannel wire format.

Specifications & references

Authoritative sources for the protocol this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — TsgcRTCPeerConnection Full property, method and event reference for this component.
Demo Project — Demos\35.P2P\05.RTCPeerConnection Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Run WebRTC in Delphi?

Download the free trial and add native RTCPeerConnection to your Delphi applications.