diff --git a/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs b/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs index fa4a28e4..63eb3dea 100644 --- a/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs +++ b/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ [assembly: AssemblyCompany("PepperDash Technology Corp")] [assembly: AssemblyProduct("PepperDashEssentials")] [assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")] -[assembly: AssemblyVersion("1.0.40.*")] +[assembly: AssemblyVersion("1.0.41.*")] diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs index 03f619df..d740921c 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharpPro.CrestronThread; +using Crestron.SimplSharp.CrestronWebSocketClient; using Crestron.SimplSharpPro; using Crestron.SimplSharp.Net.Http; using Newtonsoft.Json; @@ -21,7 +22,9 @@ namespace PepperDash.Essentials { int SseMessageLengthBeforeFailureCount; - GenericHttpSseClient SseClient; + WebSocketClient WSClient; + + //GenericHttpSseClient SseClient; /// /// Prevents post operations from stomping on each other and getting lost @@ -68,7 +71,7 @@ namespace PepperDash.Essentials Config = config; 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); CrestronConsole.AddNewConsoleCommand(AuthorizeSystem, "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 /// /// - void DisconnectSseClient(string command) + void DisconnectStreamClient(string command) { - if(SseClient != null) - SseClient.Disconnect(); + //if(SseClient != null) + // SseClient.Disconnect(); + + if (WSClient != null && WSClient.Connected) + WSClient.Disconnect(); if (ServerHeartbeatCheckTimer != null) { @@ -338,7 +344,7 @@ namespace PepperDash.Essentials /// void PostConnectionCallback(HttpClientResponse resp, HTTP_CALLBACK_ERROR err) { - Debug.Console(1, this, "PostConnectionCallback err: {0}", err); + Debug.Console(1, this, "PostConnectionCallback: {0}", err); try { if (resp != null && resp.Code == 200) @@ -349,7 +355,7 @@ namespace PepperDash.Essentials ServerReconnectTimer = null; } - ConnectSseClient(null); + ConnectStreamClient(null); } else { @@ -364,7 +370,7 @@ namespace PepperDash.Essentials } 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 /// /// - 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) - { - SseClient = new GenericHttpSseClient(string.Format("{0}-SseClient", Key), Name); + if (WSClient == null) + { + 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(SSEClient_LineReceived); - } - else - { - if (SseClient.IsConnected) - { - SseClient.Disconnect(); - } - } + //// ********************************** + //if (SseClient == null) + //{ + // SseClient = new GenericHttpSseClient(string.Format("{0}-SseClient", Key), Name); + + // CommunicationGather LineGathered = new CommunicationGather(SseClient, "\x0d\x0a"); + + // LineGathered.LineReceived += new EventHandler(SSEClient_LineReceived); + //} + //else + //{ + // if (SseClient.IsConnected) + // { + // SseClient.Disconnect(); + // } + //} 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(); + + // *********************************** } + /// /// Resets reconnect timer and updates usercode /// @@ -464,7 +485,25 @@ namespace PepperDash.Essentials } ResetOrStartHearbeatTimer(); } - + + + /// + /// + /// + /// + /// + /// + /// + 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; + } + /// /// /// @@ -496,7 +535,8 @@ namespace PepperDash.Essentials } else if (type == "close") { - SseClient.Disconnect(); + WSClient.Disconnect(); + //SseClient.Disconnect(); ServerHeartbeatCheckTimer.Stop(); // Start the reconnect timer diff --git a/Essentials/PepperDashEssentials/UIDrivers/VC/EssentialsVideoCodecUiDriver.cs b/Essentials/PepperDashEssentials/UIDrivers/VC/EssentialsVideoCodecUiDriver.cs index 8a2f014f..526585ab 100644 --- a/Essentials/PepperDashEssentials/UIDrivers/VC/EssentialsVideoCodecUiDriver.cs +++ b/Essentials/PepperDashEssentials/UIDrivers/VC/EssentialsVideoCodecUiDriver.cs @@ -678,7 +678,7 @@ namespace PepperDash.Essentials.UIDrivers.VC else { // 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 diff --git a/Release Package/PepperDashEssentials.cpz b/Release Package/PepperDashEssentials.cpz index 421c4c81..c735b174 100644 Binary files a/Release Package/PepperDashEssentials.cpz and b/Release Package/PepperDashEssentials.cpz differ diff --git a/Release Package/PepperDashEssentials.dll b/Release Package/PepperDashEssentials.dll index fd66bef9..a8efcfc9 100644 Binary files a/Release Package/PepperDashEssentials.dll and b/Release Package/PepperDashEssentials.dll differ