adhearsion 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/CHANGELOG +11 -2
  2. data/EVENTS +1 -1
  3. data/Rakefile +4 -4
  4. data/adhearsion.gemspec +8 -4
  5. data/app_generators/ahn/USAGE +3 -3
  6. data/app_generators/ahn/ahn_generator.rb +11 -11
  7. data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +3 -3
  8. data/app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb +6 -6
  9. data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.rb +16 -16
  10. data/app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb +42 -42
  11. data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb +11 -11
  12. data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +1 -1
  13. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +6 -6
  14. data/app_generators/ahn/templates/components/simon_game/simon_game.rb +4 -4
  15. data/app_generators/ahn/templates/config/startup.rb +31 -16
  16. data/bin/ahn +3 -3
  17. data/bin/ahnctl +8 -8
  18. data/bin/jahn +3 -3
  19. data/examples/asterisk_manager_interface/standalone.rb +2 -2
  20. data/lib/adhearsion.rb +4 -2
  21. data/lib/adhearsion/cli.rb +31 -31
  22. data/lib/adhearsion/component_manager.rb +39 -39
  23. data/lib/adhearsion/component_manager/component_tester.rb +14 -14
  24. data/lib/adhearsion/component_manager/spec_framework.rb +1 -1
  25. data/lib/adhearsion/events_support.rb +12 -12
  26. data/lib/adhearsion/foundation/blank_slate.rb +1 -1
  27. data/lib/adhearsion/foundation/custom_daemonizer.rb +2 -2
  28. data/lib/adhearsion/foundation/event_socket.rb +26 -26
  29. data/lib/adhearsion/foundation/future_resource.rb +6 -6
  30. data/lib/adhearsion/foundation/metaprogramming.rb +2 -2
  31. data/lib/adhearsion/foundation/numeric.rb +3 -3
  32. data/lib/adhearsion/foundation/relationship_properties.rb +7 -7
  33. data/lib/adhearsion/foundation/string.rb +8 -8
  34. data/lib/adhearsion/foundation/synchronized_hash.rb +8 -8
  35. data/lib/adhearsion/host_definitions.rb +16 -16
  36. data/lib/adhearsion/initializer.rb +74 -65
  37. data/lib/adhearsion/initializer/asterisk.rb +15 -9
  38. data/lib/adhearsion/initializer/configuration.rb +54 -39
  39. data/lib/adhearsion/initializer/database.rb +4 -4
  40. data/lib/adhearsion/initializer/drb.rb +6 -6
  41. data/lib/adhearsion/initializer/freeswitch.rb +1 -1
  42. data/lib/adhearsion/initializer/ldap.rb +51 -0
  43. data/lib/adhearsion/initializer/rails.rb +8 -8
  44. data/lib/adhearsion/logging.rb +16 -16
  45. data/lib/adhearsion/tasks/deprecations.rb +12 -12
  46. data/lib/adhearsion/tasks/generating.rb +2 -2
  47. data/lib/adhearsion/tasks/testing.rb +7 -7
  48. data/lib/adhearsion/version.rb +1 -1
  49. data/lib/adhearsion/voip/asterisk/agi_server.rb +44 -14
  50. data/lib/adhearsion/voip/asterisk/commands.rb +281 -237
  51. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +8 -8
  52. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +14 -14
  53. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +16 -16
  54. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +39 -39
  55. data/lib/adhearsion/voip/asterisk/config_manager.rb +13 -13
  56. data/lib/adhearsion/voip/asterisk/manager_interface.rb +91 -87
  57. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +739 -739
  58. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +60 -60
  59. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +16 -16
  60. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +1 -1
  61. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +13 -13
  62. data/lib/adhearsion/voip/asterisk/super_manager.rb +3 -3
  63. data/lib/adhearsion/voip/call.rb +101 -64
  64. data/lib/adhearsion/voip/call_routing.rb +9 -9
  65. data/lib/adhearsion/voip/constants.rb +7 -7
  66. data/lib/adhearsion/voip/conveniences.rb +1 -1
  67. data/lib/adhearsion/voip/dial_plan.rb +42 -40
  68. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +27 -27
  69. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +1 -1
  70. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +6 -6
  71. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +17 -17
  72. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +7 -7
  73. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +2 -2
  74. data/lib/adhearsion/voip/dsl/numerical_string.rb +3 -3
  75. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +7 -7
  76. data/lib/adhearsion/voip/freeswitch/event_handler.rb +1 -1
  77. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +20 -20
  78. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +5 -5
  79. data/lib/adhearsion/voip/freeswitch/oes_server.rb +33 -33
  80. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +1 -1
  81. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +2 -2
  82. data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +9 -9
  83. data/lib/theatre.rb +18 -18
  84. data/lib/theatre/callback_definition_loader.rb +17 -17
  85. data/lib/theatre/guid.rb +6 -6
  86. data/lib/theatre/invocation.rb +19 -19
  87. data/lib/theatre/namespace_manager.rb +28 -28
  88. metadata +55 -14
