Android11+无法在webview或chrome中收集icecandidates。
创始人
2024-08-20 09:01:02
0

Android 11+ 限制了 webview 或 chrome 中收集 ice candidates 的能力。为了解决这个问题,可以使用 Google 开发的 WebRTC 应用程序库,在应用程序中手动获取和添加 ice candidates。

下面是一些示例代码,用于手动获取和添加 ice candidates:

// 获取 PeerConnection 对象 PeerConnection peerConnection = ...;

// 创建一个 RTCConfiguration 对象,并设置 STUN/TURN 服务器的地址和凭证 RTCConfiguration rtcConfig = new RTCConfiguration.Builder() .setIceServers(Arrays.asList( new IceServer("stun:stun.l.google.com:19302"), new IceServer("turn:example.com:3478", "username", "password") )) .build();

// 创建 PeerConnectionObserver 对象 PeerConnection.Observer observer = new PeerConnection.Observer() { @Override public void onIceCandidate(IceCandidate iceCandidate) { // 当收到一个新的 ice candidate 时,手动添加到 PeerConnection 中 peerConnection.addIceCandidate(iceCandidate); }

// 其他方法省略...

};

// 创建一个 PeerConnection 实例 peerConnection = factory.createPeerConnection(rtcConfig, observer);

// 获取本地的 SDP 信息 SessionDescription localSdp = peerConnection.getLocalDescription();

// 将本地 SDP 信息设置到远程的 PeerConnection 中 remotePeerConnection.setRemoteDescription(new SimpleSdpObserver(), localSdp);

// 获取远程的 SDP 信息 SessionDescription remoteSdp = remotePeerConnection.getRemoteDescription();

// 将远程的 SDP 信息设置到本地 PeerConnection 中 peerConnection.setRemoteDescription(new SimpleSdpObserver(), remoteSdp);

// 收集 ice candidates peerConnection.createOffer(new SimpleSdpObserver() { @Override public void onCreateSuccess(SessionDescription sdp) { // 将本地的 SDP 信息设置到 PeerConnection 中 peerConnection.setLocalDescription(new SimpleSdpObserver(), sdp);

    // 遍历收集到的 ice candidates
    for (IceCandidate candidate : ice

相关内容

热门资讯

第8分钟了解!闲逸手机麻将有挂... 第8分钟了解!闲逸手机麻将有挂的么(辅助挂)起初是有挂(专业辅助高科技教程)-哔哩哔哩;闲逸手机麻将...
第3分钟了解!大同麻将有挂(辅... 第3分钟了解!大同麻将有挂(辅助挂)总是有挂(专业辅助揭秘教程)-哔哩哔哩;亲,有的,ai轻松简单,...
七分钟了解!大宝苏北麻将挂(辅... 七分钟了解!大宝苏北麻将挂(辅助挂)素来是有挂(专业辅助介绍教程)-哔哩哔哩;大宝苏北麻将挂是一种具...
6分钟了解!财神十三张牌辅助器... 6分钟了解!财神十三张牌辅助器下载(辅助挂)从来真的有挂(专业辅助系统教程)-哔哩哔哩;是一款可以让...
八分钟了解!约战丹东麻将可以赢... 八分钟了解!约战丹东麻将可以赢(辅助挂)竟然有挂(专业辅助插件教程)-哔哩哔哩;1、很好的约战丹东麻...
1分钟了解!开心十三张辅助io... 您好:开心十三张辅助ios版这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
第五分钟了解!指尖辅助软件(辅... 第五分钟了解!指尖辅助软件(辅助挂)固有是有挂(专业辅助2025新版技巧)-哔哩哔哩;1、这是跨平台...
5分钟了解!闲玩暗宝外挂(辅助... 您好:闲玩暗宝外挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
6分钟了解!乐山幺鸡麻将辅牌器... 6分钟了解!乐山幺鸡麻将辅牌器购买(辅助挂)原生存在有挂(专业辅助线上教程)-哔哩哔哩;乐山幺鸡麻将...
十分钟了解!jj斗地主控牌(辅... 十分钟了解!jj斗地主控牌(辅助挂)都是存在有挂(专业辅助详细教程)-哔哩哔哩;小薇(透视辅助)致您...