mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
Getting websocket -> cotija going
This commit is contained in:
@@ -4,5 +4,5 @@
|
|||||||
[assembly: AssemblyCompany("PepperDash Technology Corp")]
|
[assembly: AssemblyCompany("PepperDash Technology Corp")]
|
||||||
[assembly: AssemblyProduct("PepperDashEssentials")]
|
[assembly: AssemblyProduct("PepperDashEssentials")]
|
||||||
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")]
|
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")]
|
||||||
[assembly: AssemblyVersion("1.0.40.*")]
|
[assembly: AssemblyVersion("1.0.41.*")]
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
|
|||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Crestron.SimplSharpPro.CrestronThread;
|
using Crestron.SimplSharpPro.CrestronThread;
|
||||||
|
using Crestron.SimplSharp.CrestronWebSocketClient;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharp.Net.Http;
|
using Crestron.SimplSharp.Net.Http;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -21,7 +22,9 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
int SseMessageLengthBeforeFailureCount;
|
int SseMessageLengthBeforeFailureCount;
|
||||||
|
|
||||||
GenericHttpSseClient SseClient;
|
WebSocketClient WSClient;
|
||||||
|
|
||||||
|
//GenericHttpSseClient SseClient;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prevents post operations from stomping on each other and getting lost
|
/// Prevents post operations from stomping on each other and getting lost
|
||||||
@@ -68,7 +71,7 @@ namespace PepperDash.Essentials
|
|||||||
Config = config;
|
Config = config;
|
||||||
Debug.Console(0, this, "Mobile UI controller initializing for server:{0}", config.ServerUrl);
|
Debug.Console(0, this, "Mobile UI controller initializing for server:{0}", config.ServerUrl);
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(DisconnectSseClient,
|
CrestronConsole.AddNewConsoleCommand(DisconnectStreamClient,
|
||||||
"CloseHttpClient", "Closes the active HTTP client", ConsoleAccessLevelEnum.AccessOperator);
|
"CloseHttpClient", "Closes the active HTTP client", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(AuthorizeSystem,
|
CrestronConsole.AddNewConsoleCommand(AuthorizeSystem,
|
||||||
"cotijaauth", "Authorizes system to talk to cotija server", ConsoleAccessLevelEnum.AccessOperator);
|
"cotijaauth", "Authorizes system to talk to cotija server", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
@@ -318,10 +321,13 @@ namespace PepperDash.Essentials
|
|||||||
/// Disconnects the SSE Client and stops the heartbeat timer
|
/// Disconnects the SSE Client and stops the heartbeat timer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command"></param>
|
/// <param name="command"></param>
|
||||||
void DisconnectSseClient(string command)
|
void DisconnectStreamClient(string command)
|
||||||
{
|
{
|
||||||
if(SseClient != null)
|
//if(SseClient != null)
|
||||||
SseClient.Disconnect();
|
// SseClient.Disconnect();
|
||||||
|
|
||||||
|
if (WSClient != null && WSClient.Connected)
|
||||||
|
WSClient.Disconnect();
|
||||||
|
|
||||||
if (ServerHeartbeatCheckTimer != null)
|
if (ServerHeartbeatCheckTimer != null)
|
||||||
{
|
{
|
||||||
@@ -338,7 +344,7 @@ namespace PepperDash.Essentials
|
|||||||
/// <param name="err"></param>
|
/// <param name="err"></param>
|
||||||
void PostConnectionCallback(HttpClientResponse resp, HTTP_CALLBACK_ERROR err)
|
void PostConnectionCallback(HttpClientResponse resp, HTTP_CALLBACK_ERROR err)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "PostConnectionCallback err: {0}", err);
|
Debug.Console(1, this, "PostConnectionCallback: {0}", err);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (resp != null && resp.Code == 200)
|
if (resp != null && resp.Code == 200)
|
||||||
@@ -349,7 +355,7 @@ namespace PepperDash.Essentials
|
|||||||
ServerReconnectTimer = null;
|
ServerReconnectTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectSseClient(null);
|
ConnectStreamClient(null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -364,7 +370,7 @@ namespace PepperDash.Essentials
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error Initializing SSE Client: {0}", e);
|
Debug.Console(1, this, "Error Initializing Stream Client: {0}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,33 +427,48 @@ namespace PepperDash.Essentials
|
|||||||
/// Connects the SSE Client
|
/// Connects the SSE Client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="o"></param>
|
/// <param name="o"></param>
|
||||||
void ConnectSseClient(object o)
|
void ConnectStreamClient(object o)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Initializing SSE Client.");
|
Debug.Console(0, this, "Initializing Stream client to server.");
|
||||||
|
|
||||||
if (SseClient == null)
|
if (WSClient == null)
|
||||||
{
|
{
|
||||||
SseClient = new GenericHttpSseClient(string.Format("{0}-SseClient", Key), Name);
|
WSClient = new WebSocketClient();
|
||||||
|
WSClient.URL = string.Format("wss://{0}/system/join/{1}", Config.ServerUrl, this.SystemUuid);
|
||||||
|
WSClient.Connect();
|
||||||
|
Debug.Console(0, this, "Websocket connected");
|
||||||
|
WSClient.ReceiveCallBack = WebsocketReceive;
|
||||||
|
WSClient.ReceiveAsync();
|
||||||
|
}
|
||||||
|
|
||||||
CommunicationGather LineGathered = new CommunicationGather(SseClient, "\x0d\x0a");
|
|
||||||
|
|
||||||
LineGathered.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(SSEClient_LineReceived);
|
//// **********************************
|
||||||
}
|
//if (SseClient == null)
|
||||||
else
|
//{
|
||||||
{
|
// SseClient = new GenericHttpSseClient(string.Format("{0}-SseClient", Key), Name);
|
||||||
if (SseClient.IsConnected)
|
|
||||||
{
|
// CommunicationGather LineGathered = new CommunicationGather(SseClient, "\x0d\x0a");
|
||||||
SseClient.Disconnect();
|
|
||||||
}
|
// LineGathered.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(SSEClient_LineReceived);
|
||||||
}
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// if (SseClient.IsConnected)
|
||||||
|
// {
|
||||||
|
// SseClient.Disconnect();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
string uuid = Essentials.ConfigReader.ConfigObject.SystemUuid;
|
string uuid = Essentials.ConfigReader.ConfigObject.SystemUuid;
|
||||||
|
|
||||||
SseClient.Url = string.Format("http://{0}/api/system/stream/{1}", Config.ServerUrl, uuid);
|
//SseClient.Url = string.Format("http://{0}/api/system/stream/{1}", Config.ServerUrl, uuid);
|
||||||
|
|
||||||
SseClient.Connect();
|
//SseClient.Connect();
|
||||||
|
|
||||||
|
// ***********************************
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets reconnect timer and updates usercode
|
/// Resets reconnect timer and updates usercode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -465,6 +486,24 @@ namespace PepperDash.Essentials
|
|||||||
ResetOrStartHearbeatTimer();
|
ResetOrStartHearbeatTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <param name="length"></param>
|
||||||
|
/// <param name="opcode"></param>
|
||||||
|
/// <param name="err"></param>
|
||||||
|
int WebsocketReceive(byte[] data, uint length, WebSocketClient.WEBSOCKET_PACKET_TYPES opcode,
|
||||||
|
WebSocketClient.WEBSOCKET_RESULT_CODES err)
|
||||||
|
{
|
||||||
|
var rx = System.Text.Encoding.UTF8.GetString(data, 0, (int)length);
|
||||||
|
|
||||||
|
Debug.Console(0, this, "WS RECEIVED {0}", rx);
|
||||||
|
WSClient.ReceiveAsync();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -496,7 +535,8 @@ namespace PepperDash.Essentials
|
|||||||
}
|
}
|
||||||
else if (type == "close")
|
else if (type == "close")
|
||||||
{
|
{
|
||||||
SseClient.Disconnect();
|
WSClient.Disconnect();
|
||||||
|
//SseClient.Disconnect();
|
||||||
|
|
||||||
ServerHeartbeatCheckTimer.Stop();
|
ServerHeartbeatCheckTimer.Stop();
|
||||||
// Start the reconnect timer
|
// Start the reconnect timer
|
||||||
|
|||||||
@@ -678,7 +678,7 @@ namespace PepperDash.Essentials.UIDrivers.VC
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If only one contact method, just dial that method
|
// If only one contact method, just dial that method
|
||||||
DirectoryList.SetItemButtonAction(i, b => Codec.Dial(dc.ContactMethods[0].Number));
|
DirectoryList.SetItemButtonAction(i, b => { if (!b) Codec.Dial(dc.ContactMethods[0].Number); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // is DirectoryFolder
|
else // is DirectoryFolder
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user