sip_add_header and dial

54 views
Skip to first unread message

Nir Simionovich

unread,
Mar 12, 2017, 9:42:12 AM3/12/17
to Adhearsion
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?


Ben Langfeld

unread,
Mar 12, 2017, 9:51:13 AM3/12/17
to adhea...@googlegroups.com
Hello there Nir,

Enviado do meu iPhone

Em 12 de mar de 2017, às 10:35, Nir Simionovich <ni...@greenfieldtech.net> 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 adhearsion+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Klang

unread,
Mar 12, 2017, 9:56:45 AM3/12/17
to adhea...@googlegroups.com
Il giorno 12 mar 2017, alle ore 09:51, Ben Langfeld <b...@langfeld.co.uk> ha scritto:

Em 12 de mar de 2017, às 10:35, Nir Simionovich <ni...@greenfieldtech.net> 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/
signature.asc

Andrius Kairiukstis

unread,
Mar 12, 2017, 10:02:00 AM3/12/17
to Adhearsion
Sip add header works. Nir, show your code

Andrius Kairiukstis

unread,
Mar 12, 2017, 10:06:15 AM3/12/17
to Adhearsion
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

Ben Langfeld

unread,
Mar 12, 2017, 10:22:58 AM3/12/17
to adhea...@googlegroups.com


Enviado do meu iPhone

> Em 12 de mar de 2017, às 11:06, Andrius Kairiukstis <and...@kairiukstis.com> 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?

Andrius Kairiukstis

unread,
Mar 12, 2017, 10:28:55 AM3/12/17
to Adhearsion
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

Andrius Kairiukstis

unread,
Mar 12, 2017, 2:20:04 PM3/12/17
to Adhearsion
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
Reply all
Reply to author
Forward
0 new messages