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 { [JsonProperty("addresses")] public EssentialsRoomAddressPropertiesConfig Addresses { get; set; } [JsonProperty("description")] public string Description { get; set; } [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")] /// /// Gets or sets the IsRoomCombinationScenario /// public bool IsRoomCombinationScenario { get; set; } public EssentialsRoomPropertiesConfig() { LogoLight = new EssentialsLogoPropertiesConfig(); LogoDark = new EssentialsLogoPropertiesConfig(); } } /// /// Represents a EssentialsRoomUiBehaviorConfig /// public class EssentialsRoomUiBehaviorConfig { [JsonProperty("disableActivityButtonsWhileWarmingCooling")] /// /// Gets or sets the DisableActivityButtonsWhileWarmingCooling /// public bool DisableActivityButtonsWhileWarmingCooling { get; set; } } /// /// Represents a EssentialsAvRoomPropertiesConfig /// public class EssentialsAvRoomPropertiesConfig : EssentialsRoomPropertiesConfig { [JsonProperty("defaultAudioKey")] /// /// Gets or sets the DefaultAudioKey /// public string DefaultAudioKey { get; set; } [JsonProperty("sourceListKey")] /// /// Gets or sets the SourceListKey /// public string SourceListKey { get; set; } [JsonProperty("destinationListKey")] /// /// Gets or sets the DestinationListKey /// public string DestinationListKey { get; set; } [JsonProperty("audioControlPointListKey")] /// /// Gets or sets the AudioControlPointListKey /// public string AudioControlPointListKey { get; set; } [JsonProperty("cameraListKey")] /// /// Gets or sets the CameraListKey /// public string CameraListKey { get; set; } [JsonProperty("defaultSourceItem")] /// /// Gets or sets the DefaultSourceItem /// public string DefaultSourceItem { get; set; } /// /// Indicates if the room supports advanced sharing /// [JsonProperty("supportsAdvancedSharing")] /// /// Gets or sets the SupportsAdvancedSharing /// public bool SupportsAdvancedSharing { get; set; } /// /// Indicates if non-tech users can change the share mode /// [JsonProperty("userCanChangeShareMode")] /// /// Gets or sets the UserCanChangeShareMode /// public bool UserCanChangeShareMode { get; set; } [JsonProperty("matrixRoutingKey", NullValueHandling = NullValueHandling.Ignore)] /// /// Gets or sets the MatrixRoutingKey /// public string MatrixRoutingKey { get; set; } } public class EssentialsConferenceRoomPropertiesConfig : EssentialsAvRoomPropertiesConfig { [JsonProperty("videoCodecKey")] /// /// Gets or sets the VideoCodecKey /// public string VideoCodecKey { get; set; } [JsonProperty("audioCodecKey")] /// /// Gets or sets the AudioCodecKey /// public string AudioCodecKey { get; set; } } /// /// Represents a EssentialsEnvironmentPropertiesConfig /// public class EssentialsEnvironmentPropertiesConfig { /// /// Gets or sets the Enabled /// public bool Enabled { get; set; } [JsonProperty("deviceKeys")] /// /// Gets or sets the DeviceKeys /// public List DeviceKeys { get; set; } public EssentialsEnvironmentPropertiesConfig() { DeviceKeys = new List(); } } /// /// Represents a EssentialsRoomFusionConfig /// public class EssentialsRoomFusionConfig { 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)); } } } [JsonProperty("ipId")] /// /// Gets or sets the IpId /// public string IpId { get; set; } [JsonProperty("joinMapKey")] /// /// Gets or sets the JoinMapKey /// public string JoinMapKey { get; set; } } /// /// Represents a EssentialsRoomMicrophonePrivacyConfig /// public class EssentialsRoomMicrophonePrivacyConfig { [JsonProperty("deviceKey")] /// /// Gets or sets the DeviceKey /// public string DeviceKey { get; set; } [JsonProperty("behaviour")] /// /// Gets or sets the Behaviour /// public string Behaviour { get; set; } } /// /// Represents a EssentialsHelpPropertiesConfig /// public class EssentialsHelpPropertiesConfig { [JsonProperty("message")] /// /// Gets or sets the Message /// public string Message { get; set; } [JsonProperty("showCallButton")] public bool ShowCallButton { get; set; } /// /// Defaults to "Call Help Desk" /// [JsonProperty("callButtonText")] /// /// Gets or sets the CallButtonText /// public string CallButtonText { get; set; } public EssentialsHelpPropertiesConfig() { CallButtonText = "Call Help Desk"; } } /// /// Represents a EssentialsOneButtonMeetingPropertiesConfig /// public class EssentialsOneButtonMeetingPropertiesConfig { [JsonProperty("enable")] /// /// Gets or sets the Enable /// public bool Enable { get; set; } } public class EssentialsRoomAddressPropertiesConfig { [JsonProperty("phoneNumber")] public string PhoneNumber { get; set; } [JsonProperty("sipAddress")] /// /// Gets or sets the SipAddress /// public string SipAddress { get; set; } } /// /// Represents a EssentialsLogoPropertiesConfig /// public class EssentialsLogoPropertiesConfig { [JsonProperty("type")] /// /// Gets or sets the Type /// public string Type { get; set; } [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 { [JsonProperty("deviceKey")] /// /// Gets or sets the DeviceKey /// public string DeviceKey { get; set; } [JsonProperty("timeoutMinutes")] public int TimeoutMinutes { get; set; } } public class EssentialsRoomTechConfig { [JsonProperty("password")] /// /// Gets or sets the Password /// public string Password { get; set; } } }