Exemple #1
0
 private void m_pToolbar_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem.Tag == null)
     {
         return;
     }
     if (e.ClickedItem.Tag.ToString() == "delete")
     {
         SipCall sipCall = (SipCall)this.m_pCalls.SelectedItems[0].Tag;
         if (MessageBox.Show(this, string.Concat(new string[]
         {
             "Are you sure you want to terminate call '",
             sipCall.Caller,
             "->",
             sipCall.Callee,
             "' ?"
         }), "Remove Registration", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             sipCall.Terminate();
             this.m_pCalls.SelectedItems[0].Remove();
             return;
         }
     }
     else if (e.ClickedItem.Tag.ToString() == "refresh")
     {
         this.LoadData();
     }
 }
Exemple #2
0
        static void test1()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");


            StreamerSession streamer = new StreamerSession(x);

            streamer.Allocate(null,
                              StreamerSession.RcvDeviceType.RCV_DEVICE_NONE,
                              StreamerSession.SndDeviceType.SND_DEVICE_TYPE_FILE);

            SipCall sipCall = new SipCall(x);

            Credentials c = new Credentials();

            c.User     = "******";
            c.Realm    = "example.com";
            c.Password = "******";

            LinkedList <string> contactList =
                new LinkedList <string>();

            contactList.AddLast("sip:1234" + "@" + GetLocalIP());

