RTCPeerConnection
TsgcRTCPeerConnection — Delphi-side RTCPeerConnection implementation paired with the W3C WebRTC API for browser interop.
TsgcRTCPeerConnection — Delphi-side RTCPeerConnection implementation paired with the W3C WebRTC API for browser interop.
The TsgcRTCPeerConnection is a client component that allows you to connect peers using P2P through UDP.
TsgcRTCPeerConnection| Standards & specs | WebRTC 1.0 — W3C · SDP — RFC 8866 |
| Component class | TsgcRTCPeerConnection (unit sgcRTCPeerConnection) |
| Frameworks | VCL, FireMonkey, Lazarus / FPC |
| Platforms | Windows, macOS, Linux, iOS, Android |
The principal published / public properties used to configure and drive the component. Consult the online help for the full list.
RTCOptions | Connection options: STUN/TURN server, signalling WebSocket endpoint and DTLS encryption settings. |
Version | Read-only component version string. |
The principal public methods exposed by the component.
WriteData() | Sends data to the remote peer through the negotiated candidate pair. |
GatherCandidates() | Starts the ICE candidate gathering process. |
Clear() | Resets the peer-connection state and releases the active channel binding. |
The component exposes the following published events; consult the online help for full event-handler signatures.
OnRTCCandidatePairFailed | TsgcRTCPeerConnection › Events › OnRTCCandidatePairFailed |
OnRTCCandidatePairNominated | TsgcRTCPeerConnection › Events › OnRTCCandidatePairNominated |
OnRTCConnect | Fired when the data channel is open and ready to send and receive data. |
OnRTCException | Fired when an exception is raised inside the peer-connection pipeline. |
OnRTCLocalCandidate | Fired when a local ICE candidate has been gathered; set Accept to False to drop it. |
OnRTCLocalDescription | Fired when the local SDP offer/answer has been generated and can be edited. |
OnRTCMessage | Fired when data is received from the remote peer through the data channel. |
OnRTCRemoteCandidate | Fired when a remote ICE candidate is received; set Accept to False to drop it. |
OnRTCRemoteDescription | Fired when the remote SDP offer/answer is received through signalling. |
OnRTCWebSocketBeforeConnect | TsgcRTCPeerConnection › Events › OnRTCWebSocketBeforeConnect |
OnRTCWebSocketConnect | Fired when the signalling WebSocket has connected to the server. |
OnRTCWebSocketDisconnect | TsgcRTCPeerConnection › Events › OnRTCWebSocketDisconnect |
OnRTCWebSocketMessage | Fired when a raw signalling text message is received on the WebSocket. |
OnRTCWebSocketRemoteDisconnect | TsgcRTCPeerConnection › Events › OnRTCWebSocketRemoteDisconnect |
Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Send Data configuration sourced from the online help.
oRTCPeerConnection := TsgcRTCPeerConnection.Create(nil); ... oRTCPeerConnection.WriteData('Hello from sgcWebSockets!!!');
TsgcRTCPeerConnection *oRTCPeerConnection = new TsgcRTCPeerConnection(); ... oRTCPeerConnection->WriteData("Hello from sgcWebSockets!!!");
TsgcRTCPeerConnection oRTCPeerConnection = new TsgcRTCPeerConnection(); ... oRTCPeerConnection.WriteData("Hello from sgcWebSockets!!!");
The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.
The TsgcRTCPeerConnection client requires a WebSocket Server for signaling. The client makes use of the WebSocket protocol to exchange the SDP of the peers and the candidates (IPs and ports), which will allow peers to communicate.
oServer := TsgcWebSocketServer.Create(nil); oProtocol := TsgcWSPServer_RTCPeerConnection.Create(nil); oProtocol.Server := oServer; oServer.Port := 8080; oServer.Active := True;
TsgcWebSocketServer *oServer = new TsgcWebSocketServer(); TsgcWSPServer_RTCPeerConnection *oProtocol = new TsgcWSPServer_RTCPeerConnection(); oProtocol->Server = oServer; oServer->Port = 8080; oServer->Active = true;
TsgcWebSocketServer oServer = new TsgcWebSocketServer(); TsgcWSPServer_RTCPeerConnection oProtocol = new TsgcWSPServer_RTCPeerConnection(); oProtocol.Server = oServer; oServer.Port = 8080; oServer.Active = true;
Every time the TsgcRTCPeerConnection receives any data from the other peer, the event OnRTCMessage will be called.
procedure OnRTCMessage(Sender: TObject; const aBytes: TBytes); begin ShowMessage(TEncoding.UTF8.GetString(aBytes)); end;
void OnRTCMessage(TObject *Sender, const TBytes aBytes) { ShowMessage(TEncoding->UTF8->GetString(aBytes)); }
void OnRTCMessage(TObject Sender, byte[] aBytes)
{
MessageBox.Show(System.Text.Encoding.Default.GetString(aBytes));
}
Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.
Demos\35.P2P\05.RTCPeerConnection