diff --git a/Assets/Scripts/EndpointLoader.cs b/Assets/Scripts/EndpointLoader.cs index d954010..46a5fb9 100644 --- a/Assets/Scripts/EndpointLoader.cs +++ b/Assets/Scripts/EndpointLoader.cs @@ -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 availableServices = new List(); + private HashSet availableServices = new HashSet(); 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); + } }); } diff --git a/Assets/Scripts/MdnsService.cs b/Assets/Scripts/MdnsService.cs index e47be4e..7fe2951 100644 --- a/Assets/Scripts/MdnsService.cs +++ b/Assets/Scripts/MdnsService.cs @@ -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; + } }