diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index 2dd2d3f..3f0cd33 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -46,6 +46,7 @@ namespace ClientApp.Utils engineConnection = EngineConnection.INSTANCE; engineConnection.OnNoTunnelId = RetryEngineConnection; engineConnection.OnSuccessFullConnection = engineConnected; + engineConnection.OnEngineDisconnect = RetryEngineConnection; if (!engineConnection.Connected) engineConnection.Connect(); } diff --git a/ClientApp/Utils/EngineConnection.cs b/ClientApp/Utils/EngineConnection.cs index c8ac28e..c852058 100644 --- a/ClientApp/Utils/EngineConnection.cs +++ b/ClientApp/Utils/EngineConnection.cs @@ -10,16 +10,17 @@ using LibNoise.Primitive; namespace ClientApp.Utils { public delegate void HandleSerial(string message); - public delegate void HandleNoTunnelId(); - public delegate void OnSuccessfullConnection(); + public delegate void EngineDelegate(); public sealed class EngineConnection { private static EngineConnection instance = null; private static readonly object padlock = new object(); private static System.Timers.Timer updateTimer; - public HandleNoTunnelId OnNoTunnelId; - public OnSuccessfullConnection OnSuccessFullConnection; + private static System.Timers.Timer noVRResponseTimer; + public EngineDelegate OnNoTunnelId; + public EngineDelegate OnSuccessFullConnection; + public EngineDelegate OnEngineDisconnect; private static PC[] PCs = { @@ -68,6 +69,12 @@ namespace ClientApp.Utils updateTimer.Elapsed += UpdateTimer_Elapsed; updateTimer.AutoReset = true; updateTimer.Enabled = false; + + noVRResponseTimer = new System.Timers.Timer(15000); + noVRResponseTimer.Elapsed += noVRResponseTimeout; + noVRResponseTimer.AutoReset = false; + noVRResponseTimer.Enabled = false; + } private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) @@ -75,6 +82,21 @@ namespace ClientApp.Utils UpdateInfoPanel(); } + private void noVRResponseTimeout(object sender, System.Timers.ElapsedEventArgs e) + { + Write("VR RESPONSE TIMEOUT"); + noVRResponseTimer.Stop(); + sessionId = string.Empty; + tunnelId = string.Empty; + cameraId = string.Empty; + routeId = string.Empty; + panelId = string.Empty; + bikeId = string.Empty; + groundPlaneId = string.Empty; + terrainId = string.Empty; + OnEngineDisconnect?.Invoke(); + } + /// /// Singleton constructor /// @@ -166,6 +188,7 @@ namespace ClientApp.Utils { Write("got tunnel id! " + tunnelId); Connected = true; + noVRResponseTimer.Enabled = true; OnSuccessFullConnection?.Invoke(); } } @@ -177,6 +200,9 @@ namespace ClientApp.Utils //Console.WriteLine("Got serial " + serial); if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message); } + + noVRResponseTimer.Stop(); + noVRResponseTimer.Start(); } public void initScene()