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 Ddvc01VtcMessenger : MessengerBase { BasicTriList EISC; /********* Bools *********/ /// /// 724 /// const uint BDialHangup = 724; /// /// 750 /// const uint BCallIncoming = 750; /// /// 751 /// const uint BIncomingAnswer = 751; /// /// 752 /// const uint BIncomingReject = 752; /// /// 741 /// const uint BSpeedDial1 = 741; /// /// 742 /// const uint BSpeedDial2 = 742; /// /// 743 /// const uint BSpeedDial3 = 743; /// /// 744 /// const uint BSpeedDial4 = 744; /// /// 800 /// const uint BDirectorySearchBusy = 800; /// /// 801 when selected entry is a contact /// const uint BDirectoryEntryIsContact = 801; /// /// 802 To show/hide back button /// const uint BDirectoryIsAtTop = 802; /// /// 811 /// const uint BCameraControlUp = 811; /// /// 812 /// const uint BCameraControlDown = 812; /// /// 813 /// const uint BCameraControlLeft = 813; /// /// 814 /// const uint BCameraControlRight = 814; /// /// 815 /// const uint BCameraControlZoomIn = 815; /// /// 816 /// const uint BCameraControlZoomOut = 816; /// /// 821 - 826 /// const uint BCameraPresetStart = 821; /********* Ushorts *********/ /// /// 801 /// const uint UDirectorySelectRow = 801; /// /// 801 /// const uint UDirectoryRowCount = 801; /********* Strings *********/ /// /// 701 /// const uint SCurrentDialString = 701; /// /// 711 /// const uint SCurrentCallNumber = 711; /// /// 712 /// const uint SCurrentCallName = 712; /// /// 731 /// const uint SHookState = 731; /// /// 722 /// const uint SCallDirection = 722; /// /// 751 /// const uint SIncomingCallName = 751; /// /// 752 /// const uint SIncomingCallNumber = 752; /// /// 800 /// const uint SDirectorySearchString = 800; /// /// 801-1055 /// const uint SDirectoryEntriesStart = 801; /// /// 1056 /// const uint SDirectoryEntrySelectedName = 1056; /// /// 1057 /// const uint SDirectoryEntrySelectedNumber = 1057; /// /// 701-712 0-9*# /// Dictionary DTMFMap = new Dictionary { { "1", 701 }, { "2", 702 }, { "3", 703 }, { "4", 704 }, { "5", 705 }, { "6", 706 }, { "7", 707 }, { "8", 708 }, { "9", 709 }, { "0", 710 }, { "*", 711 }, { "#", 712 }, }; CodecActiveCallItem CurrentCallItem; CodecActiveCallItem IncomingCallItem; /// /// /// /// /// public Ddvc01VtcMessenger(string key, BasicTriList eisc, string messagePath) : base(key, messagePath) { EISC = eisc; CurrentCallItem = new CodecActiveCallItem(); CurrentCallItem.Type = eCodecCallType.Video; CurrentCallItem.Id = "-video-"; } /// /// /// 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(SHookState, s => { CurrentCallItem.Status = (eCodecCallStatus)Enum.Parse(typeof(eCodecCallStatus), s, true); SendCallsList(); }); 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(); }); EISC.SetBoolSigAction(BCallIncoming, b => { if (b) { var ica = new CodecActiveCallItem() { Direction = eCodecCallDirection.Incoming, Id = "-video-incoming", Name = EISC.GetString(SIncomingCallName), Number = EISC.GetString(SIncomingCallNumber), Status = eCodecCallStatus.Ringing, Type = eCodecCallType.Video }; IncomingCallItem = ica; } else { IncomingCallItem = null; } SendCallsList(); }); // Add press and holds using helper action Action addPHAction = (s, u) => AppServerController.AddAction(MessagePath + s, new PressAndHoldAction(b => EISC.SetBool(u, b))); addPHAction("/cameraUp", BCameraControlUp); addPHAction("/cameraDown", BCameraControlDown); addPHAction("/cameraLeft", BCameraControlLeft); addPHAction("/cameraRight", BCameraControlRight); addPHAction("/cameraZoomIn", BCameraControlZoomIn); addPHAction("/cameraZoonOut", BCameraControlZoomOut); // Add straight pulse calls using helper action Action addAction = (s, u) => AppServerController.AddAction(MessagePath + s, new Action(() => EISC.PulseBool(u, 100))); addAction("/endCallById", BDialHangup); addAction("/acceptById", BIncomingAnswer); addAction("/rejectById", BIncomingReject); addAction("/speedDial1", BSpeedDial1); addAction("/speedDial2", BSpeedDial2); addAction("/speedDial3", BSpeedDial3); addAction("/speedDial4", BSpeedDial4); for(uint i = 0; i < 6; i++) { addAction("/cameraPreset" + (i + 1), BCameraPresetStart + i); } // 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() { var list = new List(); if (CurrentCallItem.Status != eCodecCallStatus.Disconnected) { list.Add(CurrentCallItem); } if (EISC.GetBool(BCallIncoming)) { } return list; } } }