Class: Adhearsion::CallController

Inherits:
Object
  • Object
show all
Includes:
Dial, Input, Output, Record
Defined in:
lib/adhearsion/call_controller.rb,
lib/adhearsion/call_controller/dial.rb,
lib/adhearsion/call_controller/input.rb,
lib/adhearsion/call_controller/output.rb,
lib/adhearsion/call_controller/record.rb,
lib/adhearsion/call_controller/input/result.rb,
lib/adhearsion/call_controller/output/player.rb,
lib/adhearsion/call_controller/output/formatter.rb,
lib/adhearsion/call_controller/input/menu_builder.rb,
lib/adhearsion/call_controller/output/async_player.rb,
lib/adhearsion/call_controller/input/prompt_builder.rb,
lib/adhearsion/call_controller/output/abstract_player.rb,
lib/adhearsion/call_controller/input/ask_grammar_builder.rb

Defined Under Namespace

Modules: Dial, Input, Output, Record

Constant Summary

Constants included from Record

Record::RecordError

Constants included from Output

Output::NoDocError, Output::PlaybackError

Constants included from Input

Input::InputError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Record

#record

Methods included from Output

#locale, #locale=, #output_formatter, #play, #play!, #play_audio, #play_audio!, #play_document, #play_document!, #play_numeric, #play_numeric!, #play_time, #play_time!, #say, #say!, #say_characters, #say_characters!, #t

Methods included from Input

#ask, #menu

Methods included from Dial

#dial

Constructor Details

#initialize(call, metadata = nil, &block) ⇒ CallController

Create a new instance


83
84
85
86
87
# File 'lib/adhearsion/call_controller.rb', line 83

def initialize(call,  = nil, &block)
  @call, @metadata, @block = call,  || {}, block
  @block_context = eval "self", @block.binding if @block
  @active_components = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object


89
90
91
92
93
94
95
# File 'lib/adhearsion/call_controller.rb', line 89

def method_missing(method_name, *args, &block)
  if @block_context
    @block_context.send method_name, *args, &block
  else
    super
  end
end

Instance Attribute Details

#callCall (readonly)


65
66
67
# File 'lib/adhearsion/call_controller.rb', line 65

def call
  @call
end

#metadataHash (readonly)


68
69
70
# File 'lib/adhearsion/call_controller.rb', line 68

def 
  @metadata
end

Class Method Details

.after_call(*args, &block) ⇒ Object


58
59
60
61
# File 'lib/adhearsion/call_controller.rb', line 58

def after_call(*args, &block)
  Adhearsion.deprecated :after
  after(*args, &block)
end

.before_call(*args, &block) ⇒ Object


53
54
55
56
# File 'lib/adhearsion/call_controller.rb', line 53

def before_call(*args, &block)
  Adhearsion.deprecated :before
  before(*args, &block)
end

.exec(controller) ⇒ Object

Execute a call controller, allowing passing control to another controller


42
43
44
# File 'lib/adhearsion/call_controller.rb', line 42

def exec(controller)
  controller.exec
end

.mixin(mod) ⇒ Object

Include another module into all CallController classes


49
50
51
# File 'lib/adhearsion/call_controller.rb', line 49

def mixin(mod)
  include mod
end

Instance Method Details

#answer(*args) ⇒ Object

Answer the call


241
242
243
244
# File 'lib/adhearsion/call_controller.rb', line 241

def answer(*args)
  block_until_resumed
  call.answer(*args)
end

#bg_exec(completion_callback = nil) ⇒ Object


109
110
111
112
113
114
115
# File 'lib/adhearsion/call_controller.rb', line 109

def bg_exec(completion_callback = nil)
  Celluloid::ThreadHandle.new(Celluloid.actor_system) do
    catching_standard_errors do
      exec_with_callback completion_callback
    end
  end
end

#eql?(other) ⇒ Boolean Also known as: ==


340
341
342
# File 'lib/adhearsion/call_controller.rb', line 340

def eql?(other)
  other.instance_of?(self.class) && call == other.call &&  == other.
end

#exec(controller = self) ⇒ Object

