Class: Librevox::Listener::Outbound
- Inherits:
-
Base
- Object
- EventMachine::Protocols::HeaderAndContentProtocol
- Base
- 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
Instance Method Summary collapse
- #application(app, args = nil, params = {}, &block) ⇒ Object
- #handle_response ⇒ Object
- #post_init ⇒ Object
-
#sendmsg(msg) ⇒ Object
This should probably be in Application#sendmsg instead.
-
#session_initiated ⇒ Object
Called when a new session is initiated.
- #update_session(&block) ⇒ Object
- #variable(name) ⇒ Object
Methods included from Applications
#answer, #att_xfer, #bind_meta_app, #bridge, #deflect, #export, #gentones, #hangup, #play_and_get_digits, #playback, #pre_answer, #read, #record, #redirect, #respond, #set, #transfer, #unbind_meta_app, #unset
Methods inherited from Base
#api, #command, event, hooks, #on_event, #receive_request
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
30 31 32 |
# File 'lib/librevox/listener/outbound.rb', line 30 def session @session end |
Instance Method Details
#application(app, args = nil, params = {}, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/librevox/listener/outbound.rb', line 9 def application app, args=nil, params={}, &block msg = "sendmsg\n" msg << "call-command: execute\n" msg << "execute-app-name: #{app}\n" msg << "execute-app-arg: #{args}\n" if args && !args.empty? send_data "#{msg}\n" @application_queue.push(proc { update_session do arg = params[:variable] ? variable(params[:variable]) : nil block.call(arg) if block end }) end |
#handle_response ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/librevox/listener/outbound.rb', line 48 def handle_response if session.nil? @session = response.headers elsif response.event? && response.event == "CHANNEL_DATA" @session = response.content elsif response.command_reply? && !response.event? @application_queue.shift.call(response) if @application_queue.any? end super end |
#post_init ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/librevox/listener/outbound.rb', line 36 def post_init super @session = nil @application_queue = [] send_data "connect\n\n" send_data "myevents\n\n" @application_queue << proc {} send_data "linger\n\n" @application_queue << proc {session_initiated} end |
#sendmsg(msg) ⇒ Object
This should probably be in Application#sendmsg instead.
26 27 28 |
# File 'lib/librevox/listener/outbound.rb', line 26 def sendmsg msg send_data "sendmsg\n%s" % msg end |
#session_initiated ⇒ Object
Called when a new session is initiated.
33 34 |
# File 'lib/librevox/listener/outbound.rb', line 33 def session_initiated end |
#update_session(&block) ⇒ Object
64 65 66 |
# File 'lib/librevox/listener/outbound.rb', line 64 def update_session &block api.command "uuid_dump", session[:unique_id], &block end |
#variable(name) ⇒ Object
60 61 62 |
# File 'lib/librevox/listener/outbound.rb', line 60 def variable name session[:"variable_#{name}"] end |