//             ApiErrorCode res = sipCall.StartRegistration(
//                 contactList,
//                 "sip:[email protected]",
//                 c,
//                 DEFAULT_TIMEOUT);
//
//             if (res != ApiErrorCode.API_SUCCESS)
//                 throw new Exception("Registration failed err:" + res);


            ApiErrorCode res = sipCall.MakeCall("sip:[email protected]", streamer.LocalOffer(), c, null, DEFAULT_TIMEOUT);


            streamer.ModifyConnection(sipCall.RemoteOffer());
            streamer.PlayFile(@"c:\SOUNDS\greeting.wav", true, false);

            sipCall.HangupCall();



            Console.WriteLine("MakeCall res=" + res);
        }
        public SipCall NewSipCall(string to, string from, string fromName = null, string codecs = null, JArray headers = null, int timeout = 30, int?maxDuration = null, bool?webRTCMedia = null)
        {
            SipCall call = new SipCall(this, Guid.NewGuid().ToString())
            {
                To          = to,
                From        = from,
                FromName    = fromName,
                Headers     = headers,
                Codecs      = codecs,
                Timeout     = timeout,
                MaxDuration = maxDuration,
                WebRTCMedia = webRTCMedia
            };

            mCalls.TryAdd(call.TemporaryID, call);
            OnCallCreated?.Invoke(this, call);
            return(call);
        }
        private void OnCallingEvent_Receive(Client client, BroadcastParams broadcastParams, CallingEventParams callEventParams)
        {
            CallingEventParams.ReceiveParams receiveParams = null;
            try { receiveParams = callEventParams.ParametersAs <CallingEventParams.ReceiveParams>(); }
            catch (Exception exc)
            {
                Log(LogLevel.Warning, exc, "Failed to parse ReceiveParams");
                return;
            }

            // @note A received call should only ever receive one receive event regardless of the state of the call, but we act as though
            // we could receive multiple just for sanity here, but the callbacks will still only be called when first created, which makes
            // this effectively a no-op on additional receive events
            Call call = null;
            Call tmp  = null;

            switch (receiveParams.Device.Type)
            {
            case CallDevice.DeviceType.phone:
            {
                CallDevice.PhoneParams phoneParams = null;
                try { phoneParams = receiveParams.Device.ParametersAs <CallDevice.PhoneParams>(); }
                catch (Exception exc)
                {
                    Log(LogLevel.Warning, exc, "Failed to parse PhoneParams");
                    return;
                }

                // If the call already exists under the real call id simply obtain the call, otherwise create a new call
                call = mCalls.GetOrAdd(receiveParams.CallID, k => (tmp = new PhoneCall(this, receiveParams.NodeID, receiveParams.CallID)
                    {
                        To = phoneParams.ToNumber,
                        From = phoneParams.FromNumber,
                        Timeout = phoneParams.Timeout,
                    }));
                break;
            }

            case CallDevice.DeviceType.sip:
            {
                CallDevice.SipParams sipParams = null;
                try { sipParams = receiveParams.Device.ParametersAs <CallDevice.SipParams>(); }
                catch (Exception exc)
                {
                    Log(LogLevel.Warning, exc, "Failed to parse SipParams");
                    return;
                }

                // If the call already exists under the real call id simply obtain the call, otherwise create a new call
                call = mCalls.GetOrAdd(receiveParams.CallID, k => (tmp = new SipCall(this, receiveParams.NodeID, receiveParams.CallID)
                    {
                        To = sipParams.To,
                        From = sipParams.From,
                        Headers = sipParams.Headers,
                    }));
                break;
            }

            // @TODO: webrtc
            default:
                Log(LogLevel.Warning, string.Format("Unknown device type: {0}", receiveParams.Device.Type));
                return;
            }

            if (tmp == call)
            {
                call.Context = receiveParams.Context;

                OnCallCreated?.Invoke(this, call);
                OnCallReceived?.Invoke(this, call, receiveParams);
            }

            call.ReceiveHandler(callEventParams, receiveParams);
        }
        private void OnCallingEvent_State(Client client, BroadcastParams broadcastParams, CallingEventParams callEventParams)
        {
            CallingEventParams.StateParams stateParams = null;
            try { stateParams = callEventParams.ParametersAs <CallingEventParams.StateParams>(); }
            catch (Exception exc)
            {
                Log(LogLevel.Warning, exc, "Failed to parse StateParams");
                return;
            }

            Call call = null;
            Call tmp  = null;

            switch (stateParams.Device.Type)
            {
            case CallDevice.DeviceType.phone:
            {
                CallDevice.PhoneParams phoneParams = null;
                try { phoneParams = stateParams.Device.ParametersAs <CallDevice.PhoneParams>(); }
                catch (Exception exc)
                {
                    Log(LogLevel.Warning, exc, "Failed to parse PhoneParams");
                    return;
                }

                // If the call already exists under the real call id simply obtain the call, however if the call was found under
                // a temporary call id then readd it here under the real call id, otherwise create a new call
                call = mCalls.GetOrAdd(stateParams.CallID, k => call ?? (tmp = new PhoneCall(this, stateParams.NodeID, stateParams.CallID)
                    {
                        To = phoneParams.ToNumber,
                        From = phoneParams.FromNumber,
                        Timeout = phoneParams.Timeout,
                        // Capture the state, it may not always be created the first time we see the call
                        State = stateParams.CallState,
                    }));
                break;
            }

            case CallDevice.DeviceType.sip:
            {
                CallDevice.SipParams sipParams = null;
                try { sipParams = stateParams.Device.ParametersAs <CallDevice.SipParams>(); }
                catch (Exception exc)
                {
                    Log(LogLevel.Warning, exc, "Failed to parse SipParams");
                    return;
                }

                // If the call already exists under the real call id simply obtain the call, however if the call was found under
                // a temporary call id then readd it here under the real call id, otherwise create a new call
                call = mCalls.GetOrAdd(stateParams.CallID, k => call ?? (tmp = new SipCall(this, stateParams.NodeID, stateParams.CallID)
                    {
                        To = sipParams.To,
                        From = sipParams.From,
                        FromName = sipParams.FromName,
                        Headers = sipParams.Headers,

                        // Capture the state, it may not always be created the first time we see the call
                        State = stateParams.CallState,
                    }));
                break;
            }

            // @TODO: webrtc
            default:
                Log(LogLevel.Warning, string.Format("Unknown device type: {0}", stateParams.Device.Type));
                return;
            }

            if (tmp == call)
            {
                OnCallCreated?.Invoke(this, call);
            }

            call.StateChangeHandler(callEventParams, stateParams);
        }
