Use a HashSet for the services
This commit is contained in:
parent
916e250fa8
commit
84bc24f5cf
|
@ -19,7 +19,7 @@ public class EndpointLoader : MonoBehaviour
|
|||
private const string defaultEndpoint2 = "http://windows.local:8200/mystream/";
|
||||
private bool defaultEndpoint1Loaded = false;
|
||||
private bool defaultEndpoint2Loaded = false;
|
||||
private List<MdnsService> availableServices = new List<MdnsService>();
|
||||
private HashSet<MdnsService> availableServices = new HashSet<MdnsService>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
@ -112,9 +112,11 @@ public class EndpointLoader : MonoBehaviour
|
|||
triedMulticast = true;
|
||||
serviceDiscovery.StartListening((service) =>
|
||||
{
|
||||
Debug.Log($"Received multicast message: {service.Host}");
|
||||
availableServices.Add(service);
|
||||
AddServiceToTable(service);
|
||||
bool wasAdded = availableServices.Add(service);
|
||||
if (wasAdded)
|
||||
{
|
||||
AddServiceToTable(service);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -20,4 +20,23 @@ public class MdnsService
|
|||
{
|
||||
return $"IpAddress: {IpAddress}, Port: {Port}, Path: {Path}, Host: {Host}";
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is MdnsService service &&
|
||||
IpAddress == service.IpAddress &&
|
||||
Host == service.Host &&
|
||||
Port == service.Port &&
|
||||
Path == service.Path;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = hash * 31 + (IpAddress?.GetHashCode() ?? 0);
|
||||
hash = hash * 31 + Port.GetHashCode();
|
||||
hash = hash * 31 + (Path?.GetHashCode() ?? 0);
|
||||
hash = hash * 31 + (Host?.GetHashCode() ?? 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue