示例#1
0
        public void can_serialize_and_deserialize_OriginateOptions()
        {
            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();

                var options = new OriginateOptions()
                {
                    CallerIdName = "Dan",
                    CallerIdNumber = "0123457890",
                    ExecuteOnOriginate = "my_app::my_arg",
                    Retries = 5,
                    RetrySleepMs = 200,
                    ReturnRingReady = true,
                    TimeoutSeconds = 60,
                    UUID = "83fe4f3d-b957-4b26-b6bf-3879d7e21972",
                    IgnoreEarlyMedia = true,
                };

                formatter.Serialize(ms, options);

                ms.Seek(0, SeekOrigin.Begin);

                var fromStream = formatter.Deserialize(ms) as OriginateOptions;
                Assert.Equal(options, fromStream);
            }
        }
示例#2
0
         public void can_build_originate_string()
         {
             var options = new OriginateOptions()
                               {
                                   UUID = "985cea12-4e70-4c03-8a2c-2c4b4502bbbb",
                                   BypassMedia = true,
                                   CallerIdName = "Test",
                                   CallerIdNumber = "12341234",
                                   ExecuteOnOriginate = "start_dtmf",
                                   HangupAfterBridge = false,
                                   IgnoreEarlyMedia = true,
                                   Retries = 3,
                                   RetrySleepMs = 4000,
                                   ReturnRingReady = true,
                                   TimeoutSeconds = 20
                               };

             options.ChannelVariables.Add("foo", "bar");
             options.ChannelVariables.Add("baz", "widgets");

             var toString = options.ToString();

             const string Expected =
                 "{origination_uuid='985cea12-4e70-4c03-8a2c-2c4b4502bbbb',bypass_media='true',origination_caller_id_name='Test',origination_caller_id_number='12341234',execute_on_originate='start_dtmf',ignore_early_media='true',originate_retries='3',originate_retry_sleep_ms='4000',return_ring_ready='true',originate_timeout='20',hangup_after_bridge='false',foo='bar',baz='widgets'}";
             Assert.Equal(Expected, toString);
         }
示例#3
0
        public void Can_format_originate_options()
        {
            var options = new OriginateOptions()
                              {
                                  CallerIdName = "Dan",
                                  CallerIdNumber = "0123457890",
                                  ExecuteOnOriginate = "my_app::my_arg",
                                  Retries = 5,
                                  RetrySleepMs = 200,
                                  ReturnRingReady = true,
                                  TimeoutSeconds = 60,
                                  UUID = "83fe4f3d-b957-4b26-b6bf-3879d7e21972",
                                  IgnoreEarlyMedia = true,
                              };

            Assert.Equal(
                "{origination_caller_id_name='Dan',origination_caller_id_number='0123457890',execute_on_originate='my_app::my_arg',originate_retries='5',originate_retry_sleep_ms='200',return_ring_ready='true',originate_timeout='60',origination_uuid='83fe4f3d-b957-4b26-b6bf-3879d7e21972',ignore_early_media='true'}",
                options.ToString());
        }
 protected bool Equals(OriginateOptions other)
 {
     return(EnterpriseChannelVariables.SequenceEqual(other.EnterpriseChannelVariables) && ChannelVariables.SequenceEqual(other.ChannelVariables) && parameters.SequenceEqual(other.parameters));
 }
示例#5
0
 /// <summary>
 /// Originate a new call.
 /// </summary>
 /// <remarks>
 /// See https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-originate
 /// </remarks>
 /// <param name="endpoint">The destination to call.</param>
 /// <param name="extension">Destination number to search in dialplan</param>
 /// <param name="dialplan">(Optional) defaults to 'XML' if not specified</param>
 /// <param name="context">(Optional) defaults to 'default' if not specified</param>
 /// <param name="options">(Optional) <seealso cref="OriginateOptions"/> to configure the call.</param>
 /// <returns>A Task of <seealso cref="OriginateResult"/>.</returns>
 public Task<OriginateResult> Originate(
     string endpoint,
     string extension,
     string dialplan = "XML",
     string context = "default",
     OriginateOptions options = null)
 {
     return this.InternalOriginate(endpoint, string.Format("{0} {1} {2}", extension, dialplan, context), options);
 }
示例#6
0
        private Task<OriginateResult> InternalOriginate(string endpoint, string destination, OriginateOptions options = null)
        {
            if (options == null)
            {
                options = new OriginateOptions();
            }

            // if no UUID provided, we'll set one now and use that to filter for the correct channel events
            // this way, one inbound socket can originate many calls and we can complete the correct
            // TaskCompletionSource for each originated call.
            if (string.IsNullOrEmpty(options.UUID))
            {
                options.UUID = Guid.NewGuid().ToString();
            }

            var originateString = string.Format("{0}{1} {2}", options, endpoint, destination);

            return
                BackgroundJob("originate", originateString)
                    .ToObservable()
                    .Merge(
                        Events.FirstAsync(
                            x =>
                            x.UUID == options.UUID
                            && (x.EventName == EventName.ChannelAnswer || x.EventName == EventName.ChannelHangup
                                || (options.ReturnRingReady && x.EventName == EventName.ChannelProgress))).Cast<BasicMessage>())
                    .FirstAsync(x => ((x is BackgroundJobResult) && !((BackgroundJobResult)x).Success) || (x is EventMessage))
                    .Select(OriginateResult.FromBackgroundJobResultOrChannelEvent)
                    .ToTask();
        }
示例#7
0
 /// <summary>
 /// Originate a new call.
 /// </summary>
 /// <remarks>
 /// See https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-originate
 /// </remarks>
 /// <param name="endpoint">The destination to call.</param>
 /// <param name="options">(Optional) <seealso cref="OriginateOptions"/> to configure the call.</param>
 /// <param name="application">(Default: park) The DialPlan application to execute on answer</param>
 /// <returns>A Task of <seealso cref="OriginateResult"/>.</returns>
 public Task<OriginateResult> Originate(string endpoint, OriginateOptions options = null, string application = "park")
 {
     return this.InternalOriginate(endpoint, "&" + application, options);
 }
示例#8
0
 protected bool Equals(OriginateOptions other)
 {
     return(this.ChannelVariables.SequenceEqual(other.ChannelVariables) && this.parameters.SequenceEqual(other.parameters));
 }
示例#9
0
 public void can_set_privacy()
 {
     var options = new OriginateOptions() { OriginationPrivacy = OriginationPrivacy.HideName | OriginationPrivacy.HideNumber | OriginationPrivacy.Screen}.ToString();
     Assert.Contains("origination_privacy='hide_name:hide_number:screen'", options);
 }
示例#10
0
 public void can_set_caller_id_type()
 {
     var options = new OriginateOptions() { SipCallerIdType = SipCallerIdType.RPid }.ToString();
     Assert.Contains("sip_cid_type='rpid'", options);
 }
示例#11
0
 protected bool Equals(OriginateOptions other)
 {
     return this.ChannelVariables.SequenceEqual(other.ChannelVariables) && this.parameters.SequenceEqual(other.parameters);
 }