Exemple #6
0
        static void test2()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");


            RtpProxySession streamerRtpSession = new RtpProxySession(x);
            AbstractOffer   dummyOffer         = new AbstractOffer();

            dummyOffer.Type = "application/sdp";
            dummyOffer.Body = @"v=0" + "\n"
                              + "o=alice 2890844526 2890844526 IN IP4 0.0.0.0" + "\n"
                              + "s=" + "\n"
                              + "c=IN IP4 0.0.0.0" + "\n"
                              + "t=0 0" + "\n"
                              + "m=audio 0 RTP/AVP 0" + "\n"
                              + "a=rtpmap:0 PCMU/8000" + "\n\n";;

            ApiErrorCode res = streamerRtpSession.Allocate(dummyOffer);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }

            StreamerSession streamer = new StreamerSession(x);

            streamer.Allocate(streamerRtpSession.LocalOffer(),
                              StreamerSession.RcvDeviceType.RCV_DEVICE_NONE,
                              StreamerSession.SndDeviceType.SND_DEVICE_TYPE_FILE);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("StreamerSession Allocated failed err:" + res);
            }

            streamerRtpSession.Modify(streamer.LocalOffer());


            RtpProxySession sipRtpSession = new RtpProxySession(x);

            sipRtpSession.Allocate(dummyOffer);


            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(2) Allocated failed err:" + res);
            }

            SipCall sipCall = new SipCall(x);


            res =
                sipCall.MakeCall("sip:[email protected]", sipRtpSession.LocalOffer(), null, null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall failed err:" + res);
            }

            sipRtpSession.Modify(sipCall.RemoteOffer());

            sipRtpSession.Bridge(streamerRtpSession, true);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Bridge failed err:" + res);
            }



            streamer.PlayFile(@"c:\SOUNDS\greeting.wav", true, false);

            sipCall.Dispose();

            Console.WriteLine("MakeCall res=" + res);
        }
Exemple #7
0
        static void test6()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");

            RtpProxySession rtpProxy =
                new RtpProxySession(x);

            //
            // Allocate RTP endpoint for RTSP session.
            //
            RtpProxySession call1RtpSession = new RtpProxySession(x);
            AbstractOffer   dummyOffer      = new AbstractOffer();

            dummyOffer.Type = "application/sdp";
            dummyOffer.Body = @"v=0
o=alice 2890844526 2890844526 IN IP4 0.0.0.0
s=
c=IN IP4 0.0.0.0
t=0 0
m=audio 0 RTP/AVP 8 101
a=rtpmap:0 PCMA/8000
a=rtpmap:101 telephone-event/8000

";

            ApiErrorCode res = call1RtpSession.Allocate(dummyOffer);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            SipCall caller = new SipCall(x);

            res = caller.MakeCall("sip:[email protected]",
                                  call1RtpSession.LocalOffer(),
                                  null,
                                  null,
                                  DEFAULT_TIMEOUT);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall err:" + res);
            }

            bool shutdown = false;
            List <IActiveObject> actors =
                new List <IActiveObject>();

            actors.Add(caller);
            actors.Add(call1RtpSession);

            while (!shutdown)
            {
                Selector s        = new Selector();
                int      index    = 0;
                int      event_id = 0;
                res = s.Select(
                    actors,
                    DEFAULT_TIMEOUT,
                    ref index,
                    ref event_id);

                String dtmfs = call1RtpSession.DtmfBuffer();

                Console.Out.WriteLine("err=" + res +
                                      ", index=" + index +
                                      ", event=" + event_id +
                                      ", dtmfs=" + dtmfs);

                if (dtmfs.Contains("#") || index == 0)
                {
                    shutdown = true;
                }
            }


            caller.HangupCall();
        }
Exemple #8
0
        static void test5()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");

            SipCall      caller = new SipCall(x);
            ApiErrorCode res    = caller.MakeCall("sip:[email protected]", null, null, null, DEFAULT_TIMEOUT);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall err:" + res);
            }

            MrcpSession recog =
                new MrcpSession(x);;

            recog.Allocate(MrcpResource.RECOGNIZER, caller.RemoteOffer(), DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Allocate err:" + res);
            }

            caller.Answer(recog.RemoteOffer(MrcpResource.RECOGNIZER), null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Allocate err:" + res);
            }



            MrcpSession synth = new MrcpSession(x);

            synth.Allocate(MrcpResource.SYNTHESIZER, caller.RemoteOffer(), DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Allocate(SYNTHESIZER) err:" + res);
            }


            Thread.Sleep(1000);
            synth.SimpleSpeak(null, "Please choose red pill, or blue pill", true);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Speak err:" + res);
            }


            String pillgrammar = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!-- the default grammar language is US English -->
<grammar xmlns=""http://www.w3.org/2001/06/grammar""
         xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
         xml:lang=""en-US"" version=""1.0"" root=""pill"">
  <rule id=""pill"">
    <one-of>
      <item>red</item>
      <item>blue</item>
    </one-of> 
  </rule> 
