Merge remote-tracking branch 'origin/develop' into newDoctor
This commit is contained in:
@@ -10,7 +10,7 @@ using Util;
|
||||
namespace ClientApp.Utils
|
||||
{
|
||||
public delegate void EngineCallback();
|
||||
public class Client : IDataReceiver
|
||||
public class Client : IDataReceiver, IDisposable
|
||||
{
|
||||
public EngineCallback engineConnectFailed;
|
||||
public EngineCallback engineConnectSuccess;
|
||||
@@ -46,6 +46,7 @@ namespace ClientApp.Utils
|
||||
engineConnection = EngineConnection.INSTANCE;
|
||||
engineConnection.OnNoTunnelId = RetryEngineConnection;
|
||||
engineConnection.OnSuccessFullConnection = engineConnected;
|
||||
engineConnection.OnEngineDisconnect = RetryEngineConnection;
|
||||
if (!engineConnection.Connected) engineConnection.Connect();
|
||||
}
|
||||
|
||||
@@ -87,6 +88,10 @@ namespace ClientApp.Utils
|
||||
/// <param name="ar">the result of the async read</param>
|
||||
private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
|
||||
return;
|
||||
|
||||
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
|
||||
if (totalBufferReceived + receivedBytes > 1024)
|
||||
@@ -122,7 +127,7 @@ namespace ClientApp.Utils
|
||||
this.LoginViewModel.setLoginStatus(true);
|
||||
this.connected = true;
|
||||
initEngine();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -224,7 +229,7 @@ namespace ClientApp.Utils
|
||||
/// <param name="bytes">the message</param>
|
||||
public void Bike(byte[] bytes)
|
||||
{
|
||||
|
||||
|
||||
if (!sessionRunning)
|
||||
{
|
||||
return;
|
||||
@@ -266,7 +271,7 @@ namespace ClientApp.Utils
|
||||
/// </summary>
|
||||
public void tryLogin(string username, string password)
|
||||
{
|
||||
|
||||
|
||||
string hashPassword = Util.Hasher.HashString(password);
|
||||
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword));
|
||||
@@ -288,5 +293,13 @@ namespace ClientApp.Utils
|
||||
{
|
||||
this.LoginViewModel = loginViewModel;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Debug.WriteLine("client dispose called");
|
||||
this.stream.Dispose();
|
||||
this.client.Dispose();
|
||||
this.handler.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
@@ -42,6 +43,7 @@ namespace ClientApp.Utils
|
||||
private static string headId = string.Empty;
|
||||
private static string groundPlaneId = string.Empty;
|
||||
private static string terrainId = string.Empty;
|
||||
private static string lastMessage = "No message received yet";
|
||||
|
||||
public float BikeSpeed { get; set; }
|
||||
public float BikePower { get; set; }
|
||||
@@ -67,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)
|
||||
@@ -74,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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Singleton constructor
|
||||
/// </summary>
|
||||
@@ -165,6 +188,7 @@ namespace ClientApp.Utils
|
||||
{
|
||||
Write("got tunnel id! " + tunnelId);
|
||||
Connected = true;
|
||||
noVRResponseTimer.Enabled = true;
|
||||
OnSuccessFullConnection?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -176,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()
|
||||
@@ -297,6 +324,11 @@ namespace ClientApp.Utils
|
||||
{
|
||||
// TODO check if is drawn
|
||||
});
|
||||
SendMessageAndOnResponse(mainCommand.showMessage(panelId, "message", lastMessage), "message",
|
||||
(message) =>
|
||||
{
|
||||
// TODO check if is drawn
|
||||
});
|
||||
|
||||
// Check if every text is drawn!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user