internal CodecResponse SendCommand(CodecCommand command)
        {
            var xml = command.XmlString;

#if DEBUG
            Debug.WriteInfo("Sending command", "{0}", command.Command);
#endif
            return(_httpsClient.PutXml(xml));
        }
Beispiel #2
0
        public void Join(IEnumerable <Call> calls)
        {
            var cmd = new CodecCommand("Call", "Join");

            foreach (var call in calls)
            {
                cmd.Args.Add("CallId", call.Id);
            }
            var response = _codec.SendCommand(cmd);

#if DEBUG
            Debug.WriteInfo(response.Xml.Element("Command").ToString());
#endif
        }
Beispiel #3
0
        public void UnattendedTranser(string number)
        {
            var cmd = new CodecCommand("Call", "UnattendedTranser");

            cmd.Args.Add("CallId", Id);
            cmd.Args.Add("Number", number);
            Codec.SendCommandAsync(cmd, (id, ok, result) =>
            {
                if (!ok)
                {
                    CloudLog.Error("Call.UnattendedTranser method returned error");
                }
            });
        }
        internal int SendCommandAsync(CodecCommand command, CodecCommandResponse callback)
        {
            var xml = command.XmlString;

#if DEBUG
            CrestronConsole.PrintLine("Command: ({0} bytes)\r\n{1}", xml.Length, xml);
#endif
            var id = _httpsClient.PutXmlAsync(xml, response =>
            {
#if DEBUG
                CrestronConsole.PrintLine("Command response received with id:{0}", response.Request.Id);
#endif
                var call = _commandCallbacks[response.Request.Id];

                _commandCallbacksLock.Enter();
                _commandCallbacks.Remove(response.Request.Id);
                _commandCallbacksLock.Leave();
                if (response.Code == 200 && response.Xml != null)
                {
                    try
                    {
                        var result = response.Xml.Element("Command").Elements().First();
#if DEBUG
                        CrestronConsole.PrintLine("Request {0} {1} = {2}", response.Request.Id, result.XName.LocalName,
                                                  result.Attribute("status").Value);
#endif
                        call(response.Request.Id, result.Attribute("status").Value == "OK", result);
                        return;
                    }
                    catch (Exception e)
                    {
                        CloudLog.Exception(e);
                    }
                }
                else if (response.Code == 401)
                {
                    CloudLog.Warn(
                        "Received 401 code in {0}.SendCommandAsync(CodecCommand command, CodecCommandResponse callback)",
                        GetType().Name);
                }
                call(response.Request.Id, false, null);
            });
            _commandCallbacksLock.Enter();
            _commandCallbacks[id] = callback;
            _commandCallbacksLock.Leave();
#if DEBUG
            CrestronConsole.PrintLine("Sending command \"{0}\" with id:{1}", command.Command, id);
#endif
            return(id);
        }
Beispiel #5
0
        public void Forward(string displayName, string number)
        {
            var cmd = new CodecCommand("Call", "Forward");

            cmd.Args.Add("CallId", Id);
            cmd.Args.Add("DisplayName", displayName);
            cmd.Args.Add("Number", number);
            Codec.SendCommandAsync(cmd, (id, ok, result) =>
            {
                if (!ok)
                {
                    CloudLog.Error("Call.Forward method returned error");
                }
            });
        }
Beispiel #6
0
        internal void Dial(string number, CodecCommandArg[] args, DialResult callback)
        {
#if DEBUG
            Debug.WriteInfo("Codec Dial", "Checking Capabilities");
            Debug.WriteInfo("  MaxCalls", "{0}", _codec.Capabilities.Conference.MaxCalls);
            Debug.WriteInfo("  MaxActiveCalls", "{0}", _codec.Capabilities.Conference.MaxActiveCalls);
            Debug.WriteInfo("  MaxAudioCalls", "{0}", _codec.Capabilities.Conference.MaxAudioCalls);
            Debug.WriteInfo("  MaxVideoCalls", "{0}", _codec.Capabilities.Conference.MaxVideoCalls);
            Debug.WriteInfo("  NumberOfActiveCalls", "{0}", _codec.SystemUnit.State.NumberOfActiveCalls);
            Debug.WriteInfo("  NumberOfSuspendedCalls", "{0}", _codec.SystemUnit.State.NumberOfSuspendedCalls);
            Debug.WriteInfo("  TotalNumberOfCalls", "{0}", _codec.SystemUnit.State.TotalNumberOfCalls);
#endif
            var numberOfConnectedVideoCalls = this.Count(c => c.Connected && c.CallType == CallType.Video);
            var shouldHoldACall             = (_codec.SystemUnit.State.NumberOfActiveCalls > 0 &&
                                               _codec.SystemUnit.State.NumberOfActiveCalls ==
                                               _codec.Capabilities.Conference.MaxActiveCalls) ||
                                              (numberOfConnectedVideoCalls > 0 && numberOfConnectedVideoCalls ==
                                               _codec.Capabilities.Conference.MaxVideoCalls);

            if (shouldHoldACall)
            {
#if DEBUG
                Debug.WriteWarn("Codec needs to hold another call before calling!");
#endif
                try
                {
                    var lastConnectedCall = _codec.Calls.LastOrDefault(c => c.Connected);
                    if (lastConnectedCall != null)
                    {
                        lastConnectedCall.Hold();
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e);
                }
            }

            var cmd = new CodecCommand("", "Dial");
            cmd.Args.Add("Number", number);
            cmd.Args.Add(args);
            var requestId = _codec.SendCommandAsync(cmd, (id, ok, result) =>
            {
                var callBackInfo = _dialCallbacks[id];

                _dialCallbacksLock.Enter();
                _dialCallbacks.Remove(id);
                _dialCallbacksLock.Leave();

                Debug.WriteInfo("Dial Result Callback", "Request {0}, OK = {1}\r\n{2}", id, ok, result);

                if (ok)
                {
                    var callId = int.Parse(result.Element("CallId").Value);
                    Debug.WriteSuccess("Dial Result OK, call {0}", callId);
                    callBackInfo.CallBack(0, "OK", callId);
                    return;
                }

                try
                {
                    var cause   = int.Parse(result.Element("Cause").Value);
                    var message = result.Element("Description").Value;
                    Debug.WriteError("Dial Failed, Error {0} - {1}", cause, message);
                    callBackInfo.CallBack(cause, message, 0);
                }
                catch
                {
                    Debug.WriteError("Dial Result",
                                     result != null ? result.ToString(SaveOptions.DisableFormatting) : "Unknown Error");
                }
            });

            var info = new DialCallBackInfo()
            {
                NumberDialed = number,
                CallBack     = callback
            };

            _dialCallbacksLock.Enter();
            _dialCallbacks[requestId] = info;
            _dialCallbacksLock.Leave();
        }