static int DoPlay(string to, string file) { // Example cmd line: call [email protected] OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response; Console.WriteLine("Playing {0} to {1}", file, to); playScript = String.Format("ivr:<?xml version=\"1.0\"?><vxml version=\"1.0\"><form id=\"PlayFile\">" + "<audio src=\"{0}\"/></form></vxml>", file); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdSetUpCall); OpalParamSetUpCallRef m_callSetUp = command.GetCallSetUp(); m_callSetUp.PartyB = to; if ((response = MySendCommand(command, "Could not make call")) == null) { return(0); } currentCallToken = response.GetCallSetUp().CallToken; return(1); }
static int DoRecord(string to, string file) { // Example cmd line: call [email protected] OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response; Console.WriteLine("Calling {0}", to); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdSetUpCall); OpalParamSetUpCallRef m_callSetUp = command.GetCallSetUp(); m_callSetUp.PartyB = to; if ((response = MySendCommand(command, "Could not make call")) == null) { return(0); } currentCallToken = response.GetCallSetUp().CallToken; Console.WriteLine("Recording {0}", file); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdStartRecording); OpalParamRecordingRef m_recording = command.GetRecording(); m_recording.CallToken = currentCallToken; m_recording.File = file; m_recording.Channels = 2; if ((response = MySendCommand(command, "Could not start recording")) == null) { return(0); } return(1); }
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); }
static int DoTransfer(string to) { // Example cmd line: transfer [email protected] [email protected] OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response; Console.WriteLine("Transferring to {0}", to); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdTransferCall); OpalParamSetUpCallRef m_callSetup = command.GetCallSetUp(); m_callSetup.PartyB = to; m_callSetup.CallToken = currentCallToken; if ((response = MySendCommand(command, "Could not transfer call")) == null) { return(0); } return(1); }
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; } } }