Class: Librevox::Listener::Outbound
- Includes:
- Applications
- Defined in:
- lib/librevox/listener/outbound.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #application(app, args = nil, **params) ⇒ Object
- #handle_response ⇒ Object
-
#initialize(connection) ⇒ Outbound
constructor
A new instance of Outbound.
- #run_session ⇒ Object
-
#session_initiated ⇒ Object
Called when a new session is initiated.
- #update_session ⇒ Object
- #variable(name) ⇒ Object
Methods included from Applications
#answer, #att_xfer, #bind_meta_app, #bridge, #deflect, #export, #gentones, #hangup, #multiset, #park, #play_and_get_digits, #playback, #pre_answer, #read, #record, #redirect, #respond, #set, #transfer, #unbind_meta_app, #unset
Methods inherited from Base
#api, #disconnect, event, hooks, #on_event, #receive_message, #send_message
Constructor Details
#initialize(connection) ⇒ Outbound
Returns a new instance of Outbound.
42 43 44 45 46 |
# File 'lib/librevox/listener/outbound.rb', line 42 def initialize(connection) super(connection) @session = nil @app_complete_queue = Async::Queue.new end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
36 37 38 |
# File 'lib/librevox/listener/outbound.rb', line 36 def session @session end |
Class Method Details
Instance Method Details
#application(app, args = nil, **params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/librevox/listener/outbound.rb', line 16 def application(app, args = nil, **params) variable_name = params.delete(:variable) headers = params .merge( event_lock: true, call_command: "execute", execute_app_name: app, execute_app_arg: args, ) .map { |key, value| "#{key.to_s.tr('_', '-')}: #{value}" } "sendmsg\n#{headers.join("\n")}" response = @app_complete_queue.dequeue @session = response.content variable(variable_name) if variable_name end |
#handle_response ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/librevox/listener/outbound.rb', line 55 def handle_response if response.event? && response.event == "CHANNEL_DATA" @session = response.content elsif response.event? && response.event == "CHANNEL_EXECUTE_COMPLETE" @app_complete_queue.push(response) end super end |
#run_session ⇒ Object
48 49 50 51 52 53 |
# File 'lib/librevox/listener/outbound.rb', line 48 def run_session @session = ("connect").headers "myevents" "linger" session_initiated end |
#session_initiated ⇒ Object
Called when a new session is initiated.
39 40 |
# File 'lib/librevox/listener/outbound.rb', line 39 def session_initiated end |
#update_session ⇒ Object
69 70 71 72 |
# File 'lib/librevox/listener/outbound.rb', line 69 def update_session response = api.command "uuid_dump", session[:unique_id] @session = response.content end |
#variable(name) ⇒ Object
65 66 67 |
# File 'lib/librevox/listener/outbound.rb', line 65 def variable(name) session[:"variable_#{name}"] end |