0
Follow
2
View

Android webrtc - Invalid transport parameter in ICE URI

dillboy 注册会员
2023-01-24 23:58

in apprtc src/app_engine/constants.py, urls is a json array

# ICE_SERVER_OVERRIDE  = [
#   {
#     "urls": [
#       "turn:hostname/IpToTurnServer:19305?transport=udp",
#       "turn:hostname/IpToTurnServer:19305?transport=tcp"
#     ],
#     "username": "TurnServerUsername",
#     "credential": "TurnServerCredentials"
#   },
#   {
#     "urls": [
#       "stun:hostname/IpToStunServer:19302"
#     ]
#   }
# ]

but the android app treat it as a json string here

String url = server.getString("urls");

so you should change android code to

private List iceServersFromPCConfigJSON(String pcConfig)
      throws JSONException {
    JSONObject json = new JSONObject(pcConfig);
    JSONArray servers = json.getJSONArray("iceServers");
    List ret = new ArrayList<>();
    for (int i = 0; i < servers.length(); ++i) {
      JSONObject server = servers.getJSONObject(i);
      JSONArray urls = server.getJSONArray("urls");
      String username = server.has("username") ? server.getString("username") : "";
      String credential = server.has("credential") ? server.getString("credential") : "";
      for (int j = 0; j < urls.length(); ++j) {
        String url = urls.getString(j);
        PeerConnection.IceServer turnServer =
                PeerConnection.IceServer.builder(url)
                        .setUsername(username)
                        .setPassword(credential)
                        .createIceServer();
        ret.add(turnServer);
      }
    }
    return ret;
  }

About the Author

Question Info

Publish Time
2023-01-24 23:58
Update Time
2023-01-24 23:58