@@ -4,7 +4,7 @@ module Adhearsion
4
4
  class DialingDSL
5
5
  module MonkeyPatches
6
6
  module RegexpMonkeyPatch
7
-
7
+
8
8
  def |(other)
9
9
  case other
10
10
  when RouteRule
@@ -2,24 +2,24 @@ module Adhearsion
2
2
  module VoIP
3
3
  module DSL
4
4
  module Dialplan
5
- # A ControlPassingException is used internally to stop execution of one
6
- # dialplan context and begin execution of another proc instead. It is
5
+ # A ControlPassingException is used internally to stop execution of one
6
+ # dialplan context and begin execution of another proc instead. It is
7
7
  # most notably used by the ~@ unary operator that can be called on a
8
8
  # context name within a dialplan to transfer control entirely to that
9
9
  # particular context. The serve() method in the servlet_container actually
10
10
  # rescues these exceptions specifically and then does +e.target to execute
11
11
  # that code.
12
12
  class ControlPassingException < Exception
13
-
13
+
14
14
  attr_reader :target
15
-
15
+
16
16
  def initialize(target)
17
17
  super()
18
18
  @target = target
19
19
  end
20
-
20
+
21
21
  end
22
-
22
+
23
23
  class ContextNotFoundException < Exception; end
24
24
  end
25
25
  end
@@ -2,7 +2,7 @@ module Adhearsion
2
2
  module VoIP
3
3
  module DSL
4
4
  module Dialplan
5
-
5
+
6
6
  class ReturnValue < Exception
7
7
  attr_reader :obj
8
8
  def initialize(obj)
@@ -10,34 +10,34 @@ module Adhearsion
10
10
  super
11
11
  end
12
12
  end
13
-
13
+
14
14
  class Hangup < Exception; end
15
-
15
+
16
16
  # Instantiated and returned in every dialplan command
17
17
  class EventCommand
18
-
18
+
19
19
  attr_accessor :app, :args, :response_block, :returns, :on_keypress
20
-
20
+
21
21
  def initialize(app, *args, &block)
22
22
  @hash = args.pop if args.last.kind_of?(Hash)
23
23
  @app, @args = app, args
24
-
24
+
25
25
  if @hash
26
- @returns = @hash[:returns] || :raw
26
+ @returns = @hash[:returns] || :raw
27
27
  @on_keypress = @hash[:on_keypress]
28
28
  end
29
-
29
+
30
30
  @response_block = block if block_given?
31
31
  end
32
-
32
+
33
33
  def on_keypress(&block)
34
34
  block_given? ? @on_keypress = block : @on_keypress
35
35
  end
36
-
36
+
37
37
  def on_break(&block)
38
38
  block_given? ? @on_break = block : @on_break
39
39
  end
40
-
40
+
41
41
  end
42
42
 
43
43
  class NoOpEventCommand < EventCommand
@@ -57,7 +57,7 @@ module Adhearsion
57
57
  # every command must start with "api", but, when doing an originate, it
58
58
  # must begin with an ampersand. These two pre-processors would be developed
59
59
  # as separate CommandDispatchers.
60
- class CommandDispatcher
60
+ class CommandDispatcher
61
61
 
62
62
  attr_reader :factory, :context
63
63
 
@@ -84,13 +84,13 @@ module Adhearsion
84
84
  end
85
85
  dispatched_command
86
86
  else
87
- command
87
+ command
88
88
  end
89
89
  end.last
90
90
  rescue ReturnValue => r
91
91
  return r.obj
92
92
  end
93
-
93
+
94
94
  def return!(obj)
95
95
  raise DSL::Dialplan::ReturnValue.new(obj)
96
96
  end
@@ -98,7 +98,7 @@ module Adhearsion
98
98
  def break!(uuid=@context)
99
99
  raise NotImplementedError, "Must subclass #{self.class} and override this!"
100
100
  end
