Class: Adhearsion::VoIP::FreeSwitch::OesServer::OesDispatcher
- Inherits:
-
DSL::Dialplan::CommandDispatcher
- Object
- DSL::Dialplan::CommandDispatcher
- Adhearsion::VoIP::FreeSwitch::OesServer::OesDispatcher
- Defined in:
- lib/adhearsion/voip/freeswitch/oes_server.rb
Instance Attribute Summary
Attributes inherited from DSL::Dialplan::CommandDispatcher
Instance Method Summary collapse
- #break!(uuid = @context) ⇒ Object
- #dispatch!(event) ⇒ Object
-
#initialize(uuid = nil) ⇒ OesDispatcher
constructor
A new instance of OesDispatcher.
Methods inherited from DSL::Dialplan::CommandDispatcher
#clone, #def_keys!, #method_missing, #return!
Constructor Details
#initialize(uuid = nil) ⇒ OesDispatcher
Returns a new instance of OesDispatcher.
105 106 107 |
# File 'lib/adhearsion/voip/freeswitch/oes_server.rb', line 105 def initialize(uuid=nil) super FreeSwitchDialplanCommandFactory, uuid end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher
Instance Method Details
#break!(uuid = @context) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/adhearsion/voip/freeswitch/oes_server.rb', line 183 def break!(uuid=@context) log "Breaking with #{uuid}" Thread.my.call.mgr << "api break #{uuid}" Thread.my.call.mgr.get_raw_header # Thread.my.call.mgr.get_raw_header # Thread.my.call.mgr.get_raw_header end |
#dispatch!(event) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/adhearsion/voip/freeswitch/oes_server.rb', line 109 def dispatch!(event) if event.kind_of?(DSL::Dialplan::NoOpEventCommand) && event.on_keypress return_value = nil dispatch = lambda do loop do Thread.my.call.mgr.get_raw_header async_event = Thread.my.call.mgr.get_header if async_event['Event-Name'] == 'DTMF' key = async_event['DTMF-String'] return_value = event.on_keypress.call(('0'..'9').include?(key) ? key.to_i : key) end end end if event.timeout begin Timeout.timeout event.timeout, &dispatch rescue Timeout::Error break! return_value end else dispatch.call end else log "Not a noop. Sending #{event.app}(#{event.args.to_a * " "})" Thread.my.call.mgr << "SendMsg\ncall-command: execute\nexecute-app-name: " + "#{event.app}\nexecute-app-arg: #{event.args.to_a * " "}" if event.kind_of? DSL::Dialplan::ExitingEventCommand Thread.my.call.io.close Thread.me.exit end # Useless "command/reply" +OK and content-length headers lambda do Thread.my.call.mgr.get_raw_header redo if Thread.my.call.mgr.get_header['Event-Name'] == "CHANNEL_EXECUTE_COMPLETE" end.call # Main event information. Keep track of the Core-UUID and wait for # it to come back to us as a CHANNEL_EXECUTE_COMPLETE event. execution_header = Thread.my.call.mgr.get_header execution_uuid = execution_header['Core-UUID'] loop do log "Waiting for either a DTMF or the app to finish" hdr = Thread.my.call.mgr.get_raw_header log "Got head #{hdr}" if hdr == "Content-Type: api/response\nContent-Length: 0" break end async_event = Thread.my.call.mgr.get_header event_name = async_event['Event-Name'] if event_name == 'DTMF' && event.on_keypress key = async_event['DTMF-String'] event.on_keypress.call(('0'..'9') === key ? key.to_i : key) elsif event_name == 'CHANNEL_EXECUTE_COMPLETE' && async_event['Core-UUID'] == execution_uuid break async_event else end end end rescue DSL::Dialplan::ReturnValue => r log "Dispatch!: Got a return value with #{r.obj}" break! raise r rescue DSL::Dialplan::Hangup Thread.my.call.mgr << "SendMsg\ncall-command: hangup" Thread.my.call.mgr.io.close rescue nil end |