WebRTC从PeerConnection创建数据通道始终为空

时间:2019-01-14 08:11:21

标签: android webrtc rtcdatachannel

我正在开发一个Android WebRTC应用程序,在建立连接时,我需要数据通道来发送一些附加信息。我正在这样创建数据通道:

DataChannel.Init init = new DataChannel.Init();
dataChannel = peerConnection.createDataChannel("knock_data_chanel", init);

但这不会在我的应用程序中创建任何DataChannel,并且当我在上面的代码后立即检查时,dataChannel始终为空。

有人知道如何解决吗?可以是我的PeerConnection吗?还是MediaConstraints之类的东西?

我的PeerConnection创建过程:

PeerConnection.RTCConfiguration rtcConfig =
    new PeerConnection.RTCConfiguration(signalingParameters.iceServers);
// TCP candidates are only useful when connecting to a server that supports
// ICE-TCP.
rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;//todo change to GATHER_CONTINUALLY later if that's possible on server end.
// Use ECDSA encryption.
rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
// Enable DTLS for normal calls and disable for loopback calls.
rtcConfig.enableDtlsSrtp = !peerConnectionParameters.loopback;
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
peerConnection = peerConnectionFactory.createPeerConnection(rtcConfig, pcObserver);

我的SDP MediaConstraint

sdpMediaConstraints = new MediaConstraints();
sdpMediaConstraints.mandatory.add(
    new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair(
    "OfferToReceiveVideo", "true"));
sdpMediaConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));

然后我以此创建报价:

peerConnection.createOffer(sdpObserver, sdpMediaConstraints);

任何帮助将不胜感激,谢谢!

0 个答案:

没有答案