From df192895a160469c65de8fa309de49c688cf26a9 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 5 Dec 2019 15:43:53 -0700 Subject: [PATCH] Moved messaging for new types to specifc type messengers and tested. --- .../Messengers/CameraBaseMessenger.cs | 12 +-- .../Messengers/IRunRouteActionMessenger.cs | 82 +++++++++++++++++++ ...eControlEssentialsHuddleSpaceRoomBridge.cs | 45 +++------- .../PepperDashEssentials.csproj | 1 + 4 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 PepperDashEssentials/AppServer/Messengers/IRunRouteActionMessenger.cs diff --git a/PepperDashEssentials/AppServer/Messengers/CameraBaseMessenger.cs b/PepperDashEssentials/AppServer/Messengers/CameraBaseMessenger.cs index e1a3468a..f11130b0 100644 --- a/PepperDashEssentials/AppServer/Messengers/CameraBaseMessenger.cs +++ b/PepperDashEssentials/AppServer/Messengers/CameraBaseMessenger.cs @@ -132,17 +132,17 @@ namespace PepperDash.Essentials.AppServer.Messengers { var presetsCamera = Camera as IHasCameraPresets; - var presets = new List(); + var presetList = new List(); if (presetsCamera != null) - presets = presetsCamera.Presets; + presetList = presetsCamera.Presets; - var info = new + PostStatusMessage(new { cameraMode = GetCameraMode(), - hasPresets = Camera as IHasCameraPresets, - presets = presets - }; + hasPresets = Camera is IHasCameraPresets, + presets = presetList + }); } /// diff --git a/PepperDashEssentials/AppServer/Messengers/IRunRouteActionMessenger.cs b/PepperDashEssentials/AppServer/Messengers/IRunRouteActionMessenger.cs new file mode 100644 index 00000000..b1ce4b09 --- /dev/null +++ b/PepperDashEssentials/AppServer/Messengers/IRunRouteActionMessenger.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +using PepperDash.Core; +using PepperDash.Essentials.Core; + +using Newtonsoft.Json.Linq; + +namespace PepperDash.Essentials.AppServer.Messengers +{ + public class IRunRouteActionMessenger : MessengerBase + { + /// + /// Device being bridged + /// + public IRunRouteAction RoutingDevice {get; set;} + + public IRunRouteActionMessenger(string key, IRunRouteAction routingDevice, string messagePath) + : base(key, messagePath) + { + if (routingDevice == null) + throw new ArgumentNullException("routingDevice"); + + RoutingDevice = routingDevice; + + var routingSink = RoutingDevice as IRoutingSinkNoSwitching; + + if (routingSink != null) + { + routingSink.CurrentSourceChange += new SourceInfoChangeHandler(routingSink_CurrentSourceChange); + } + } + + void routingSink_CurrentSourceChange(SourceListItem info, ChangeType type) + { + SendRoutingFullMessageObject(); + } + + protected override void CustomRegisterWithAppServer(MobileControlSystemController appServerController) + { + appServerController.AddAction(MessagePath + "/fullStatus", new Action(SendRoutingFullMessageObject)); + + appServerController.AddAction(string.Format(@"/device/inRoomPc-1/source"), new Action(c => + { + RoutingDevice.RunRouteAction(c.SourceListItem, c.SourceListKey); + })); + + var sinkDevice = RoutingDevice as IRoutingSinkNoSwitching; + if(sinkDevice != null) + { + sinkDevice.CurrentSourceChange += new SourceInfoChangeHandler((o, a) => + { + SendRoutingFullMessageObject(); + }); + } + } + + /// + /// Helper method to update full status of the routing device + /// + void SendRoutingFullMessageObject() + { + var sinkDevice = RoutingDevice as IRoutingSinkNoSwitching; + + if(sinkDevice != null) + { + var sourceKey = sinkDevice.CurrentSourceInfoKey; + + if (string.IsNullOrEmpty(sourceKey)) + sourceKey = "none"; + + PostStatusMessage(new + { + selectedSourceKey = sourceKey + }); + } + } + } +} \ No newline at end of file diff --git a/PepperDashEssentials/AppServer/RoomBridges/MobileControlEssentialsHuddleSpaceRoomBridge.cs b/PepperDashEssentials/AppServer/RoomBridges/MobileControlEssentialsHuddleSpaceRoomBridge.cs index 711f60a1..8a67ba14 100644 --- a/PepperDashEssentials/AppServer/RoomBridges/MobileControlEssentialsHuddleSpaceRoomBridge.cs +++ b/PepperDashEssentials/AppServer/RoomBridges/MobileControlEssentialsHuddleSpaceRoomBridge.cs @@ -78,36 +78,6 @@ namespace PepperDash.Essentials } })); - //****************Temp until testing complete. Then move to own messenger*********************** - - var routeDevice = DeviceManager.GetDeviceForKey("inRoomPc-1") as IRunRouteAction; - if (routeDevice != null) - { - Parent.AddAction(string.Format(@"/device/inRoomPc-1/source"), new Action(c => - { - routeDevice.RunRouteAction(c.SourceListItem, c.SourceListKey); - })); - - var sinkDevice = routeDevice as IRoutingSinkNoSwitching; - if(sinkDevice != null) - { - sinkDevice.CurrentSourceChange += new SourceInfoChangeHandler((o, a) => - { - var contentObject = new - { - selectedSourceKey = sinkDevice.CurrentSourceInfoKey - }; - - Parent.SendMessageToServer(JObject.FromObject(new - { - type = "/device/inRoomPc-1/status", - content = contentObject - })); - - }); - } - } - var defaultRoom = Room as IRunDefaultPresentRoute; if(defaultRoom != null) @@ -190,9 +160,18 @@ namespace PepperDash.Essentials if (device is Essentials.Devices.Common.Cameras.CameraBase) { var camDevice = device as Essentials.Devices.Common.Cameras.CameraBase; - var devKey = device.Key; - Debug.Console(2, this, "Adding CameraBaseMessenger for device: {0}", devKey); - DeviceMessengers.Add(devKey, new CameraBaseMessenger(devKey + "-" + Parent.Key, camDevice, "/device/" + devKey)); + Debug.Console(2, this, "Adding CameraBaseMessenger for device: {0}", device.Key); + var cameraMessenger = new CameraBaseMessenger(device.Key + "-" + Parent.Key, camDevice, "/device/" + device.Key); + DeviceMessengers.Add(device.Key, cameraMessenger); + cameraMessenger.RegisterWithAppServer(Parent); + } + if (device is Essentials.Devices.Common.SoftCodec.BlueJeansPc) + { + var softCodecDevice = device as Essentials.Devices.Common.SoftCodec.BlueJeansPc; + Debug.Console(2, this, "Adding IRunRouteActionMessnger for device: {0}", device.Key); + var routeMessenger = new IRunRouteActionMessenger(device.Key + "-" + Parent.Key, softCodecDevice, "/device/" + device.Key); + DeviceMessengers.Add(device.Key, routeMessenger); + routeMessenger.RegisterWithAppServer(Parent); } } } diff --git a/PepperDashEssentials/PepperDashEssentials.csproj b/PepperDashEssentials/PepperDashEssentials.csproj index 0a535d76..91f07c7d 100644 --- a/PepperDashEssentials/PepperDashEssentials.csproj +++ b/PepperDashEssentials/PepperDashEssentials.csproj @@ -113,6 +113,7 @@ +