RTC Peer Connection
TsgcRTCPeerConnection — sgcWebRTC 背后的唯一组件:ICE/TURN 连接、手动 SDP offer/answer 信令(RFC 8829 JSEP)、DTLS-SRTP 加密传输、SCTP 数据通道(RFC 8831/8832)和 RTP 音视频轨道,适用于 Delphi 和 C++ Builder。
TsgcRTCPeerConnection — sgcWebRTC 背后的唯一组件:ICE/TURN 连接、手动 SDP offer/answer 信令(RFC 8829 JSEP)、DTLS-SRTP 加密传输、SCTP 数据通道(RFC 8831/8832)和 RTP 音视频轨道,适用于 Delphi 和 C++ Builder。
设置 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
用 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 包含 ICE、ICEServers、DTLS / DTLSOptions、Media(拥塞控制、FEC、发送节奏控制、RTX)以及传统的 WebSocket 信令设置。
CreateOffer、CreateAnswer、SetLocalDescription、SetRemoteDescription、AddIceCandidate、RestartIce、Close。
ConnectionState、SignalingState、LocalDescription、RemoteDescription、Renegotiating、NegotiationNeeded、Polite、TrickleICE。
CreateDataChannel、DataChannelCount、DataChannels[i]、OnDataChannel。
AddTrack、RemoveTrack、TrackCount、Tracks[i]、OnTrack。
OnLocalDescription、OnICECandidate、OnConnectionStateChange、OnNegotiationNeeded、OnError,以及传统的 OnRTCConnect / OnRTCCandidatePairNominated / OnRTCException 系列事件。