using System; using System.Collections.Generic; using Crestron.SimplSharp; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Privacy; using Serilog.Events; namespace PepperDash.Essentials.Room.Config { /// /// Represents a EssentialsRoomConfigHelper /// public class EssentialsRoomConfigHelper { /// /// GetEmergency method /// public static EssentialsRoomEmergencyBase GetEmergency(EssentialsRoomPropertiesConfig props, IEssentialsRoom room) { // This emergency var emergency = props.Emergency; if (emergency != null) { //switch on emergency type here. Right now only contact and shutdown var e = new EssentialsRoomEmergencyContactClosure(room.Key + "-emergency", props.Emergency, room); DeviceManager.AddDevice(e); return e; } return null; } /// /// /// /// /// /// /// /// GetMicrophonePrivacy method /// public static MicrophonePrivacyController GetMicrophonePrivacy( EssentialsRoomPropertiesConfig props, IPrivacy room) { var microphonePrivacy = props.MicrophonePrivacy; if (microphonePrivacy == null) { Debug.LogMessage(LogEventLevel.Information, "Cannot create microphone privacy with null properties"); return null; } // Get the MicrophonePrivacy device from the device manager var mP = (DeviceManager.GetDeviceForKey(props.MicrophonePrivacy.DeviceKey) as MicrophonePrivacyController); // Set this room as the IPrivacy device if (mP == null) { Debug.LogMessage(LogEventLevel.Information, "ERROR: Selected device {0} is not MicrophonePrivacyController", props.MicrophonePrivacy.DeviceKey); return null; } mP.SetPrivacyDevice(room); var behaviour = props.MicrophonePrivacy.Behaviour.ToLower(); if (behaviour == null) { Debug.LogMessage(LogEventLevel.Information, "WARNING: No behaviour defined for MicrophonePrivacyController"); return null; } if (behaviour == "trackroomstate") { // Tie LED enable to room power state var essRoom = room as IEssentialsRoom; essRoom.OnFeedback.OutputChange += (o, a) => { if (essRoom.OnFeedback.BoolValue) mP.EnableLeds = true; else mP.EnableLeds = false; }; mP.EnableLeds = essRoom.OnFeedback.BoolValue; } else if (behaviour == "trackcallstate") { // Tie LED enable to room power state var inCallRoom = room as IHasInCallFeedback; inCallRoom.InCallFeedback.OutputChange += (o, a) => { if (inCallRoom.InCallFeedback.BoolValue) mP.EnableLeds = true; else mP.EnableLeds = false; }; mP.EnableLeds = inCallRoom.InCallFeedback.BoolValue; } return mP; } } /// /// Represents a EssentialsRoomPropertiesConfig /// public class EssentialsRoomPropertiesConfig { /// /// Gets or sets the Addresses /// [JsonProperty("addresses")] public EssentialsRoomAddressPropertiesConfig Addresses { get; set; } /// /// Gets or sets the Description /// [JsonProperty("description")] public string Description { get; set; } /// /// Gets or sets the Emergency /// [JsonProperty("emergency")] public EssentialsRoomEmergencyConfig Emergency { get; set; } /// /// Gets or sets the Help /// [JsonProperty("help")] public EssentialsHelpPropertiesConfig Help { get; set; } /// /// Gets or sets the HelpMessage /// [JsonProperty("helpMessage")] public string HelpMessage { get; set; } /// /// Read this value to get the help message. It checks for the old and new config format. /// public string HelpMessageForDisplay { get { if (Help != null && !string.IsNullOrEmpty(Help.Message)) { return Help.Message; } else { return HelpMessage; } } } /// /// Gets or sets the Environment /// [JsonProperty("environment")] public EssentialsEnvironmentPropertiesConfig Environment { get; set; } /// /// Gets or sets the LogoLight /// [JsonProperty("logo")] public EssentialsLogoPropertiesConfig LogoLight { get; set; } /// /// Gets or sets the LogoDark /// [JsonProperty("logoDark")] public EssentialsLogoPropertiesConfig LogoDark { get; set; } /// /// Gets or sets the MicrophonePrivacy /// [JsonProperty("microphonePrivacy")] public EssentialsRoomMicrophonePrivacyConfig MicrophonePrivacy { get; set; } /// /// Gets or sets the Occupancy /// [JsonProperty("occupancy")] public EssentialsRoomOccSensorConfig Occupancy { get; set; } /// /// Gets or sets the OneButtonMeeting /// [JsonProperty("oneButtonMeeting")] public EssentialsOneButtonMeetingPropertiesConfig OneButtonMeeting { get; set; } /// /// Gets or sets the ShutdownVacancySeconds /// [JsonProperty("shutdownVacancySeconds")] public int ShutdownVacancySeconds { get; set; } /// /// Gets or sets the ShutdownPromptSeconds /// [JsonProperty("shutdownPromptSeconds")] public int ShutdownPromptSeconds { get; set; } /// /// Gets or sets the Tech /// [JsonProperty("tech")] public EssentialsRoomTechConfig Tech { get; set; } /// /// Gets or sets the Volumes /// [JsonProperty("volumes")] public EssentialsRoomVolumesConfig Volumes { get; set; } /// /// Gets or sets the Fusion /// [JsonProperty("fusion")] public EssentialsRoomFusionConfig Fusion { get; set; } /// /// Gets or sets the UiBehavior /// [JsonProperty("essentialsRoomUiBehaviorConfig", NullValueHandling = NullValueHandling.Ignore)] public EssentialsRoomUiBehaviorConfig UiBehavior { get; set; } /// /// Gets or sets the ZeroVolumeWhenSwtichingVolumeDevices /// [JsonProperty("zeroVolumeWhenSwtichingVolumeDevices")] public bool ZeroVolumeWhenSwtichingVolumeDevices { get; set; } /// /// Indicates if this room represents a combination of other rooms /// [JsonProperty("isRoomCombinationScenario")] public bool IsRoomCombinationScenario { get; set; } /// /// Constructor /// public EssentialsRoomPropertiesConfig() { LogoLight = new EssentialsLogoPropertiesConfig(); LogoDark = new EssentialsLogoPropertiesConfig(); } } /// /// Represents a EssentialsRoomUiBehaviorConfig /// public class EssentialsRoomUiBehaviorConfig { /// /// Gets or sets the DisableActivityButtonsWhileWarmingCooling /// [JsonProperty("disableActivityButtonsWhileWarmingCooling")] public bool DisableActivityButtonsWhileWarmingCooling { get; set; } } /// /// Represents a EssentialsAvRoomPropertiesConfig /// public class EssentialsAvRoomPropertiesConfig : EssentialsRoomPropertiesConfig { /// /// Gets or sets the DefaultAudioKey /// [JsonProperty("defaultAudioKey")] public string DefaultAudioKey { get; set; } /// /// Gets or sets the DefaultOnDspPresetKey /// [JsonProperty("defaultOnDspPresetKey")] public string DefaultOnDspPresetKey { get; set; } /// /// Gets or sets the DefaultOffDspPresetKey /// [JsonProperty("defaultOffDspPresetKey")] public string DefaultOffDspPresetKey { get; set; } /// /// Gets or sets the SourceListKey /// /// [JsonProperty("sourceListKey")] public string SourceListKey { get; set; } /// /// Gets or sets the DestinationListKey /// [JsonProperty("destinationListKey")] public string DestinationListKey { get; set; } /// /// Gets or sets the AudioControlPointListKey /// [JsonProperty("audioControlPointListKey")] public string AudioControlPointListKey { get; set; } /// /// Gets or sets the CameraListKey /// [JsonProperty("cameraListKey")] public string CameraListKey { get; set; } /// /// Gets or sets the DefaultSourceItem /// [JsonProperty("defaultSourceItem")] public string DefaultSourceItem { get; set; } /// /// Indicates if the room supports advanced sharing /// [JsonProperty("supportsAdvancedSharing")] public bool SupportsAdvancedSharing { get; set; } /// /// Indicates if non-tech users can change the share mode /// [JsonProperty("userCanChangeShareMode")] public bool UserCanChangeShareMode { get; set; } /// /// Gets or sets the MatrixRoutingKey /// [JsonProperty("matrixRoutingKey", NullValueHandling = NullValueHandling.Ignore)] public string MatrixRoutingKey { get; set; } } /// /// Represents a EssentialsConferenceRoomPropertiesConfig /// public class EssentialsConferenceRoomPropertiesConfig : EssentialsAvRoomPropertiesConfig { /// /// Gets or sets the VideoCodecKey /// [JsonProperty("videoCodecKey")] public string VideoCodecKey { get; set; } /// /// Gets or sets the AudioCodecKey /// [JsonProperty("audioCodecKey")] public string AudioCodecKey { get; set; } } /// /// Represents a EssentialsEnvironmentPropertiesConfig /// public class EssentialsEnvironmentPropertiesConfig { /// /// Gets or sets the Enabled /// public bool Enabled { get; set; } /// /// Gets or sets the DeviceKeys /// [JsonProperty("deviceKeys")] public List DeviceKeys { get; set; } /// /// Constructor /// public EssentialsEnvironmentPropertiesConfig() { DeviceKeys = new List(); } } /// /// Represents a EssentialsRoomFusionConfig /// public class EssentialsRoomFusionConfig { /// /// Gets the the IpId as a UInt16 /// public uint IpIdInt { get { try { return Convert.ToUInt32(IpId, 16); } catch (Exception) { throw new FormatException(string.Format("ERROR:Unable to convert IP ID: {0} to hex. Error:\n{1}", IpId)); } } } /// /// Gets or sets the IpId /// [JsonProperty("ipId")] public string IpId { get; set; } /// /// Gets or sets the JoinMapKey /// [JsonProperty("joinMapKey")] public string JoinMapKey { get; set; } } /// /// Represents a EssentialsRoomMicrophonePrivacyConfig /// public class EssentialsRoomMicrophonePrivacyConfig { /// /// Gets or sets the DeviceKey /// [JsonProperty("deviceKey")] public string DeviceKey { get; set; } /// /// Gets or sets the Behaviour /// [JsonProperty("behaviour")] public string Behaviour { get; set; } } /// /// Represents a EssentialsHelpPropertiesConfig /// public class EssentialsHelpPropertiesConfig { /// /// Gets or sets the Message /// [JsonProperty("message")] public string Message { get; set; } /// /// Gets or sets the ShowCallButton /// [JsonProperty("showCallButton")] public bool ShowCallButton { get; set; } /// /// Defaults to "Call Help Desk" /// [JsonProperty("callButtonText")] public string CallButtonText { get; set; } /// /// Constructor /// public EssentialsHelpPropertiesConfig() { CallButtonText = "Call Help Desk"; } } /// /// Represents a EssentialsOneButtonMeetingPropertiesConfig /// public class EssentialsOneButtonMeetingPropertiesConfig { /// /// Gets or sets the Enable /// [JsonProperty("enable")] public bool Enable { get; set; } } /// /// Represents a EssentialsRoomAddressPropertiesConfig /// public class EssentialsRoomAddressPropertiesConfig { /// /// Gets or sets the PhoneNumber /// [JsonProperty("phoneNumber")] public string PhoneNumber { get; set; } /// /// Gets or sets the SipAddress /// [JsonProperty("sipAddress")] public string SipAddress { get; set; } } /// /// Represents a EssentialsLogoPropertiesConfig /// public class EssentialsLogoPropertiesConfig { /// /// Gets or sets the Type /// [JsonProperty("type")] public string Type { get; set; } /// /// Gets or sets the Url /// [JsonProperty("url")] public string Url { get; set; } /// /// GetLogoUrlLight method /// public string GetLogoUrlLight() { if (Type == "url") return Url; if (Type == "system") return string.Format("http://{0}:8080/logo.png", CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)); return null; } /// /// GetLogoUrlDark method /// public string GetLogoUrlDark() { if (Type == "url") return Url; if (Type == "system") return string.Format("http://{0}:8080/logo-dark.png", CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)); return null; } } /// /// Represents a EssentialsRoomOccSensorConfig /// public class EssentialsRoomOccSensorConfig { /// /// Gets or sets the DeviceKey /// [JsonProperty("deviceKey")] public string DeviceKey { get; set; } /// /// Gets or sets the TimeoutMinutes /// [JsonProperty("timeoutMinutes")] public int TimeoutMinutes { get; set; } } /// /// Represents a EssentialsRoomTechConfig /// public class EssentialsRoomTechConfig { /// /// Gets or sets the Password /// [JsonProperty("password")] public string Password { get; set; } } }