Use multicast first

This commit is contained in:
Santiago Lo Coco 2024-11-04 22:17:42 +01:00
parent 020fe53278
commit 64f57d675d
2 changed files with 126 additions and 48 deletions

View File

@ -11867,13 +11867,13 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 3596669758744615198}
- component: {fileID: 4877567036410796677}
- component: {fileID: 938761637425299912}
- component: {fileID: 9095211984209372687}
- component: {fileID: 4130250295964021826}
- component: {fileID: 1893886425749181031}
- component: {fileID: 9095211984209372690}
- component: {fileID: 9095211984209372689}
- component: {fileID: 9095211984209372691}
m_Layer: 0
m_Name: ScrollParent
m_TagString: Untagged
@ -12555,27 +12555,6 @@ MonoBehaviour:
minCompressPercentage: 0.25
highlightPlate: {fileID: 7553873076742740425}
highlightPlateAnimationTime: 0.25
--- !u!114 &4877567036410796677
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3467693338133494675}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2d1fea68463e4e84b86c395b654f950d, type: 3}
m_Name:
m_EditorClassIdentifier:
visualizationObject: {fileID: 0}
interactableObject: {fileID: 0}
buttonBehavior: 0
autoFollowAtDistance: 0
autoFollowDistance: 2
autoFollowTransformTarget: {fileID: 0}
autoFollowTriggered:
m_PersistentCalls:
m_Calls: []
--- !u!114 &4975191770747669838
MonoBehaviour:
m_ObjectHideFlags: 0
@ -14797,12 +14776,12 @@ MonoBehaviour:
rotateStarted:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
- m_Target: {fileID: 9095211984209372691}
m_TargetAssemblyTypeName: UnityEngine.AudioSource, UnityEngine
m_MethodName: PlayOneShot
m_Mode: 2
m_Arguments:
m_ObjectArgument: {fileID: 8300000, guid: 765efbcf7ca1773488edcc8ab6ba4923, type: 3}
m_ObjectArgument: {fileID: 8300000, guid: a16c53885bdbc54469088880ea44a9fd, type: 3}
m_ObjectArgumentAssemblyTypeName: UnityEngine.AudioClip, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
@ -14812,12 +14791,12 @@ MonoBehaviour:
rotateStopped:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
- m_Target: {fileID: 9095211984209372691}
m_TargetAssemblyTypeName: UnityEngine.AudioSource, UnityEngine
m_MethodName: PlayOneShot
m_Mode: 2
m_Arguments:
m_ObjectArgument: {fileID: 8300000, guid: 9d90886bb6646244e852a0acb1de3a3b, type: 3}
m_ObjectArgument: {fileID: 8300000, guid: bcae4cbce6135d84b9b04ee9e5b909f4, type: 3}
m_ObjectArgumentAssemblyTypeName: UnityEngine.AudioClip, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
@ -14827,12 +14806,12 @@ MonoBehaviour:
scaleStarted:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
- m_Target: {fileID: 9095211984209372691}
m_TargetAssemblyTypeName: UnityEngine.AudioSource, UnityEngine
m_MethodName: PlayOneShot
m_Mode: 2
m_Arguments:
m_ObjectArgument: {fileID: 8300000, guid: bdc1f15a0c976854780adcd7e56cfb3e, type: 3}
m_ObjectArgument: {fileID: 8300000, guid: a16c53885bdbc54469088880ea44a9fd, type: 3}
m_ObjectArgumentAssemblyTypeName: UnityEngine.AudioClip, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
@ -14842,12 +14821,12 @@ MonoBehaviour:
scaleStopped:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_TargetAssemblyTypeName:
- m_Target: {fileID: 9095211984209372691}
m_TargetAssemblyTypeName: UnityEngine.AudioSource, UnityEngine
m_MethodName: PlayOneShot
m_Mode: 2
m_Arguments:
m_ObjectArgument: {fileID: 8300000, guid: 23a78d131feb8774ebe5dd1ea221933e, type: 3}
m_ObjectArgument: {fileID: 8300000, guid: bcae4cbce6135d84b9b04ee9e5b909f4, type: 3}
m_ObjectArgumentAssemblyTypeName: UnityEngine.AudioClip, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
@ -14875,6 +14854,102 @@ MonoBehaviour:
m_EditorClassIdentifier:
autoConstraintSelection: 1
selectedConstraints: []
--- !u!82 &9095211984209372691
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3467693338133494675}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!33 &9134068405370652459
MeshFilter:
m_ObjectHideFlags: 0

View File

@ -20,16 +20,18 @@ public class EndpointLoader : MonoBehaviour
[SerializeField]
private ServicesListPopulator servicesListPopulator;
private string apiUrl;
private bool triedMulticast = false;
private string apiUrl = "http://windows.loca:5000/api/endpoints"; // Typo on purpose
private bool defaultEndpointLoaded = false;
private HashSet<MdnsService> availableServices = new HashSet<MdnsService>();
private const string defaultApiUrl = "http://windows.local:5000/api/endpoints";
private const string defaultEndpoint1 = "http://windows.local:8100/mystream/";
private const string defaultEndpoint2 = "http://windows.local:8200/mystream/";
private bool defaultEndpoint1Loaded = false;
private bool defaultEndpoint2Loaded = false;
private HashSet<MdnsService> availableServices = new HashSet<MdnsService>();
private void Start()
{
apiUrl = defaultApiUrl;
StartCoroutine(LoadEndpoints());
}
@ -38,13 +40,13 @@ public class EndpointLoader : MonoBehaviour
using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint1))
{
yield return request.SendWebRequest();
ProcessEndpointResponse(request, webView1, defaultEndpoint1, ref defaultEndpoint1Loaded);
ProcessEndpointResponse(request, webView1, defaultEndpoint1, ref defaultEndpointLoaded);
}
using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint2))
{
yield return request.SendWebRequest();
ProcessEndpointResponse(request, webView2, defaultEndpoint2, ref defaultEndpoint2Loaded);
ProcessEndpointResponse(request, webView2, defaultEndpoint2, ref defaultEndpointLoaded);
}
}
@ -64,6 +66,12 @@ public class EndpointLoader : MonoBehaviour
private IEnumerator LoadEndpoints()
{
if (!triedMulticast)
{
StartListeningForMulticast();
yield break;
}
var request = new UnityWebRequest(apiUrl, UnityWebRequest.kHttpVerbGET);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
@ -84,14 +92,9 @@ public class EndpointLoader : MonoBehaviour
yield return StartCoroutine(TryLoadingFromDefaultEndpoints());
}
if (defaultEndpoint1Loaded || defaultEndpoint2Loaded)
if (defaultEndpointLoaded)
{
Debug.Log("At least one default endpoint loaded successfully. No need for multicast or endpoints.");
yield break;
}
else if (!triedMulticast)
{
StartListeningForMulticast();
Debug.Log("At least one default endpoint loaded successfully");
yield break;
}
@ -103,7 +106,7 @@ public class EndpointLoader : MonoBehaviour
if (endpoints.Length == 0)
{
Debug.LogError("Parsed endpoints are empty.");
Debug.LogError("Parsed endpoints are empty");
}
else
{