/// <summary> /// Calls OpalGetMessage() to get next message from the OPAL context. /// </summary> public bool GetMessage( OpalMessageRef message, uint timeout = 0) { if (m_handle == IntPtr.Zero) { message.SetMessageType(Opal_API.OpalMessageType.OpalIndCommandError); message.CmdError = "Uninitialised OPAL context."; return false; } IntPtr ptrMessage = Opal_API.OpalGetMessage(m_handle, timeout); if (ptrMessage == IntPtr.Zero) { message.SetMessageType(Opal_API.OpalMessageType.OpalIndCommandError); message.CmdError = "Timeout getting message."; return false; } message.m_message = (Opal_API.OpalMessage)Marshal.PtrToStructure(ptrMessage, typeof(Opal_API.OpalMessage)); return true; }
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; }
/// <summary> /// Calls OpalSendMessage() to send a message to the OPAL context. /// </summary> /// <param name="message">Message to send to OPAL.</param> /// <param name="response"> Response from OPAL.</param> public bool SendMessage(OpalMessageRef message, OpalMessageRef response) { if (m_handle == IntPtr.Zero) { response.SetMessageType(Opal_API.OpalMessageType.OpalIndCommandError); response.CmdError = "Uninitialised OPAL context."; return false; } IntPtr ptrMessage = Opal_API.OpalSendMessage(m_handle, ref message.m_message); if(ptrMessage == IntPtr.Zero) { response.SetMessageType(Opal_API.OpalMessageType.OpalIndCommandError); response.CmdError = "Invalid message"; return false; } response.m_message = (Opal_API.OpalMessage)Marshal.PtrToStructure(ptrMessage, typeof(Opal_API.OpalMessage)); return response.GetMessageType() != Opal_API.OpalMessageType.OpalIndCommandError; }
static int DoSubscribe(string package, string aor, string from) { // Example cmd line: subscribe "dialog;sla;ma" [email protected] [email protected] OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response; Console.WriteLine("Susbcribing {0}", aor); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdRegistration); OpalParamRegistrationRef m_registrationInfo = command.GetRegistrationInfo(); m_registrationInfo.Protocol = "sip"; m_registrationInfo.Identifier = aor; m_registrationInfo.HostName = from; m_registrationInfo.EventPackage = package; m_registrationInfo.TimeToLive = 300; if ((response = MySendCommand(command, "Could not subscribe")) == null) return 0; 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 DoRegister(string aor, string pwd) { // Example cmd line: register [email protected] secret OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response; Console.WriteLine("Registering {0}", aor); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdRegistration); OpalParamRegistrationRef m_registrationInfo = command.GetRegistrationInfo(); if (!aor.Contains(':')) { m_registrationInfo.Protocol = "h323"; m_registrationInfo.Identifier = aor; } else { m_registrationInfo.Protocol = aor; m_registrationInfo.Identifier = aor.Substring(aor.IndexOf(':') + 1); } m_registrationInfo.Password = pwd; m_registrationInfo.TimeToLive = 300; if ((response = MySendCommand(command, "Could not register endpoint")) == null) return 0; 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 int DoHold() { // Example cmd line: hold [email protected] OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response; Console.WriteLine("Hold"); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdHoldCall); command.SetCallToken(currentCallToken); if ((response = MySendCommand(command, "Could not hold call")) == null) return 0; heldCallToken = currentCallToken; currentCallToken = null; return 1; }
static int DoMute(bool on) { // Example cmd line: mute [email protected] OpalMessageRef command = new OpalMessageRef(); OpalMessageRef response = new OpalMessageRef(); Console.WriteLine("Mute {0}", on ? "on" : "off"); command.SetMessageType(Opal_API.OpalMessageType.OpalCmdMediaStream); OpalStatusMediaStreamRef m_mediaStream = command.GetMediaStream(); m_mediaStream.CallToken = currentCallToken; m_mediaStream.Type = "audio out"; m_mediaStream.State = on ? Opal_API.OpalMediaStates.OpalMediaStatePause : Opal_API.OpalMediaStates.OpalMediaStateResume; if ((response = MySendCommand(command, "Could not mute call")) == 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; }