Method: Librevox::Applications#bridge

Defined in:
lib/librevox/applications.rb

#bridge(*args, &block) ⇒ Object

Bridges an incoming call to an endpoint, optionally taking an array of channel variables to set. If given an array of arrays, each contained array of endpoints will be called simultaneously, with the next array of endpoints as failover. See the examples below for different constructs and the callstring it sends to FreeSWITCH.

Examples:

bridge "user/coltrane", "user/backup-office"
#=> user/coltrane,user/backup-office

With channel variables

bridge "user/coltrane", "user/backup-office", :some_var => "value"
#=> {some_var=value}user/coltrane,user/backup-office

With failover

bridge ['user/coltrane', 'user/davis'], ['user/sun-ra', 'user/taylor']
#=> user/coltrane,user/davis|user/sun-ra,user/taylor

See Also:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/librevox/applications.rb', line 56

def bridge *args, &block
  variables = if args.last.is_a? Hash
                # We need to sort the key/value pairs to facilitate testing.
                # This can be removed once 1.8-compat is dropped.
                key_value_pairs = args.pop.sort {|x,y| x.to_s <=> y.to_s}
                key_value_pairs.map! {|k,v| "#{k}=#{v}"}
                "{#{key_value_pairs.join(",")}}"
              else
                ""
              end

  endpoints = if args.first.is_a? Array
                args.map {|e| e.join(",")}.join("|")
              else
                args.join ","
              end

  application "bridge", variables + endpoints, &block
end