sipsorcery-mono /sipsorcery-core/SIPSorcery.Web.Services/CallManager/CallManagerServices.cs

Language C# Lines 119
MD5 Hash 129ec5e5b4f13d2e7a664f3d69b3de1e
Repository https://github.com/thecc4re/sipsorcery-mono.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SIPSorcery.SIP.App;
using SIPSorcery.Sys;
using log4net;

namespace SIPSorcery.Web.Services
{
    public class CallManagerServices : ICallManagerServices
    {
        public const string WEB_CALLBACK_DIALPLAN_NAME = "webcallback";
        public const string WEB_TRANSFER_DIALPLAN_NAME = "transfer";

        private static ILog logger = AppState.logger;

        private ISIPCallManager m_sipCallManager;
        private ISIPDialogueManager m_sipDialogueManager;

        public CallManagerServices() { }

        public CallManagerServices(ISIPCallManager sipCallManager, ISIPDialogueManager sipDialogueManager)
        {
            m_sipCallManager = sipCallManager;
            m_sipDialogueManager = sipDialogueManager;
        }

        public bool IsAlive()
        {
            return true;
        }

        public string WebCallback(string username, string number)
        {
            try
            {
                logger.Debug("CallManagerServices webcallback, username=" + username + ", number=" + number + ".");

                if (username.IsNullOrBlank())
                {
                    return "A username must be specified when initiating a web callback, the callback was not initiated.";
                }
                else
                {
                    return m_sipCallManager.ProcessWebCall(username, number, WEB_CALLBACK_DIALPLAN_NAME, null);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception WebCallback. " + excp.Message);
                throw;
            }
        }

        public string BlindTransfer(string username, string destination, string replacesCallID)
        {
            try
            {
                logger.Debug("CallManagerServices BlindTransfer, user=" + username + ", destination=" + destination + ", callID=" + replacesCallID + ".");

                string transferResult = null;

                if (username.IsNullOrBlank())
                {
                    transferResult = "A username must be specified when initiating a blind transfer, the transfer was not initiated.";
                }
                else if (replacesCallID.IsNullOrBlank())
                {
                    transferResult = "Blind transfer requires a Call-ID to replace, the transfer was not initiated.";
                }
                else
                {
                    transferResult = m_sipCallManager.ProcessWebCall(username, destination, WEB_TRANSFER_DIALPLAN_NAME, replacesCallID);
                }

                logger.Debug("BlindTransfer result=" + transferResult + ".");

                return transferResult;
            }
            catch (Exception excp)
            {
                logger.Error("Exception BlindTransfer. " + excp.Message);
                throw;
            }
        }

        /// <summary>
        /// An attended transfer between two separate established calls where one leg of each call is being transferred 
        /// to the other.
        /// </summary>
        /// <param name="callID1">The Call-ID of the first call leg that is no longer required and of which the opposite end will be transferred.</param>
        /// <param name="callID2">The Call-ID of the second call leg that is no longer required and of which the opposite end will be transferred. If 
        /// left empty then the transfer will default to using the last call that was received.</param>
        /// <returns>If successful null otherwise a string with an error message.</returns>
        public string DualTransfer(string username, string callID1, string callID2)
        {
            try
            {
                logger.Debug("CallManagerServices DualTransfer, Username=" + username + ", CallID1=" + callID1 + ", CallID2=" + callID2 + ".");

                m_sipDialogueManager.DualTransfer(username, callID1, callID2);

                return null;
            }
            catch (ApplicationException appExcp)
            {
                logger.Warn("ApplicationException DualTransfer. " + appExcp.Message);
                return appExcp.Message;
            }
            catch (Exception excp)
            {
                logger.Error("Exception DualTransfer. " + excp.Message);
                throw;
            }
        }
    }
}
Back to Top