using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Essentials.Devices.Common.Codec; using PepperDash.Essentials.Devices.Common.AudioCodec; namespace PepperDash.Essentials.AppServer.Messengers { /// /// Provides a messaging bridge for an AudioCodecBase device /// public class AudioCodecBaseMessenger : MessengerBase { /// /// Device being bridged /// public AudioCodecBase Codec { get; set; } /// /// Constuctor /// /// /// /// public AudioCodecBaseMessenger(string key, AudioCodecBase codec, string messagePath) : base(key, messagePath) { if (codec == null) throw new ArgumentNullException("codec"); Codec = codec; codec.CallStatusChange += new EventHandler(codec_CallStatusChange); } protected override void CustomRegisterWithAppServer(MobileControlSystemController appServerController) { appServerController.AddAction(MessagePath + "/fullStatus", new Action(SendAtcFullMessageObject)); appServerController.AddAction(MessagePath + "/dial", new Action(s => Codec.Dial(s))); appServerController.AddAction(MessagePath + "/endCallById", new Action(s => { var call = GetCallWithId(s); if (call != null) Codec.EndCall(call); })); appServerController.AddAction(MessagePath + "/endAllCalls", new Action(Codec.EndAllCalls)); appServerController.AddAction(MessagePath + "/dtmf", new Action(s => Codec.SendDtmf(s))); appServerController.AddAction(MessagePath + "/rejectById", new Action(s => { var call = GetCallWithId(s); if (call != null) Codec.RejectCall(call); })); appServerController.AddAction(MessagePath + "/acceptById", new Action(s => { var call = GetCallWithId(s); if (call != null) Codec.AcceptCall(call); })); } /// /// Helper to grab a call with string ID /// /// /// CodecActiveCallItem GetCallWithId(string id) { return Codec.ActiveCalls.FirstOrDefault(c => c.Id == id); } void codec_CallStatusChange(object sender, CodecCallStatusItemChangeEventArgs e) { SendAtcFullMessageObject(); } /// /// Helper method to build call status for vtc /// /// void SendAtcFullMessageObject() { var info = Codec.CodecInfo; PostStatusMessage(new { isInCall = Codec.IsInCall, calls = Codec.ActiveCalls, info = new { phoneNumber = info.PhoneNumber } }); } } }