101
-
101
+
102
102
  # Takes a Hash and meta_def()'s a method for each key that returns
103
103
  # the key's value in the Hash.
104
104
  def def_keys!(hash)
@@ -106,7 +106,7 @@ module Adhearsion
106
106
  meta_def(k) { v } rescue nil
107
107
  end
108
108
  end
109
-
109
+
110
110
  def clone
111
111
  returning super do |nemesis|
112
112
  instance_variables.each do |iv|
@@ -115,7 +115,7 @@ module Adhearsion
115
115
  end
116
116
  end
117
117
  end
118
-
118
+
119
119
  end
120
120
 
121
121
  end
@@ -6,22 +6,22 @@ module Adhearsion
6
6
  module Dialplan
7
7
  #TODO: This is obsolete, but we still need it for Freeswitch until we port that to the new 0.8.0 APIs
8
8
  module DialplanParser
9
-
9
+
10
10
  # Create a container and then clone that. when the container is created
11
11
  # it should have all the contexts meta_def'd into it. for each call coming
12
12
  # in, the cloned copy has the variables meta_def'd and set as instance
13
13
  # variables
14
-
14
+
15
15
  #TODO: separate into smaller pieces
16
16
  def self.get_contexts
17
17
  envelope = ContextsEnvelope.new
18
-
18
+
19
19
  dialplans = AHN_CONFIG.files_from_setting "paths", "dialplan"
20
20
  ahn_log.dialplan.warn "No dialplan files were found!" if dialplans.empty?
21
-
21
+
22
22
  returning({}) do |contexts|
23
23
  dialplans.each do |file|
24
- raise "Dialplan file #{file} does not exist!" unless File.exists? file
24
+ raise "Dialplan file #{file} does not exist!" unless File.exists? file
25
25
  envelope.instance_eval do
26
26
  eval File.read(file)
27
27
  end
@@ -42,7 +42,7 @@ module Adhearsion
42
42
  end
43
43
  end
44
44
  end
45
-
45
+
46
46
  class ContextsEnvelope
47
47
 
48
48
  keep = %w"__send__ __id__ define_method instance_eval meta_def meta_eval metaclass"
@@ -65,7 +65,7 @@ module Adhearsion
65
65
  end
66
66
 
67
67
  end
68
-
68
+
69
69
  end
70
70
  end
71
71
  end
@@ -4,11 +4,11 @@ module Adhearsion
4
4
  module DSL
5
5
  module Dialplan
6
6
  module ThreadMixin
7
-
7
+
8
8
  def call
9
9
  @thread_call_struct ||= OpenStruct.new
10
10
  end
11
-
11
+
12
12
  end
13
13
  end
14
14
  end
@@ -3,13 +3,13 @@ module Adhearsion
3
3
  module DSL
4
4
  # In Ruby, a number with a leading zero such as 023.45 or 023 does not evaluate as expected.
5
5
  # In the case of the float 023.45, you get a syntax error. In the case of 023 the number is
6
- # parsed as being in octal form and the number 19 is returned.
6
+ # parsed as being in octal form and the number 19 is returned.
7
7
  #
8
8
  # In Adhearsion, various strings that are entirely numeric might start with zero and that zero
9
- # should be preserved when converting that string of numbers into a number. The numerical string
9
+ # should be preserved when converting that string of numbers into a number. The numerical string
10
10
  # retains the zero while still allowing it to be compared to other numbers.
11
11
  #
12
- # [[I think this leading zero thing is only part of the reason that NumericalString exists. I'm
12
+ # [[I think this leading zero thing is only part of the reason that NumericalString exists. I'm
13
13
  # currently writing tests for this leading zero stuff so I thought I'd dump some of my assumptions
14
14
  # about it here in the documentation.]]
15
15
  class NumericalString
@@ -1,22 +1,22 @@
1
1
  module Adhearsion
2
2
  module VoIP
3
3
  module FreeSwitch
4
-
4
+
5
5
  class BasicConnectionManager
6
6
 
7
7
  def initialize(io)
8
8
  @io = io
9
9
  end
10
-
10
+
11
11
  # The send-command operator
12
12
  def <<(str)
13
13
  @io.write str + "\n\n"
14
14
  end
15
-
15
+
16
16
  def get_header
17
17
  separate_pairs get_raw_header
18
18
  end
19
-
19
+
20
20
  def get_raw_header