</grammar>";

            Dictionary <String, Object> p =
                new Dictionary <String, Object>();

            p["cancel_if_queue"]       = true;
            p["content_id"]            = "<*****@*****.**>";
            p["content_type"]          = "application/srgs+xml";
            p["no_input_timeout"]      = 20000;
            p["confidence_threshhold"] = 0.9;
            p["start_input_timers"]    = true;



            String answer;

            res = recog.Recognize(
                p,
                pillgrammar,
                DEFAULT_TIMEOUT * 10000,
                true,
                out answer);


            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Speak err:" + res);
            }


            Console.Out.WriteLine(answer);

            caller.WaitTillHangup();
        }
Exemple #9
0
        static void test4()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");

            //
            // Allocate RTP endpoint for RTSP session.
            //
            RtpProxySession call1RtpSession = new RtpProxySession(x);
            AbstractOffer   dummyOffer      = new AbstractOffer();

            dummyOffer.Type = "application/sdp";
            dummyOffer.Body = @"v=0" + "\n"
                              + "o=alice 2890844526 2890844526 IN IP4 0.0.0.0" + "\n"
                              + "s=" + "\n"
                              + "c=IN IP4 0.0.0.0" + "\n"
                              + "t=0 0" + "\n"
                              + "m=audio 0 RTP/AVP 8" + "\n"
                              + "a=rtpmap:0 PCMA/8000" + "\n\n";;

            ApiErrorCode res = call1RtpSession.Allocate(dummyOffer);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            //
            // Allocate sip RTP session
            //
            RtpProxySession call2RtpSession = new RtpProxySession(x);

            res = call2RtpSession.Allocate(dummyOffer);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            //
            // Make call1
            //
            SipCall sipCall1 = new SipCall(x);

            res = sipCall1.MakeCall("sip:[email protected]", call1RtpSession.LocalOffer(), null, null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall failed err:" + res);
            }


            call1RtpSession.Modify(sipCall1.RemoteOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Modify failed err:" + res);
            }

            //
            // Make call2
            //
            SipCall sipCall2 = new SipCall(x);

            res = sipCall2.MakeCall("sip:[email protected]", call2RtpSession.LocalOffer(), null, null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall failed err:" + res);
            }
            call2RtpSession.Modify(sipCall2.RemoteOffer());


            call1RtpSession.Bridge(call2RtpSession, true);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Bridge failed err:" + res);
            }



            Thread.Sleep(30000);
            sipCall1.Dispose();
            sipCall2.Dispose();

            Console.WriteLine("MakeCall res=" + res);
        }
Exemple #10
0
        static void test3()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");

            //
            // Allocate RTP endpoint for RTSP session.
            //
            RtpProxySession rtspRtpSession = new RtpProxySession(x);
            AbstractOffer   dummyOffer     = new AbstractOffer();

            dummyOffer.Type = "application/sdp";
            dummyOffer.Body = @"v=0" + "\n"
                              + "o=alice 2890844526 2890844526 IN IP4 0.0.0.0" + "\n"
                              + "s=" + "\n"
                              + "c=IN IP4 0.0.0.0" + "\n"
                              + "t=0 0" + "\n"
                              + "m=audio 0 RTP/AVP 8" + "\n"
                              + "a=rtpmap:0 PCMA/8000" + "\n\n";;

            ApiErrorCode res = rtspRtpSession.Allocate(dummyOffer);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            //
            // Set up RTSP session and update its RTP endpoint.
            //
            RtspSession rtsp = new RtspSession(x);

            res = rtsp.Setup("rtsp://10.116.100.78/IvrScript.wav", rtspRtpSession.LocalOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtspSession Setup failed err:" + res);
            }

            res = rtspRtpSession.Modify(rtsp.RemoteOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtspSession Modify failed err:" + res);
            }


            //
            // Allocate sip RTP session
            //
            RtpProxySession sipRtpSession = new RtpProxySession(x);

            res = sipRtpSession.Allocate(dummyOffer);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            //
            // Make call
            //
            SipCall sipCall = new SipCall(x);

            res = sipCall.MakeCall("sip:[email protected]", sipRtpSession.LocalOffer(), null, null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall failed err:" + res);
            }

            sipRtpSession.Modify(sipCall.RemoteOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Modify failed err:" + res);
            }

            rtspRtpSession.Bridge(sipRtpSession, false);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Bridge failed err:" + res);
            }



            res = rtsp.Play(0.0, 0.0, 1);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }

            Thread.Sleep(10000);


            sipCall.Dispose();

            Console.WriteLine("MakeCall res=" + res);
        }