sip_add_header and dial

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

sip_add_header and dial

Nir Simionovich
Hi All,

  I'm taking my first steps in Adhearsion, mainly due to the fact that I've been a fair PHP Supporter (I still love PHP).

  I've managed to run into an interesting issue, which I'll detail below:

  1. Adding a SIP header using the adhearsion-asterisk sip_add_header function, then issuing a dial method, doesn't
      seem to generate a SIP INVITE with the new headers.
  2. When I do the above using execute - seems to be working correctly.
  3. Another thing that is odd, if I add options to dial method, like :for 30.seconds, ruby fails on 'seconds' claiming it has
      no idea what to do with it.

  Am I missing some kind of operational construct here? I suspect 1 and 2 relate directly to the fact that 
Adhearsion dial is done asynchronously from the first call, thus, anything creating on the first channel,
doesn't have a direct relation to the next channel in line. 

  Also, in regards to number 3, if I remove the 'seconds' indicator, the function works just as expected - however, it would seem
that the documentation is a little off-base. 

  Can any shed some light on the matter?


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sip_add_header and dial

Ben Langfeld
Hello there Nir,

Enviado do meu iPhone

Em 12 de mar de 2017, às 10:35, Nir Simionovich <[hidden email]> escreveu:

Hi All,

  I'm taking my first steps in Adhearsion, mainly due to the fact that I've been a fair PHP Supporter (I still love PHP).

  I've managed to run into an interesting issue, which I'll detail below:

  1. Adding a SIP header using the adhearsion-asterisk sip_add_header function, then issuing a dial method, doesn't
      seem to generate a SIP INVITE with the new headers.
  2. When I do the above using execute - seems to be working correctly.
  3. Another thing that is odd, if I add options to dial method, like :for 30.seconds, ruby fails on 'seconds' claiming it has
      no idea what to do with it.

  Am I missing some kind of operational construct here? I suspect 1 and 2 relate directly to the fact that 
Adhearsion dial is done asynchronously from the first call, thus, anything creating on the first channel,
doesn't have a direct relation to the next channel in line. 

Indeed you are correct here. You can instead, I believe, set headers on the outbound call like this:

dial "SIP/foi", headers: { "X-my-header" => "something" }

  Also, in regards to number 3, if I remove the 'seconds' indicator, the function works just as expected - however, it would seem
that the documentation is a little off-base. 

Indeed, the documentation was probably not updated correctly when ActiveSupport (which implements .seconds amongst a million other things) was removed as a dependency because of its weight.

If anyone could submit a patch for the documentation, that would be lovely.

  Can any shed some light on the matter?


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sip_add_header and dial

Ben Klang-2

Il giorno 12 mar 2017, alle ore 09:51, Ben Langfeld <[hidden email]> ha scritto:

Em 12 de mar de 2017, às 10:35, Nir Simionovich <[hidden email]> escreveu:

  3. Another thing that is odd, if I add options to dial method, like :for 30.seconds, ruby fails on 'seconds' claiming it has
      no idea what to do with it.

  Also, in regards to number 3, if I remove the 'seconds' indicator, the function works just as expected - however, it would seem
that the documentation is a little off-base. 

Indeed, the documentation was probably not updated correctly when ActiveSupport (which implements .seconds amongst a million other things) was removed as a dependency because of its weight.

If anyone could submit a patch for the documentation, that would be lovely.

And for the record, there are two solutions to this:

A. You can add ActiveSupport to your app’s Gemfile and require ‘active_support/all’. This gets you a lot of helper methods (like 30.seconds, 1.minute, etc)
B. You actually don’t need the .seconds suffix because 30 - just do `dial for: 30`  as the value does not need converting

/BAK/


  Can any shed some light on the matter?



-- 
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: sip_add_header and dial

Andrius Kairiukstis-2
In reply to this post by Ben Langfeld
Sip add header works. Nir, show your code

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

sip_add_header and dial

Andrius Kairiukstis-2
In reply to this post by Nir Simionovich
Sorry you are right. With dial command sip add header would not work. It uses same technique as AMI originate. You can use execute or Ben's proposal that give limited support to work with sip headers

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sip_add_header and dial

Ben Langfeld


Enviado do meu iPhone

> Em 12 de mar de 2017, às 11:06, Andrius Kairiukstis <[hidden email]> escreveu:
>
> Sorry you are right. With dial command sip add header would not work. It uses same technique as AMI originate. You can use execute or Ben's proposal that give limited support to work with sip headers

Limited in what way? It allows you to set any headers you like on the outbound call. What more could you want?

>
> --
> You received this message because you are subscribed to the Google Groups "Adhearsion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sip_add_header and dial

Andrius Kairiukstis-2
Not all types of headers.

In a project I am working with now, we do need to manipulate with sip invite. I have to use execute command

I will post my dial controller version later, on mobile now  

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sip_add_header and dial

Andrius Kairiukstis-2
Here is my dial command with comments

def dial_destination(destination)

  # this part, that can be processed by adhearsion natively:
  # dial "SIP/foo", headers: { "X-my-header" => "something" }
  if destination.sip_headers
    destination.sip_headers.each_pair do |header, content|
      execute "SIPAddHeader #{header}:#{content}"
    end
  end

  # Set SIP other SIP invite options
  # those options can't be set with Adhearsion and I have to use execute command
  %w(sip_uri_options fromdomain codec codec_inbound codec_outbound).each do |opt|
    if opt == 'sip_uri_options' && destination.sip_uri_options
      options = destination.sip_uri_options.map { |option_name, option_value| "#{option_name}=#{option_value}" }.join(';')
      set_variable '__SIP_URI_OPTIONS', options
    elsif opt == 'fromdomain' && destination.fromdomain
      set_variable '__SIPFROMDOMAIN', destination.fromdomain
    else
      # set_variable '__SIP_CODEC', 'ulaw'
      # set_variable '__SIP_CODEC_INBOUND', 'gsm'
      # set_variable '__SIP_CODEC_OUTBOUND', 'alaw'
      if data = destination[opt]
        set_variable "__SIP_#{opt.upcase}", data
      end
    end
  end

  # construct dial string
  dialstring = if destination.fromhost
    if destination.outboundproxy
      number, host = destination.to.split('@')

      # system is fully dynamic and managed through API, we don't have SIP trunks, so here we do create
      # MySQL database record with trunk definition and it's SIP outboundproxy, so Asterisk will send call
      # to the right destination through correct provider.
      sp = Sippeer.build host:          host,
                         outboundproxy: destination.outboundproxy,
                         fromdomain:    destination.fromdomain

      logger.info "Dialing number #{number} at host #{host} through outboundproxy #{destination.outboundproxy} and fromdomain #{destination.fromdomain}. Sippeer used: #{sp.inspect}"

      "SIP/#{number}@#{sp.name}!#{number}@#{destination.fromhost},#{duration}"
    else
      "SIP/#{destination.to}!#{destination.to.split('@').first}@#{destination.fromhost},#{duration}"
    end
  else
    "SIP/#{destination.to},#{duration}"
  end

  logger.info "#{self.class}: dialstring with arguments: #{dialstring}"
  execute "Dial #{dialstring}"
end

On Sunday, 12 March 2017 15:28:55 UTC+1, Andrius Kairiukstis wrote:
Not all types of headers.

In a project I am working with now, we do need to manipulate with sip invite. I have to use execute command

I will post my dial controller version later, on mobile now  

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.