PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/sipsorcery-core/SIPSorcery.AppServer.DialPlan/DialPlanApps/GoogleVoiceUserAgent.cs

https://github.com/thecc4re/sipsorcery-mono
C# | 119 lines | 75 code | 12 blank | 32 comment | 2 complexity | a9c172f35f5dcc5868d3ee2a1aff450c MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //-----------------------------------------------------------------------------
  2. // Filename: GoogleVoiceUserAgent.cs
  3. //
  4. // Description: A wrapper for the Google Voice call application to allow it to
  5. // work the same way as a standard SIP call and be used in dial strings.
  6. //
  7. // History:
  8. // 22 Jan 2011 Aaron Clauson Created.
  9. //
  10. // License:
  11. // This software is licensed under the BSD License http://www.opensource.org/licenses/bsd-license.php
  12. //
  13. // Copyright (c) 2011 Aaron Clauson (aaron@sipsorcery.com), SIP Sorcery Ltd, Hobart (www.sipsorcery.com)
  14. // All rights reserved.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that
  17. // the following conditions are met:
  18. //
  19. // Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  20. // Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  21. // disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of SIP Sorcery Ltd.
  22. // nor the names of its contributors may be used to endorse or promote products derived from this software without specific
  23. // prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  26. // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  27. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  28. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  29. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. // POSSIBILITY OF SUCH DAMAGE.
  32. //-----------------------------------------------------------------------------
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Text;
  37. using SIPSorcery.SIP;
  38. using SIPSorcery.SIP.App;
  39. using SIPSorcery.Sys;
  40. using log4net;
  41. namespace SIPSorcery.AppServer.DialPlan
  42. {
  43. public class GoogleVoiceUserAgent : ISIPClientUserAgent
  44. {
  45. private const int MAX_CALLBACK_WAIT_TIME = 60; // The maximum time that the callback will be waited for. Generally the call would be cancelled before this anyway.
  46. private static ILog logger = AppState.logger;
  47. public string Owner { get; set ;}
  48. public string AdminMemberId { get; set; }
  49. public UACInviteTransaction ServerTransaction { get; set; }
  50. public SIPDialogue SIPDialogue { get; set; }
  51. public SIPCallDescriptor CallDescriptor { get; set; }
  52. public bool IsUACAnswered { get; set; }
  53. public event SIPCallResponseDelegate CallTrying;
  54. public event SIPCallResponseDelegate CallRinging;
  55. public event SIPCallResponseDelegate CallAnswered;
  56. public event SIPCallFailedDelegate CallFailed;
  57. private GoogleVoiceCall m_googleVoiceCall;
  58. public GoogleVoiceUserAgent(
  59. SIPTransport sipTransport,
  60. ISIPCallManager callManager,
  61. SIPMonitorLogDelegate logDelegate,
  62. string username,
  63. string adminMemberId,
  64. SIPEndPoint outboundProxy)
  65. {
  66. Owner = username;
  67. AdminMemberId = adminMemberId;
  68. m_googleVoiceCall = new GoogleVoiceCall(sipTransport, callManager, logDelegate, username, adminMemberId, outboundProxy);
  69. m_googleVoiceCall.CallProgress += new CallProgressDelegate(CallProgress);
  70. }
  71. private void CallProgress(SIPResponseStatusCodesEnum progressStatus, string reasonPhrase, string[] customHeaders, string progressContentType, string progressBody, ISIPClientUserAgent uac)
  72. {
  73. SIPResponse progressResponse = new SIPResponse(progressStatus, reasonPhrase, null);
  74. CallRinging(this, progressResponse);
  75. }
  76. public void Call(SIPCallDescriptor descriptor)
  77. {
  78. try
  79. {
  80. CallDescriptor = descriptor;
  81. SIPURI destinationURI = SIPURI.ParseSIPURIRelaxed(descriptor.Uri);
  82. SIPDialogue = m_googleVoiceCall.InitiateCall(descriptor.Username, descriptor.Password, descriptor.CallbackNumber, destinationURI.User, descriptor.CallbackPattern, descriptor.CallbackPhoneType, MAX_CALLBACK_WAIT_TIME, descriptor.ContentType, descriptor.Content);
  83. if (SIPDialogue != null)
  84. {
  85. CallAnswered(this, null);
  86. }
  87. else
  88. {
  89. CallFailed(this, "Google Voice call failed.");
  90. }
  91. }
  92. catch (Exception excp)
  93. {
  94. logger.Error("Exception GoogleVoiceCallAgent Call. " + excp.Message);
  95. CallFailed(this, excp.Message);
  96. }
  97. }
  98. public void Cancel()
  99. {
  100. m_googleVoiceCall.ClientCallTerminated(CallCancelCause.Unknown);
  101. }
  102. public void Update(CRMHeaders crmHeaders)
  103. {
  104. throw new NotImplementedException();
  105. }
  106. }
  107. }