21
21
  (returning [] do |lines|
22
22
  until line = @io.gets and line.chomp.empty?
@@ -31,7 +31,7 @@ module Adhearsion
31
31
  # puts "Reading an event of #{length} bytes"
32
32
  separate_pairs @io.read(length)
33
33
  end
34
-
34
+
35
35
  def separate_pairs(lines)
36
36
  lines.inject({}) do |h,line|
37
37
  returning h do |hash|
@@ -40,9 +40,9 @@ module Adhearsion
40
40
  end
41
41
  end
42
42
  end
43
-
43
+
44
44
  end
45
-
45
+
46
46
  end
47
47
  end
48
48
  end
@@ -51,7 +51,7 @@ module Adhearsion
51
51
  def self.on(event, &block)
52
52
  event = event.underscore.to_sym if event.is_a? String
53
53
  (event.kind_of?(Hash) ? @@compound_events : @@events)[event] = block
54
- end
54
+ end
55
55
  end
56
56
  end
57
57
  end
@@ -4,30 +4,30 @@ module Adhearsion
4
4
  module VoIP
5
5
  module FreeSwitch
6
6
  class FreeSwitchDialplanCommandFactory
7
-
7
+
8
8
  def initialize(context=nil)
9
9
  @context = context
10
10
  end
11
-
11
+
12
12
  # These should all return those objects...
13
13
  def speak(text, hash={})
14
14
  voice, engine = hash[:voice] || "Dianne", hash[:engine] || "cepstral"
15
-
15
+
16
16
  dtmf = hash[:on_keypress]
17
17
  speak_cmd = cmd 'speak', "#{engine}|#{voice}|%p" % text, :on_keypress => dtmf
18
-
18
+
19
19
  if hash[:timeout] == 0
20
20
  [speak_cmd, DSL::Dialplan::NoOpEventCommand.new(hash[:timeout], :on_keypress => dtmf)]
21
21
  else
22
22
  puts "Returning the normal speak command"
23
- speak_cmd
23
+ speak_cmd
24
24
  end
25
25
  end
26
-
26
+
27
27
  def set(key, value)
28
28
  cmd 'set', "#{key}=#{value}"
29
29
  end
30
-
30
+
31
31
  def play(*files)
32
32
  hash = files.last.kind_of?(Hash) ? files.pop : {}
33
33
  conference, to = hash[:conference], hash[:to]
@@ -48,27 +48,27 @@ module Adhearsion
48
48
  files.map { |file| cmd('playback', file) }
49
49
  end
50
50
  end
51
-
51
+
52
52
  def join(id)
53
53
  DSL::Dialplan::ExitingEventCommand.new "conference", id.to_s
54
54
  end
55
-
55
+
56
56
  def hangup!
57
57
  cmd "exit"
58
58
  end
59
-
59
+
60
60
  def return!(obj)
61
61
  raise DSL::Dialplan::ReturnValue.new(obj)
62
62
  end
63
-
63
+
64
64
  def hangup!
65
65
  raise DSL::Dialplan::Hangup
66
66
  end
67
-
67
+
68
68
  def wait(seconds=nil, &block)
69
69
  DSL::Dialplan::NoOpEventCommand.new(seconds)
70
70
  end
71
-
71
+
72
72
  def record(hash={}, &block)
73
73
  # TODO: Could want to record a conference or a UUID
74
74
  p hash
@@ -76,13 +76,13 @@ module Adhearsion
76
76
  cmd 'stop_record_session', hash[:stop]
77
77
  else
78
78
  file = hash[:file] || File.join(Dir::tmpdir, String.random(32), '.wav')
79
-
79
+
80
80
  raise "Cannot supply both a timeout and a block!" if hash[:timeout] && block_given?
81
-
81
+
82
82
  dtmf_breaker = lambda do |digit|
83
83
  return! file if digit == hash[:break_on]
84
84
  end
85
-
85
+
86
86
  rec_cmd = cmd "record", file, :on_keypress => dtmf_breaker
87
87
  returning [] do |cmds|
88
88
  cmds << play('beep') if hash[:beep]
@@ -99,7 +99,7 @@ module Adhearsion
99
99
  end
100
100
  end
101
101
  end
102
-
102
+
103
103
  def input(number=nil, hash={})
104
104
  timeout, file = hash[:timeout], hash[:play] || hash[:file]
105
105
  break_on = hash[:break_on] || '#'
@@ -116,13 +116,13 @@ module Adhearsion
116
116
  command.on_keypress &dtmf_hook
117
117
  end
118
118
  end
119
-
119
+
120
120
  private
121
-
121
+
122
122
  def cmd(*args, &block)
123
123
  DSL::Dialplan::EventCommand.new(*args, &block)
124
124
  end
125
-
125
+
126
126
  end
127
127
  end
128
128
  end
@@ -3,9 +3,9 @@ module Adhearsion
3
3
  module VoIP
4
4
  module FreeSwitch
5
5
  class InboundConnectionManager < BasicConnectionManager
6
-
6
+
7
7
  DEFAULTS = { :pass => "ClueCon", :host => '127.0.0.1', :port => 8021 }
8
-
8
+
9
9
  def initialize(arg)
10
10
  if arg.kind_of? Hash
11
11
  @opts = DEFAULTS.merge arg
@@ -19,19 +19,19 @@ module Adhearsion
19
19
  super @io
20
20
  end
21
21
  end
22
-
22
+
23
23
  def enable_events!(which='ALL')
24
24
  self << "event plain #{which}"
25
25
  get_raw_header
26
26
  end
27
-
27
+
28
28
  # Only called when nothing has been sent over the socket.
29
29
  def login(pass)
30
30
  get_raw_header
31
31
  self << "auth #{pass}"
32
32
  get_raw_header.include? "+OK"
33
33
  end
34
-
34
+
35
35
  end
36
36
  end
37
37
  end
@@ -10,65 +10,65 @@ module Adhearsion
10
10
  module VoIP
11
11
  module FreeSwitch
12
12
  class OesServer < GServer
13
-
13
+
14
14
  def initialize(port, host=nil)
15
15
  @port, @host = port || 4572, host || "0.0.0.0"
16
16
  @cache_lock = Mutex.new
17
17
  super @port, @host, (1.0/0.0)
18
18
  log "Starting FreeSwitch OES Server"
19
19
  end
20
-
20
+
21
21
  def serve(io)
22
-
22
+
23
23
  log "Incoming call on the FreeSwitch outbound event socket..."
24
24
  Thread.me.extend DSL::Dialplan::ThreadMixin
25
25
  Thread.me.call.io = io
26
26
  conn = BasicConnectionManager.new io
27
-
27
+
28
28
  Thread.my.call.mgr = conn
29
29
  conn << "connect"
30
30
  @vars = conn.get_header
31
31
  answered = @vars['variable_endpoint_disposition'] == "ANSWER"
32
-
32
+
33
33
  conn << "myevents"
34
34
  myevents_response = conn.get_header
35
35
  answered ||= myevents_response['Event-Name'] == 'CHANNEL_ANSWER'
36
-
36
+
37
37
  log "Connected to Freeswitch. Waiting for answer state."
38
-
38
+
39
39
  until answered
40
40
  answered ||= conn.get_header['Event-Name'] == 'CHANNEL_ANSWER'
41
41
  end
42
-
42
+
43
43
  log "Loading cached dialplan"
44
44
  contexts, dispatcher = cached_dialplan_data
45
45
  log "Finished loading cached dialplans"
46
-
46
+
47
47
  first_context_name = @vars['variable_context'] || @vars["Channel-Context"]
48
48
  first_context = contexts[first_context_name.to_sym]
49
-
49
+
50
50
  log "Found context #{first_context_name} from call variables."
51
-
51
+
52
52
  # If the target context does not exist, warn and don't handle the call
53
53
  unless first_context
54
54
  log "No context '#{first_context_name}' found in " +
55
55
  "#{AHN_CONFIG.files_from_setting("paths", "").to_sentence(:connector => "or")}. Ignoring request!"
56
56
  return
57
57
  end
58
-
58
+
59
59
  # Enable events
60
-
60
+
61
61
  # Now that we have the code, let's dispatch it back.
62
-
62
+
63
63
  pretty_vars = rubyize_keys_for @vars
64
64
  dispatcher.def_keys! pretty_vars
65
65
  dispatcher.instance_eval(&first_context.block)
66
-
66
+
67
67
  rescue => e
68
68
  p e
69
69
  puts e.backtrace.map {|x| " " * 4 + x }
70
70
  end
71
-
71
+
72
72
  def cached_dialplan_data
73
73
  @cache_lock.synchronize do
74
74
  log "Checking whether the contexts should be reloaded"
@@ -79,33 +79,33 @@ module Adhearsion
79
79
  @abstract_dispatcher = OesDispatcher.new @vars['Channel-Unique-ID']
80
80
  log "Done creating it"
81
81
  @abstract_dispatcher.def_keys! @abstract_contexts
82
- else
82
+ else
83
83
  log "Should not reload context."
84
84
  @abstract_dispatcher.instance_variable_set :@uuid, @vars['Channel-Unique-ID']
85
85
  end
86
86
  return [@abstract_contexts.clone, @abstract_dispatcher.clone]
87
87
  end
88
88
  end
89
-
89
+
90
90
  # TODO. This is broken. Always returns true. Should cache the last reload
91
91
  # time.
92
92
  def should_reload_contexts?
93
93
  !@abstract_contexts || !@abstract_dispatcher ||
94
94
  AHN_CONFIG.files_from_setting("paths", "dialplan").map { |x| File.mtime(x) }.max < Time.now
95
95
  end
96
-
96
+
97
97
  def rubyize_keys_for(hash)
98
98
  returning({}) do |pretty|
99
99
  hash.each { |k,v| pretty[k.to_s.underscore] = v }
100
100
  end
101
101
  end
102
-
102
+
103
103
  class OesDispatcher < DSL::Dialplan::CommandDispatcher
104
-
104
+
105
105
  def initialize(uuid=nil)
106
106
  super FreeSwitchDialplanCommandFactory, uuid
107
107
  end
108
-
108
+
109
109
  def dispatch!(event)
110
110
  if event.kind_of?(DSL::Dialplan::NoOpEventCommand) && event.on_keypress
111
111
  return_value = nil
@@ -128,37 +128,37 @@ module Adhearsion
128
128
  end
129
129
  else dispatch.call
130
130
  end
131
-
131
+
132
132
  else
133
133
  log "Not a noop. Sending #{event.app}(#{event.args.to_a * " "})"
134
- Thread.my.call.mgr << "SendMsg\ncall-command: execute\nexecute-app-name: " +
134
+ Thread.my.call.mgr << "SendMsg\ncall-command: execute\nexecute-app-name: " +
135
135
  "#{event.app}\nexecute-app-arg: #{event.args.to_a * " "}"
136
-
136
+
137
137
  if event.kind_of? DSL::Dialplan::ExitingEventCommand
138
138
  Thread.my.call.io.close
139
139
  Thread.me.exit
140
140
  end
141
-
141
+
142
142
  # Useless "command/reply" +OK and content-length headers
143
143
  lambda do
144
144
  Thread.my.call.mgr.get_raw_header
145
145
  redo if Thread.my.call.mgr.get_header['Event-Name'] == "CHANNEL_EXECUTE_COMPLETE"
146
146
  end.call
147
-
147
+
148
148
  # Main event information. Keep track of the Core-UUID and wait for
149
149
  # it to come back to us as a CHANNEL_EXECUTE_COMPLETE event.
150
150
  execution_header = Thread.my.call.mgr.get_header
151
151
  execution_uuid = execution_header['Core-UUID']
152
-
152
+
153
153
  loop do
154
154
  log "Waiting for either a DTMF or the app to finish"
155
155
  hdr = Thread.my.call.mgr.get_raw_header
156
156
  log "Got head #{hdr}"
157
-
157
+
158
158
  if hdr == "Content-Type: api/response\nContent-Length: 0"
159
159
  break
160
160
  end
161
-
161
+
162
162
  async_event = Thread.my.call.mgr.get_header
163
163
  event_name = async_event['Event-Name']
164
164
  if event_name == 'DTMF' && event.on_keypress
@@ -167,7 +167,7 @@ module Adhearsion
167
167
  elsif event_name == 'CHANNEL_EXECUTE_COMPLETE' && async_event['Core-UUID'] == execution_uuid
168
168
  break async_event
169
169
  else
170
-
170
+
171
171
  end
172
172
  end
173
173
  end
@@ -179,7 +179,7 @@ module Adhearsion
179
179
  Thread.my.call.mgr << "SendMsg\ncall-command: hangup"
180
180
  Thread.my.call.mgr.io.close rescue nil
181
181
  end
182
-
182
+
183
183
  def break!(uuid=@context)
184
184
  log "Breaking with #{uuid}"
185
185
  Thread.my.call.mgr << "api break #{uuid}"
@@ -188,7 +188,7 @@ module Adhearsion
188
188
  # Thread.my.call.mgr.get_raw_header
189
189
  end
190
190
  end
191
-
191
+
192
192
  end
193
193
  end
194
194
  end