Example #1
0
        private void HandleOpalMessages()
        {
            OpalMessagePtr msg = new OpalMessagePtr();

            while (m_opalContext.GetMessage(msg, System.UInt32.MaxValue))
            {
                // Handle the message
                switch (msg.GetType())
                {
                case OpalMessageType.OpalIndRegistration:
                    OpalStatusRegistration reg = msg.GetRegistrationStatus();
                    switch (reg.status)
                    {
                    case OpalRegistrationStates.OpalRegisterSuccessful:
                        SetTextSafely(RegisterStatus, "Registration complete to " + reg.serverName);
                        EnableSafely(Unregister, true);
                        break;

                    case OpalRegistrationStates.OpalRegisterRemoved:
                        SetTextSafely(RegisterStatus, "Registration removed from " + reg.serverName);
                        EnableSafely(Unregister, false);
                        EnableSafely(Register, true);
                        EnableSafely(host, true);
                        EnableSafely(user, true);
                        EnableSafely(password, true);
                        break;

                    case OpalRegistrationStates.OpalRegisterFailed:
                        SetTextSafely(RegisterStatus, "Registration failed: " + reg.error);
                        EnableSafely(Register, true);
                        break;
                    }
                    break;

                case OpalMessageType.OpalIndIncomingCall:
                    EnableSafely(Call, false);
                    EnableSafely(Answer, true);
                    EnableSafely(HangUp, true);
                    SetTextSafely(CallStatus, "Incoming call ..." + msg.GetIncomingCall().remoteDisplayName);
                    break;

                case OpalMessageType.OpalIndEstablished:
                    SetTextSafely(CallStatus, "Call established");
                    break;

                case OpalMessageType.OpalIndCallCleared:
                    EnableSafely(Call, true);
                    EnableSafely(Answer, false);
                    EnableSafely(HangUp, false);
                    SetTextSafely(CallStatus, "Call ended: " + msg.GetCallCleared().reason);
                    break;
                }
            }
        }
Example #2
0
        private void HandleOpalMessages()
        {
            OpalMessagePtr msg = new OpalMessagePtr();

            while (m_opalContext.GetMessage(msg, System.UInt32.MaxValue))
            {
                // Handle the message
                switch (msg.GetType())
                {
                case OpalMessageType.OpalIndRegistration:
                    OpalStatusRegistration reg = msg.GetRegistrationStatus();
                    switch (reg.status)
                    {
                    case OpalRegistrationStates.OpalRegisterSuccessful:
                        MessageBox.Show("Registration complete to " + reg.serverName);
                        EnableSafely(Unregister, true);
                        break;

                    case OpalRegistrationStates.OpalRegisterRemoved:
                        MessageBox.Show("Registration removed from " + reg.serverName);
                        EnableSafely(Unregister, false);
                        EnableSafely(Register, true);
                        break;

                    case OpalRegistrationStates.OpalRegisterFailed:
                        MessageBox.Show("Registration failed: " + reg.error);
                        EnableSafely(Register, true);
                        break;
                    }
                    break;

                case OpalMessageType.OpalIndIncomingCall:
                    EnableSafely(Call, false);
                    EnableSafely(Answer, true);
                    EnableSafely(HangUp, true);
                    break;

                case OpalMessageType.OpalIndCallCleared:
                    EnableSafely(Call, true);
                    EnableSafely(Answer, false);
                    EnableSafely(HangUp, false);
                    MessageBox.Show("Call ended: " + msg.GetCallCleared().reason);
                    break;
                }
            }
        }
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;
                }
            }
        }