android: add IceServer.urls field
This makes api more consistent with ios and native library BUG=None Review-Url: https://codereview.webrtc.org/3012843002 Cr-Commit-Position: refs/heads/master@{#19770}
This commit is contained in:
committed by
Commit Bot
parent
e0406fd955
commit
0ea0310b89
@ -99,7 +99,8 @@ public class PeerConnection {
|
||||
// List of URIs associated with this server. Valid formats are described
|
||||
// in RFC7064 and RFC7065, and more may be added in the future. The "host"
|
||||
// part of the URI may contain either an IP address or a hostname.
|
||||
public final String uri;
|
||||
@Deprecated public final String uri;
|
||||
public final List<String> urls;
|
||||
public final String username;
|
||||
public final String password;
|
||||
public final TlsCertPolicy tlsCertPolicy;
|
||||
@ -136,12 +137,32 @@ public class PeerConnection {
|
||||
@Deprecated
|
||||
public IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy,
|
||||
String hostname) {
|
||||
this(uri, username, password, tlsCertPolicy, hostname, null, null);
|
||||
this(uri, Collections.singletonList(uri), username, password, tlsCertPolicy, hostname, null,
|
||||
null);
|
||||
}
|
||||
|
||||
private IceServer(String uri, String username, String password, TlsCertPolicy tlsCertPolicy,
|
||||
String hostname, List<String> tlsAlpnProtocols, List<String> tlsEllipticCurves) {
|
||||
private IceServer(String uri, List<String> urls, String username, String password,
|
||||
TlsCertPolicy tlsCertPolicy, String hostname, List<String> tlsAlpnProtocols,
|
||||
List<String> tlsEllipticCurves) {
|
||||
if (uri == null || urls == null || urls.isEmpty()) {
|
||||
throw new IllegalArgumentException("uri == null || urls == null || urls.isEmpty()");
|
||||
}
|
||||
for (String it : urls) {
|
||||
if (it == null) {
|
||||
throw new IllegalArgumentException("urls element is null: " + urls);
|
||||
}
|
||||
}
|
||||
if (username == null) {
|
||||
throw new IllegalArgumentException("username == null");
|
||||
}
|
||||
if (password == null) {
|
||||
throw new IllegalArgumentException("password == null");
|
||||
}
|
||||
if (hostname == null) {
|
||||
throw new IllegalArgumentException("hostname == null");
|
||||
}
|
||||
this.uri = uri;
|
||||
this.urls = urls;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.tlsCertPolicy = tlsCertPolicy;
|
||||
@ -151,16 +172,20 @@ public class PeerConnection {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return uri + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname
|
||||
return urls + " [" + username + ":" + password + "] [" + tlsCertPolicy + "] [" + hostname
|
||||
+ "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]";
|
||||
}
|
||||
|
||||
public static Builder builder(String uri) {
|
||||
return new Builder(uri);
|
||||
return new Builder(Collections.singletonList(uri));
|
||||
}
|
||||
|
||||
public static Builder builder(List<String> urls) {
|
||||
return new Builder(urls);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String uri;
|
||||
private final List<String> urls;
|
||||
private String username = "";
|
||||
private String password = "";
|
||||
private TlsCertPolicy tlsCertPolicy = TlsCertPolicy.TLS_CERT_POLICY_SECURE;
|
||||
@ -168,8 +193,11 @@ public class PeerConnection {
|
||||
private List<String> tlsAlpnProtocols;
|
||||
private List<String> tlsEllipticCurves;
|
||||
|
||||
private Builder(String uri) {
|
||||
this.uri = uri;
|
||||
private Builder(List<String> urls) {
|
||||
if (urls == null || urls.isEmpty()) {
|
||||
throw new IllegalArgumentException("urls == null || urls.isEmpty(): " + urls);
|
||||
}
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public Builder setUsername(String username) {
|
||||
@ -203,8 +231,8 @@ public class PeerConnection {
|
||||
}
|
||||
|
||||
public IceServer createIceServer() {
|
||||
return new IceServer(
|
||||
uri, username, password, tlsCertPolicy, hostname, tlsAlpnProtocols, tlsEllipticCurves);
|
||||
return new IceServer(urls.get(0), urls, username, password, tlsCertPolicy, hostname,
|
||||
tlsAlpnProtocols, tlsEllipticCurves);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,8 +349,8 @@ void JavaToNativeIceServers(JNIEnv* jni,
|
||||
PeerConnectionInterface::IceServers* ice_servers) {
|
||||
for (jobject j_ice_server : Iterable(jni, j_ice_servers)) {
|
||||
jclass j_ice_server_class = GetObjectClass(jni, j_ice_server);
|
||||
jfieldID j_ice_server_uri_id =
|
||||
GetFieldID(jni, j_ice_server_class, "uri", "Ljava/lang/String;");
|
||||
jfieldID j_ice_server_urls_id =
|
||||
GetFieldID(jni, j_ice_server_class, "urls", "Ljava/util/List;");
|
||||
jfieldID j_ice_server_username_id =
|
||||
GetFieldID(jni, j_ice_server_class, "username", "Ljava/lang/String;");
|
||||
jfieldID j_ice_server_password_id =
|
||||
@ -366,8 +366,7 @@ void JavaToNativeIceServers(JNIEnv* jni,
|
||||
jni, j_ice_server_class, "tlsAlpnProtocols", "Ljava/util/List;");
|
||||
jfieldID j_ice_server_tls_elliptic_curves_id = GetFieldID(
|
||||
jni, j_ice_server_class, "tlsEllipticCurves", "Ljava/util/List;");
|
||||
jstring uri = reinterpret_cast<jstring>(
|
||||
GetObjectField(jni, j_ice_server, j_ice_server_uri_id));
|
||||
jobject urls = GetObjectField(jni, j_ice_server, j_ice_server_urls_id);
|
||||
jstring username = reinterpret_cast<jstring>(
|
||||
GetObjectField(jni, j_ice_server, j_ice_server_username_id));
|
||||
jstring password = reinterpret_cast<jstring>(
|
||||
@ -381,7 +380,7 @@ void JavaToNativeIceServers(JNIEnv* jni,
|
||||
jobject tls_elliptic_curves = GetNullableObjectField(
|
||||
jni, j_ice_server, j_ice_server_tls_elliptic_curves_id);
|
||||
PeerConnectionInterface::IceServer server;
|
||||
server.uri = JavaToStdString(jni, uri);
|
||||
server.urls = JavaToStdVectorStrings(jni, urls);
|
||||
server.username = JavaToStdString(jni, username);
|
||||
server.password = JavaToStdString(jni, password);
|
||||
server.tls_cert_policy = tls_cert_policy;
|
||||
|
||||
Reference in New Issue
Block a user