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 Ddvc01AtcMessenger : MessengerBase { BasicTriList EISC; /// /// 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 Ddvc01AtcMessenger(string key, BasicTriList eisc, string messagePath) : base(key, messagePath) { EISC = eisc; CurrentCallItem = new CodecActiveCallItem(); CurrentCallItem.Type = eCodecCallType.Audio; CurrentCallItem.Id = "-audio-"; } /// /// /// void SendFullStatus() { this.PostStatusMessage(new { calls = GetCurrentCallList(), currentCallString = EISC.GetString(SCurrentCallNumber), currentDialString = EISC.GetString(SCurrentDialString), isInCall = EISC.GetString(SHookState) == "Connected" }); } /// /// /// /// protected override void CustomRegisterWithAppServer(CotijaSystemController appServerController) { //EISC.SetStringSigAction(SCurrentDialString, s => PostStatusMessage(new { currentDialString = s })); EISC.SetStringSigAction(SHookState, s => { CurrentCallItem.Status = (eCodecCallStatus)Enum.Parse(typeof(eCodecCallStatus), s, true); //GetCurrentCallList(); SendFullStatus(); }); EISC.SetStringSigAction(SCurrentCallNumber, s => { CurrentCallItem.Number = s; SendCallsList(); }); EISC.SetStringSigAction(SCurrentCallName, s => { CurrentCallItem.Name = s; SendCallsList(); }); EISC.SetStringSigAction(SCallDirection, 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", BDialHangupOnHook); addAction("/endAllCalls", BDialHangupOnHook); addAction("/acceptById", BIncomingAnswer); addAction("/rejectById", BIncomingReject); addAction("/speedDial1", BSpeedDial1); addAction("/speedDial2", BSpeedDial2); addAction("/speedDial3", BSpeedDial3); addAction("/speedDial4", BSpeedDial4); // Get status AppServerController.AddAction(MessagePath + "/fullStatus", new Action(SendFullStatus)); // Dial on string AppServerController.AddAction(MessagePath + "/dial", new Action(s => EISC.SetString(SCurrentDialString, s))); // Pulse DTMF AppServerController.AddAction(MessagePath + "/dtmf", new Action(s => { if (DTMFMap.ContainsKey(s)) { EISC.PulseBool(DTMFMap[s], 100); } })); } /// /// /// void SendCallsList() { PostStatusMessage(new { calls = GetCurrentCallList(), }); } /// /// Turns the /// /// List GetCurrentCallList() { if (CurrentCallItem.Status == eCodecCallStatus.Disconnected) { return new List(); } else { return new List() { CurrentCallItem }; } } } }