| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | package org.webrtc; |
| 12 |
| 13 | import androidx.annotation.Nullable; |
| 14 | import java.util.Arrays; |
| 15 | import org.webrtc.PeerConnection; |
| 16 |
| 17 | /** |
| 18 | * Representation of a single ICE Candidate, mirroring |
| 19 | * {@code IceCandidateInterface} in the C++ API. |
| 20 | */ |
| 21 | public class IceCandidate { |
| 22 | public final String sdpMid; |
| 23 | public final int sdpMLineIndex; |
| 24 | public final String sdp; |
| 25 | public final String serverUrl; |
| 26 | public final PeerConnection.AdapterType adapterType; |
| 27 |
| 28 | public IceCandidate(String sdpMid, int sdpMLineIndex, String sdp) { |
| 29 | this.sdpMid = sdpMid; |
| 30 | this.sdpMLineIndex = sdpMLineIndex; |
| 31 | this.sdp = sdp; |
| 32 | this.serverUrl = ""; |
| 33 | this.adapterType = PeerConnection.AdapterType.UNKNOWN; |
| 34 | } |
| 35 |
| 36 | @CalledByNative |
| 37 | IceCandidate(String sdpMid, int sdpMLineIndex, String sdp, String serverUrl, |
| 38 | PeerConnection.AdapterType adapterType) { |
| 39 | this.sdpMid = sdpMid; |
| 40 | this.sdpMLineIndex = sdpMLineIndex; |
| 41 | this.sdp = sdp; |
| 42 | this.serverUrl = serverUrl; |
| 43 | this.adapterType = adapterType; |
| 44 | } |
| 45 |
| 46 | @Override |
| 47 | public String toString() { |
| 48 | return sdpMid + ":" + sdpMLineIndex + ":" + sdp + ":" + serverUrl + ":" |
| 49 | + adapterType.toString(); |
| 50 | } |
| 51 |
| 52 | @CalledByNative |
| 53 | String getSdpMid() { |
| 54 | return sdpMid; |
| 55 | } |
| 56 |
| 57 | @CalledByNative |
| 58 | String getSdp() { |
| 59 | return sdp; |
| 60 | } |
| 61 |
| 62 | /** equals() checks sdpMid, sdpMLineIndex, and sdp for equality. */ |
| 63 | @Override |
| 64 | public boolean equals(@Nullable Object object) { |
| 65 | if (!(object instanceof IceCandidate)) { |
| 66 | return false; |
| 67 | } |
| 68 |
| 69 | IceCandidate that = (IceCandidate) object; |
| 70 | return objectEquals(this.sdpMid, that.sdpMid) && this.sdpMLineIndex == that.sdpMLineIndex |
| 71 | && objectEquals(this.sdp, that.sdp); |
| 72 | } |
| 73 |
| 74 | @Override |
| 75 | public int hashCode() { |
| 76 | Object[] values = {sdpMid, sdpMLineIndex, sdp}; |
| 77 | return Arrays.hashCode(values); |
| 78 | } |
| 79 |
| 80 | private static boolean objectEquals(Object o1, Object o2) { |
| 81 | if (o1 == null) { |
| 82 | return o2 == null; |
| 83 | } |
| 84 | return o1.equals(o2); |
| 85 | } |
| 86 | } |
| 87 |