Execute the controller, allowing passing control to another controller


100
101
102
103
104
105
106
107
# File 'lib/adhearsion/call_controller.rb', line 100

def exec(controller = self)
  new_controller = catch :pass_controller do
    controller.execute!
    nil
  end

  exec new_controller if new_controller
end

#exec_with_callback(completion_callback = nil) ⇒ Object


117
118
119
120
121
# File 'lib/adhearsion/call_controller.rb', line 117

def exec_with_callback(completion_callback = nil)
  exec
ensure
  completion_callback.call call if completion_callback
end

#hangup(headers = nil) ⇒ Object

Hangup the call, and execute after callbacks

Raises:


251
252
253
254
255
# File 'lib/adhearsion/call_controller.rb', line 251

def hangup(headers = nil)
  block_until_resumed
  call.hangup headers
  raise Call::Hangup
end

#hard_pass(controller_class, metadata = nil) ⇒ Object

Cease execution of this controller, including any components it is executing, and pass to another.


186
187
188
189
190
# File 'lib/adhearsion/call_controller.rb', line 186

def hard_pass(controller_class,  = nil)
  logger.info "Hard passing with active components #{@active_components.inspect}"
  stop_all_components
  pass controller_class, 
end

#invoke(controller_class, metadata = nil) ⇒ Object

Invoke another controller class within this controller, returning to this context on completion.


152
153
154
155
# File 'lib/adhearsion/call_controller.rb', line 152

def invoke(controller_class,  = nil)
  controller = controller_class.new call, 
  controller.run
end

#join(target, options = {}) ⇒ Object

Join the call to another call or a mixer, and block until the call is unjoined (by hangup or otherwise).

Options Hash (options):

  • :async (Boolean)

    Return immediately, without waiting for the calls to unjoin. Defaults to false.

See Also:


308
309
310
311
312
313
314
# File 'lib/adhearsion/call_controller.rb', line 308

def join(target, options = {})
  block_until_resumed
  async = (target.is_a?(Hash) ? target : options).delete :async
  join = call.join target, options
  waiter = async ? join[:joined_condition] : join[:unjoined_condition]
  waiter.wait
end

#loggerObject


345
346
347
348
349
# File 'lib/adhearsion/call_controller.rb', line 345

def logger
  call.logger
rescue Celluloid::DeadActorError
  super
end

#mute(*args) ⇒ Object

Mute the call


284
285
286
287
# File 'lib/adhearsion/call_controller.rb', line 284

def mute(*args)
  block_until_resumed
  call.mute(*args)
end

#pass(controller_class, metadata = nil) ⇒ Object

Cease execution of this controller, and pass to another.


163
164
165
# File 'lib/adhearsion/call_controller.rb', line 163

def pass(controller_class,  = nil)
  throw :pass_controller, controller_class.new(call, )
end

#redirect(*args) ⇒ Object

Redirect the call to some other target


273
274
275
276
277
# File 'lib/adhearsion/call_controller.rb', line 273

def redirect(*args)
  block_until_resumed
  call.redirect(*args)
  raise Call::Hangup
end

#reject(*args) ⇒ Object

Reject the call


262
263
264
265
266
# File 'lib/adhearsion/call_controller.rb', line 262

def reject(*args)
  block_until_resumed
  call.reject(*args)
  raise Call::Hangup
end

#runObject

Invoke the block supplied when creating the controller


141
142
143
# File 'lib/adhearsion/call_controller.rb', line 141

def run
  instance_exec(&block) if block
end

#stop_all_componentsObject

Stop execution of all the components currently running in the controller.


170
171
172
173
174
175
176
177
178
# File 'lib/adhearsion/call_controller.rb', line 170

def stop_all_components
  logger.info "Stopping all controller components"
  @active_components.each do |component|
    begin
      component.stop!
    rescue Adhearsion::Rayo::Component::InvalidActionError
    end
  end
end

#unmute(*args) ⇒ Object

Unmute the call


294
295
296
297
# File 'lib/adhearsion/call_controller.rb', line 294

def unmute(*args)
  block_until_resumed
  call.unmute(*args)
end