RTC Peer Connection 组件 — sgcWebRTC | eSeGeCe

RTC Peer Connection

TsgcRTCPeerConnection — sgcWebRTC 背后的唯一组件:ICE/TURN 连接、手动 SDP offer/answer 信令(RFC 8829 JSEP)、DTLS-SRTP 加密传输、SCTP 数据通道(RFC 8831/8832)和 RTP 音视频轨道,适用于 Delphi 和 C++ Builder。

TsgcRTCPeerConnection

设置 RTCOptions,挂接 SDP 和 ICE 事件,然后既可以自行驱动 offer/answer 交换,也可以打开一个数据通道并让 CreateOffer 代劳。构建于 sgcWebSockets Enterprise 中基础组件所使用的同一套 ICE/DTLS 传输之上。

组件类

TsgcRTCPeerConnection

单元

sgcP2P(重新导出自 sgcP2P_RTCPeerConnection

标准

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

语言

Delphi, C++ Builder

添加一个视频轨道并发出 Offer

AddTrack 附加一个轨道,挂接 SDP 事件,然后调用 CreateOffer。通过您自己的信令通道将 aSDP 发送给远端对等方,并通过 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);

关键属性、方法与事件

您最常使用的成员。完整的分类明细请参见功能矩阵

配置

RTCOptions 包含 ICEICEServersDTLS / DTLSOptionsMedia(拥塞控制、FEC、发送节奏控制、RTX)以及传统的 WebSocket 信令设置。

信令

CreateOfferCreateAnswerSetLocalDescriptionSetRemoteDescriptionAddIceCandidateRestartIceClose

状态

ConnectionStateSignalingStateLocalDescriptionRemoteDescriptionRenegotiatingNegotiationNeededPoliteTrickleICE

数据通道

CreateDataChannelDataChannelCountDataChannels[i]OnDataChannel

媒体轨道

AddTrackRemoveTrackTrackCountTracks[i]OnTrack

事件

OnLocalDescriptionOnICECandidateOnConnectionStateChangeOnNegotiationNeededOnError,以及传统的 OnRTCConnect / OnRTCCandidatePairNominated / OnRTCException 系列事件。

继续探索

在线帮助TsgcRTCPeerConnection 的完整 API 参考和使用指南。
完整功能矩阵音频、视频、数据通道、屏幕共享、SRTP 和带宽评估。
下载免费试用版针对浏览器或另一个原生对等方运行该对等连接。
价格Single、Team 和 Site 授权,均含完整源代码。
超值之选:All-AccesseSeGeCe 全部产品,含高级支持,每年 €1,059 起。
查看 All-Access 价格

准备好开始了吗?

下载免费试用版,开始在 Delphi 或 C++ Builder 中打开一个对等连接。