gpt4 book ai didi

android - android 中的 PeerConnection 实例始终为空?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:49 25 4
gpt4 key购买 nike

我必须在 android 应用程序中实现 WebRTC,因为我正在使用 libjingle 库,ver-11139。在这里我总是得到 pc(PeerConnection class instance) 总是空的。我检查了值

factory(PeerConnectionFactory)
iceServers(LinkedList<IceServers>
mediaConstraints
Peer.this(PCObserver interface))

但它们都不为空。那为什么我总是得到空的结果。我在这里做错了吗???

pc = factory.createPeerConnection(iceServers, mediaConstraints, Peer.this);

编辑:

 public CallManager(TagoveApplication context, CustomSocket server, CallType callType) {
this.server = server;
this.context = context;
initializeFactoryFieldTrials(); //initialize peer conn factory field trials
PeerConnectionFactory.initializeAndroidGlobals(context, true, true, true);

//PeerConnectionFactory.initializeAndroidGlobals(context, true, true, true, VideoRendererGui.getEGLContext());
factory = new PeerConnectionFactory();

iceServers.add(new PeerConnection.IceServer("turn:xxx.xxx.xxx.xxx:xxxx?transport=udp", "xxxxxxxx", "xxxxxxxxx"));

iceServers.add(new PeerConnection.IceServer("stun:stunserver.org"));
iceServers.add(new PeerConnection.IceServer("stun:stun.ekiga.net"));
iceServers.add(new PeerConnection.IceServer("stun:stun.fwdnet.net"));
iceServers.add(new PeerConnection.IceServer("stun:stun.ideasip.com"));
iceServers.add(new PeerConnection.IceServer("stun:stun.iptel.org"));
iceServers.add(new PeerConnection.IceServer("stun:stun.rixtelecom.se"));
iceServers.add(new PeerConnection.IceServer("stun:stun.schlund.de"));

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

this.callType = callType;
}

创建 Peer 构造函数:

    public Peer(
String label,
PeerConnectionFactory factory,
LinkedList<PeerConnection.IceServer> iceServers,
MediaConstraints mediaConstraints,
PeerCallbacks peerCallbacks,
StreamChangeListener listener,
boolean incoming){

this.label=label;
this.peerCBacks=peerCallbacks;

//Create Peer connection using RTCConfiguration
Log.d("PCTest","Peer factory value - "+String.valueOf(factory));
Log.d("PCTest","ice servers size - "+iceServers.size());
Log.d("PCTest","media constraints - "+String.valueOf(mediaConstraints));

PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
Log.d("","");
this.pc = factory.createPeerConnection(rtcConfig, mediaConstraints, this);
Log.d("PCTest","Peer constructor called pc value - "+String.valueOf(this.pc));

this.streamListener=listener;
log("new +"+" "+label+ " "+(peerCallbacks!=null? "notNull":"issNull")+" ++ "+incoming);
}

最佳答案

答案是针对官方 webRTC android API compile 'org.webrtc:google-webrtc:1.0.+'

在创建 IceServers 时,你应该使用正确的 TlsCertPolicy。如果您的 stun/turn 服务器不安全,例如:stun:stun1.l.google.com:19302 而不是 stuns:stun1.l.google.com:19302 那么您应该将 TLS 证书策略设置为 TLS_CERT_POLICY_INSECURE_NO_CHECK。可以使用 IceServerBuilder 以这种方式完成:

List<PeerConnection.IceServer> iceServers = new ArrayList<>();
PeerConnection.IceServer.Builder iceServerBuilder = PeerConnection.IceServer.builder("stun:stun1.l.google.com:19302");
iceServerBuilder.setTlsCertPolicy(PeerConnection.TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK); //this does the magic.
PeerConnection.IceServer iceServer = iceServerBuilder.createIceServer();
iceServers.add(iceServer);
localPeer = peerConnectionFactory.createPeerConnection(iceServers, sdpConstraints,sdpObserver);

关于android - android 中的 PeerConnection 实例始终为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38762061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com