예제 #1
0
파일: Program.cs 프로젝트: Binauric/opal
    static void HandleMessages(uint timeout)
    {
      OpalMessageRef command = new OpalMessageRef();
      OpalMessageRef response;
      OpalMessageRef message = new OpalMessageRef();

      while (context.GetMessage(message, timeout))
      {
        switch (message.GetMessageType())
        {
          case Opal_API.OpalMessageType.OpalIndRegistration:
            OpalStatusRegistrationRef m_param = message.GetRegistrationStatus();

            switch (m_param.Status)
            {
              case Opal_API.OpalRegistrationStates.OpalRegisterRetrying:
                Console.WriteLine("Trying registration to {0}.", m_param.ServerName);
                break;
              case Opal_API.OpalRegistrationStates.OpalRegisterRestored:
                Console.WriteLine("Registration of {0} restored.",m_param.ServerName);
                break;
              case Opal_API.OpalRegistrationStates.OpalRegisterSuccessful:
                Console.WriteLine("Registration of {0} successful.", m_param.ServerName);
                break;
              case Opal_API.OpalRegistrationStates.OpalRegisterRemoved:
                Console.WriteLine("Unregistered {0}.", m_param.ServerName);
                break;
              case Opal_API.OpalRegistrationStates.OpalRegisterFailed:
                if (m_param.Error == null || m_param.Error.Length == 0)
                  Console.WriteLine("Registration of {0} failed.", m_param.ServerName);
                else
                  Console.WriteLine("Registration of {0} error: {1}",m_param.ServerName, m_param.Error);
                break;
            }
            break;

          case Opal_API.OpalMessageType.OpalIndLineAppearance:
            OpalStatusLineAppearanceRef m_lineStatus = message.GetLineAppearance();
            switch (m_lineStatus.State)
            {
              case Opal_API.OpalLineAppearanceStates.OpalLineIdle:
                Console.WriteLine("Line {0} available.", m_lineStatus.Line);
                break;
              case Opal_API.OpalLineAppearanceStates.OpalLineTrying:
                Console.WriteLine("Line {0} in use.", m_lineStatus.Line);
                break;
              case Opal_API.OpalLineAppearanceStates.OpalLineProceeding:
                Console.WriteLine("Line {0} calling.", m_lineStatus.Line);
                break;
              case Opal_API.OpalLineAppearanceStates.OpalLineRinging:
                Console.WriteLine("Line {0} ringing.", m_lineStatus.Line);
                break;
              case Opal_API.OpalLineAppearanceStates.OpalLineConnected:
                Console.WriteLine("Line {0} connected.", m_lineStatus.Line);
                break;
              case Opal_API.OpalLineAppearanceStates.OpalLineSubcribed:
                Console.WriteLine("Line {0} subscription successful.", m_lineStatus.Line);
                break;
              case Opal_API.OpalLineAppearanceStates.OpalLineUnsubcribed:
                Console.WriteLine("Unsubscribed line {0}.", m_lineStatus.Line);
                break;
            }
            break;

          case Opal_API.OpalMessageType.OpalIndIncomingCall:
            OpalStatusIncomingCallRef incomingCall = message.GetIncomingCall();

            Console.WriteLine("Incoming call from \"{0}\", \"{1}\" to \"{2}\", handled by \"{3}\".",
                   incomingCall.RemoteDisplayName,
                   incomingCall.RemoteAddress,
                   incomingCall.CalledAddress,
                   incomingCall.LocalAddress);
            if (currentCallToken == null)
            {
              command = new OpalMessageRef(Opal_API.OpalMessageType.OpalCmdAnswerCall);
              OpalParamAnswerCallRef answerCall = command.GetAnswerCall();
              answerCall.CallToken = incomingCall.CallToken;
              OpalParamProtocolRef overrides = new OpalParamProtocolRef(answerCall.Overrides);              
              overrides.UserName = "******";
              overrides.DisplayName = "Test Called Party";
              answerCall.Overrides = overrides.Param;

              MySendCommand(command, "Could not answer call");              
            }
            else
            {
              command = new OpalMessageRef(Opal_API.OpalMessageType.OpalCmdClearCall);
              OpalParamCallClearedRef clearCall = command.GetClearCall();
              OpalStatusIncomingCallRef m_incomingCall = message.GetIncomingCall();
              clearCall.CallToken = m_incomingCall.CallToken;
              clearCall.Reason = Opal_API.OpalCallEndReason.OpalCallEndedByLocalBusy;
              MySendCommand(command, "Could not refuse call");                
            }
            break;

          case Opal_API.OpalMessageType.OpalIndProceeding:
            Console.WriteLine("Proceeding.");
            break;

          case Opal_API.OpalMessageType.OpalIndAlerting:
            Console.WriteLine("Ringing.");
            break;

          case Opal_API.OpalMessageType.OpalIndEstablished:
            Console.WriteLine("Established.");

            if (playScript != null)
            {
              Console.WriteLine("Playing {0}", playScript);

              command = new OpalMessageRef(Opal_API.OpalMessageType.OpalCmdTransferCall);
              OpalParamSetUpCallRef m_callSetUp = command.GetCallSetUp();
              m_callSetUp.CallToken = currentCallToken;
              m_callSetUp.PartyA = "pc:";
              m_callSetUp.PartyB = playScript;
              MySendCommand(command, "Could not start playing");               
            }
            break;

          case Opal_API.OpalMessageType.OpalIndMediaStream:
            OpalStatusMediaStreamRef m_mediaStream = message.GetMediaStream();
            Console.WriteLine("Media stream {0} {1} using {2}.", m_mediaStream.Type, 
              m_mediaStream.State == Opal_API.OpalMediaStates.OpalMediaStateOpen ? "opened" : "closed",
              m_mediaStream.Format);
            break;

          case Opal_API.OpalMessageType.OpalIndUserInput:
            OpalStatusUserInputRef m_userInput = message.GetUserInput();
            Console.WriteLine("User Input: {0}.", m_userInput.UserInput);
            break;

          case Opal_API.OpalMessageType.OpalIndCallCleared:
            OpalStatusCallClearedRef m_callCleared = message.GetCallCleared();
            if (m_callCleared.Reason == null)
              Console.WriteLine("Call cleared.");
            else
              Console.WriteLine("Call cleared: {0}", m_callCleared.Reason);
            break;

          default:
            break;
        }        
      }
    }