Example #1
0
    static int DoCall(string from, string to)
    {
      // Example cmd line: call [email protected]
      OpalMessageRef command = new OpalMessageRef();
      OpalMessageRef response = new OpalMessageRef();

      Console.WriteLine("Calling {0}", to);
    
      command.SetMessageType(Opal_API.OpalMessageType.OpalCmdSetUpCall);
      OpalParamSetUpCallRef m_callSetUp = command.GetCallSetUp();
      m_callSetUp.PartyA = from;
      m_callSetUp.PartyB = to;

      OpalParamProtocolRef overrides = new OpalParamProtocolRef(new Opal_API.OpalParamProtocol());
      overrides.DisplayName = "Test Calling Party";
      m_callSetUp.Overrides = overrides.Param;

      if ((response = MySendCommand(command, "Could not make call")) == null)
        return 0;

      m_callSetUp = response.GetCallSetUp();
      currentCallToken = m_callSetUp.CallToken;
  
      return 1;
    }
Example #2
0
    public void SetMessageType(Opal_API.OpalMessageType type)
    {
      Opal_API.OpalFreeMessage(ref m_message);

      m_message = new Opal_API.OpalMessage();  
      
      switch(type)
      {
        case Opal_API.OpalMessageType.OpalCmdSetGeneralParameters:
          m_generalParams = new OpalParamGeneralRef(m_message.m_param.m_general);
          break;
        case Opal_API.OpalMessageType.OpalCmdSetProtocolParameters:
          m_protocolParams = new OpalParamProtocolRef(m_message.m_param.m_protocol);
          break;
        case Opal_API.OpalMessageType.OpalCmdRegistration:
          m_registrationInfo = new OpalParamRegistrationRef(m_message.m_param.m_registrationInfo);
          break;
        case Opal_API.OpalMessageType.OpalIndRegistration:
          m_registrationStatus = new OpalStatusRegistrationRef(m_message.m_param.m_registrationStatus);
          break;
        case Opal_API.OpalMessageType.OpalCmdSetUpCall:
        case Opal_API.OpalMessageType.OpalIndProceeding:
        case Opal_API.OpalMessageType.OpalIndAlerting:
        case Opal_API.OpalMessageType.OpalIndEstablished:
        case Opal_API.OpalMessageType.OpalIndCompletedIVR:
          m_callSetUp = new OpalParamSetUpCallRef(m_message.m_param.m_callSetUp);
          break;
        case Opal_API.OpalMessageType.OpalIndIncomingCall:
          m_incomingCall = new OpalStatusIncomingCallRef(m_message.m_param.m_incomingCall);
          break;
        case Opal_API.OpalMessageType.OpalCmdAlerting:
        case Opal_API.OpalMessageType.OpalCmdAnswerCall:
          m_answerCall = new OpalParamAnswerCallRef(m_message.m_param.m_answerCall);
          break;
        case Opal_API.OpalMessageType.OpalIndUserInput:
        case Opal_API.OpalMessageType.OpalCmdUserInput:
          m_userInput = new OpalStatusUserInputRef(m_message.m_param.m_userInput);
          break;
        case Opal_API.OpalMessageType.OpalIndMessageWaiting:
          m_messageWaiting = new OpalStatusMessageWaitingRef(m_message.m_param.m_messageWaiting);
          break;
        case Opal_API.OpalMessageType.OpalIndLineAppearance:
          m_lineAppearance = new OpalStatusLineAppearanceRef(m_message.m_param.m_lineAppearance);
          break;
        case Opal_API.OpalMessageType.OpalIndCallCleared:
          m_callCleared = new OpalStatusCallClearedRef(m_message.m_param.m_callCleared);
          break;
        case Opal_API.OpalMessageType.OpalCmdClearCall:
          m_clearCall = new OpalParamCallClearedRef(m_message.m_param.m_clearCall);
          break;
        case Opal_API.OpalMessageType.OpalIndMediaStream:
        case Opal_API.OpalMessageType.OpalCmdMediaStream:
          m_mediaStream = new OpalStatusMediaStreamRef(m_message.m_param.m_mediaStream);
          break;
        case Opal_API.OpalMessageType.OpalCmdSetUserData:
          m_setUserData = new OpalParamSetUserDataRef(m_message.m_param.m_setUserData);
          break;
        case Opal_API.OpalMessageType.OpalCmdStartRecording:
          m_recording = new OpalParamRecordingRef(m_message.m_param.m_recording);
          break;
        case Opal_API.OpalMessageType.OpalIndTransferCall:
          m_transferStatus = new OpalStatusTransferCallRef(m_message.m_param.m_transferStatus);
          break;
        default:
          break;

      }
      m_message.m_type = type;
    }
Example #3
0
    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;
        }        
      }
    }