diff --git a/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo b/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo index b6936dce..6b5fb15e 100644 Binary files a/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo and b/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo differ diff --git a/Essentials DM/Essentials_DM/Essentials_DM.projectinfo b/Essentials DM/Essentials_DM/Essentials_DM.projectinfo index d071b712..483e1974 100644 Binary files a/Essentials DM/Essentials_DM/Essentials_DM.projectinfo and b/Essentials DM/Essentials_DM/Essentials_DM.projectinfo differ diff --git a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo index da52e959..56e6cf1a 100644 Binary files a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo and b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo differ diff --git a/Essentials/PepperDashEssentials/ControlSystem.cs b/Essentials/PepperDashEssentials/ControlSystem.cs index 381d83b1..7080c443 100644 --- a/Essentials/PepperDashEssentials/ControlSystem.cs +++ b/Essentials/PepperDashEssentials/ControlSystem.cs @@ -48,8 +48,8 @@ namespace PepperDash.Essentials /// public void GoWithLoad() { - var thread = new Thread(o => - { +// var thread = new Thread(o => +// { try { CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync", @@ -58,9 +58,9 @@ namespace PepperDash.Essentials //PortalSync = new PepperDashPortalSyncClient(); //Temp Cotija testing - //CotijaInterfaceController CotijaInterface = new CotijaInterfaceController("WebClient1"); + CotijaInterfaceController CotijaInterface = new CotijaInterfaceController("WebClient1"); - //CotijaInterface.InitializeClient("http://192.168.1.105"); + //CotijaInterface.InitializeClientAndEventStream("http://localhost:3000/api/system/stream/abcdefgh"); Debug.Console(0, "Starting Essentials load from configuration"); ConfigReader.LoadConfig2(); @@ -77,8 +77,8 @@ namespace PepperDash.Essentials { Debug.Console(0, "FATAL INITIALIZE ERROR. System is in an inconsistent state:\r{0}", e); } - return null; - }, null); +// return null; +// }, null); } public void EnablePortalSync(string s) diff --git a/Essentials/PepperDashEssentials/Fusion/FusionSystemController.cs b/Essentials/PepperDashEssentials/Fusion/FusionSystemController.cs index c4aed8fc..3deeccb9 100644 --- a/Essentials/PepperDashEssentials/Fusion/FusionSystemController.cs +++ b/Essentials/PepperDashEssentials/Fusion/FusionSystemController.cs @@ -78,6 +78,7 @@ namespace PepperDash.Essentials.Fusion public EssentialsHuddleSpaceFusionSystemController(EssentialsHuddleSpaceRoom room, uint ipId) : base(room.Key + "-fusion") { + Room = room; IpId = ipId; diff --git a/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo b/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo index 161f6048..8f657ecb 100644 Binary files a/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo and b/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo differ diff --git a/Essentials/PepperDashEssentials/UI/CotijaInterfaceController.cs b/Essentials/PepperDashEssentials/UI/CotijaInterfaceController.cs index c105d873..7aa3752b 100644 --- a/Essentials/PepperDashEssentials/UI/CotijaInterfaceController.cs +++ b/Essentials/PepperDashEssentials/UI/CotijaInterfaceController.cs @@ -14,23 +14,77 @@ namespace PepperDash.Essentials { public class CotijaInterfaceController : Device { + StreamReader Reader; + + Crestron.SimplSharp.Net.Connection Connection; + public CotijaInterfaceController(string key) : base(key) { - CrestronConsole.AddNewConsoleCommand(InitializeClient, "InitializeHttpClient", "Initializes a new HTTP client connection to a specified URL", ConsoleAccessLevelEnum.AccessOperator); + CrestronConsole.AddNewConsoleCommand(InitializeClientAndEventStream, "InitializeHttpClient", "Initializes a new HTTP client connection to a specified URL", ConsoleAccessLevelEnum.AccessOperator); } - public void InitializeClient(string url) + public void InitializeClientAndEventStream(string url) { - HttpClient webClient = new HttpClient(); - webClient.Verbose = true; - HttpClientRequest request = new HttpClientRequest(); - request.Url.Parse(url); - request.Header.AddHeader(new HttpHeader("accept", "text/event-stream")); - request.Header.SetHeaderValue("Expect", ""); - webClient.DispatchAsync(request, (resp, err) => + try { - CrestronConsole.PrintLine(resp.ContentString); - }); + HttpClient webClient = new HttpClient(); + webClient.Verbose = true; + HttpClientRequest request = new HttpClientRequest(); + request.Url = new UrlParser(url); + request.Header.AddHeader(new HttpHeader("Accept", "text/event-stream")); + request.KeepAlive = true; + + /// Experimenting with grabbing connection before the request + Connection = webClient.ConnectNew("192.168.1.120", 3000); + Debug.Console(1, this, "Connection Port: {0}", Connection.LocalEndPointPort); + Reader = new StreamReader(Connection); + Connection.OnBytesReceived += new EventHandler(DataConnection_OnBytesReceived); + + /// Not sure if this is starting a new connection + webClient.DispatchAsync(request, StreamConnectionCallback); + + } + catch (Exception e) + { + Debug.Console(1, this, "Error Initializing Cotija client:\n{0}", e); + } } + + // This callback happens but none of the events would fire (when not commented out) + void StreamConnectionCallback(HttpClientResponse resp, HTTP_CALLBACK_ERROR err) + { + Debug.Console(1, this, "Connection Port: {0}", resp.DataConnection.LocalEndPointPort); + Debug.Console(1, this, "Connections are equal {0}", resp.DataConnection == Connection); + Debug.Console(1, this, "Callback Fired"); + //resp.DataConnection.OnBytesReceived += new EventHandler(DataConnection_OnBytesReceived); + //Debug.Console(1, this, "Received: '{0}'", resp.ContentString); + //resp.OnTransferEnd += new Crestron.SimplSharp.Net.TransferEndEventHandler(resp_OnTransferEnd); + //resp.OnTransferProgress += new Crestron.SimplSharp.Net.TransferProgressEventHandler(resp_OnTransferProgress); + //resp.OnTransferStart += new Crestron.SimplSharp.Net.TransferStartEventHandler(resp_OnTransferStart); + } + + // We could never get this event handler to fire + void DataConnection_OnBytesReceived(object sender, EventArgs e) + { + Debug.Console(1, this, "OnBytesReceived Event Fired."); + Debug.Console(1, this, "Event: Received: '{0}'", Reader.ReadToEnd()); + } + + //void resp_OnTransferStart(object sender, Crestron.SimplSharp.Net.TransferStartEventArgs e) + //{ + // Debug.Console(1, this, "OnTransferStart"); + //} + + //void resp_OnTransferProgress(object sender, Crestron.SimplSharp.Net.TransferProgressEventArgs e) + //{ + // Debug.Console(1, this, "OnTransferProgress"); + //} + + + + //void resp_OnTransferEnd(object sender, Crestron.SimplSharp.Net.TransferEndEventArgs e) + //{ + // Debug.Console(1, this, "OnTransferEnd"); + //} } } \ No newline at end of file