using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.EthernetCommunication; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Devices.Common.Codec; namespace PepperDash.Essentials.AppServer.Messengers { public class SIMPLAtcMessenger : MessengerBase { BasicTriList EISC; public SIMPLAtcJoinMap JoinMap {get; private set;} ///// ///// 221 ///// //const uint BDialHangupOnHook = 221; ///// ///// 251 ///// //const uint BIncomingAnswer = 251; ///// ///// 252 ///// //const uint BIncomingReject = 252; ///// ///// 241 ///// //const uint BSpeedDial1 = 241; ///// ///// 242 ///// //const uint BSpeedDial2 = 242; ///// ///// 243 ///// //const uint BSpeedDial3 = 243; ///// ///// 244 ///// //const uint BSpeedDial4 = 244; ///// ///// 201 ///// //const uint SCurrentDialString = 201; ///// ///// 211 ///// //const uint SCurrentCallNumber = 211; ///// ///// 212 ///// //const uint SCurrentCallName = 212; ///// ///// 221 ///// //const uint SHookState = 221; ///// ///// 222 ///// //const uint SCallDirection = 222; ///// ///// 201-212 0-9*# ///// //Dictionary DTMFMap = new Dictionary //{ // { "1", 201 }, // { "2", 202 }, // { "3", 203 }, // { "4", 204 }, // { "5", 205 }, // { "6", 206 }, // { "7", 207 }, // { "8", 208 }, // { "9", 209 }, // { "0", 210 }, // { "*", 211 }, // { "#", 212 }, //}; /// /// /// CodecActiveCallItem CurrentCallItem; /// /// /// /// /// public SIMPLAtcMessenger(string key, BasicTriList eisc, string messagePath) : base(key, messagePath) { EISC = eisc; JoinMap = new SIMPLAtcJoinMap(201); CurrentCallItem = new CodecActiveCallItem(); CurrentCallItem.Type = eCodecCallType.Audio; CurrentCallItem.Id = "-audio-"; } /// /// /// void SendFullStatus() { this.PostStatusMessage(new { calls = GetCurrentCallList(), currentCallString = EISC.GetString(JoinMap.CurrentCallName.JoinNumber), currentDialString = EISC.GetString(JoinMap.CurrentDialString.JoinNumber), isInCall = EISC.GetString(JoinMap.HookState.JoinNumber) == "Connected" }); } /// /// /// /// protected override void CustomRegisterWithAppServer(MobileControlSystemController appServerController) { //EISC.SetStringSigAction(SCurrentDialString, s => PostStatusMessage(new { currentDialString = s })); EISC.SetStringSigAction(JoinMap.HookState.JoinNumber, s => { CurrentCallItem.Status = (eCodecCallStatus)Enum.Parse(typeof(eCodecCallStatus), s, true); //GetCurrentCallList(); SendFullStatus(); }); EISC.SetStringSigAction(JoinMap.CurrentCallNumber.JoinNumber, s => { CurrentCallItem.Number = s; SendCallsList(); }); EISC.SetStringSigAction(JoinMap.CurrentCallName.JoinNumber, s => { CurrentCallItem.Name = s; SendCallsList(); }); EISC.SetStringSigAction(JoinMap.CallDirection.JoinNumber, s => { CurrentCallItem.Direction = (eCodecCallDirection)Enum.Parse(typeof(eCodecCallDirection), s, true); SendCallsList(); }); // Add press and holds using helper Action addPHAction = (s, u) => AppServerController.AddAction(MessagePath + s, new PressAndHoldAction(b => EISC.SetBool(u, b))); // Add straight pulse calls Action addAction = (s, u) => AppServerController.AddAction(MessagePath + s, new Action(() => EISC.PulseBool(u, 100))); addAction("/endCallById", JoinMap.EndCall.JoinNumber); addAction("/endAllCalls", JoinMap.EndCall.JoinNumber); addAction("/acceptById", JoinMap.IncomingAnswer.JoinNumber); addAction("/rejectById", JoinMap.IncomingReject.JoinNumber); var speeddialStart = JoinMap.SpeedDialStart.JoinNumber; var speeddialEnd = JoinMap.SpeedDialStart.JoinNumber + JoinMap.SpeedDialStart.JoinSpan; var speedDialIndex = 1; for (uint i = speeddialStart; i < speeddialEnd; i++) { addAction(string.Format("/speedDial{0}", speedDialIndex), i); speedDialIndex++; } // Get status AppServerController.AddAction(MessagePath + "/fullStatus", new Action(SendFullStatus)); // Dial on string AppServerController.AddAction(MessagePath + "/dial", new Action(s => EISC.SetString(JoinMap.CurrentDialString.JoinNumber, s))); // Pulse DTMF AppServerController.AddAction(MessagePath + "/dtmf", new Action(s => { var join = JoinMap.Joins[s]; if (join != null) { if (join.JoinNumber > 0) { EISC.PulseBool(join.JoinNumber, 100); } } })); } /// /// /// void SendCallsList() { PostStatusMessage(new { calls = GetCurrentCallList(), }); } /// /// Turns the /// /// List GetCurrentCallList() { if (CurrentCallItem.Status == eCodecCallStatus.Disconnected) { return new List(); } else { return new List() { CurrentCallItem }; } } } }