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

https://github.com/thecc4re/sipsorcery-mono · C# · 118 lines · 94 code · 16 blank · 8 comment · 4 complexity · 129ec5e5b4f13d2e7a664f3d69b3de1e MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SIPSorcery.SIP.App;
  6. using SIPSorcery.Sys;
  7. using log4net;
  8. namespace SIPSorcery.Web.Services
  9. {
  10. public class CallManagerServices : ICallManagerServices
  11. {
  12. public const string WEB_CALLBACK_DIALPLAN_NAME = "webcallback";
  13. public const string WEB_TRANSFER_DIALPLAN_NAME = "transfer";
  14. private static ILog logger = AppState.logger;
  15. private ISIPCallManager m_sipCallManager;
  16. private ISIPDialogueManager m_sipDialogueManager;
  17. public CallManagerServices() { }
  18. public CallManagerServices(ISIPCallManager sipCallManager, ISIPDialogueManager sipDialogueManager)
  19. {
  20. m_sipCallManager = sipCallManager;
  21. m_sipDialogueManager = sipDialogueManager;
  22. }
  23. public bool IsAlive()
  24. {
  25. return true;
  26. }
  27. public string WebCallback(string username, string number)
  28. {
  29. try
  30. {
  31. logger.Debug("CallManagerServices webcallback, username=" + username + ", number=" + number + ".");
  32. if (username.IsNullOrBlank())
  33. {
  34. return "A username must be specified when initiating a web callback, the callback was not initiated.";
  35. }
  36. else
  37. {
  38. return m_sipCallManager.ProcessWebCall(username, number, WEB_CALLBACK_DIALPLAN_NAME, null);
  39. }
  40. }
  41. catch (Exception excp)
  42. {
  43. logger.Error("Exception WebCallback. " + excp.Message);
  44. throw;
  45. }
  46. }
  47. public string BlindTransfer(string username, string destination, string replacesCallID)
  48. {
  49. try
  50. {
  51. logger.Debug("CallManagerServices BlindTransfer, user=" + username + ", destination=" + destination + ", callID=" + replacesCallID + ".");
  52. string transferResult = null;
  53. if (username.IsNullOrBlank())
  54. {
  55. transferResult = "A username must be specified when initiating a blind transfer, the transfer was not initiated.";
  56. }
  57. else if (replacesCallID.IsNullOrBlank())
  58. {
  59. transferResult = "Blind transfer requires a Call-ID to replace, the transfer was not initiated.";
  60. }
  61. else
  62. {
  63. transferResult = m_sipCallManager.ProcessWebCall(username, destination, WEB_TRANSFER_DIALPLAN_NAME, replacesCallID);
  64. }
  65. logger.Debug("BlindTransfer result=" + transferResult + ".");
  66. return transferResult;
  67. }
  68. catch (Exception excp)
  69. {
  70. logger.Error("Exception BlindTransfer. " + excp.Message);
  71. throw;
  72. }
  73. }
  74. /// <summary>
  75. /// An attended transfer between two separate established calls where one leg of each call is being transferred
  76. /// to the other.
  77. /// </summary>
  78. /// <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>
  79. /// <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
  80. /// left empty then the transfer will default to using the last call that was received.</param>
  81. /// <returns>If successful null otherwise a string with an error message.</returns>
  82. public string DualTransfer(string username, string callID1, string callID2)
  83. {
  84. try
  85. {
  86. logger.Debug("CallManagerServices DualTransfer, Username=" + username + ", CallID1=" + callID1 + ", CallID2=" + callID2 + ".");
  87. m_sipDialogueManager.DualTransfer(username, callID1, callID2);
  88. return null;
  89. }
  90. catch (ApplicationException appExcp)
  91. {
  92. logger.Warn("ApplicationException DualTransfer. " + appExcp.Message);
  93. return appExcp.Message;
  94. }
  95. catch (Exception excp)
  96. {
  97. logger.Error("Exception DualTransfer. " + excp.Message);
  98. throw;
  99. }
  100. }
  101. }
  102. }