Class: Adhearsion::Translator::Asterisk::Component::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/translator/asterisk/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_node, call = nil) ⇒ Component

Returns a new instance of Component.



10
11
12
13
14
15
16
# File 'lib/adhearsion/translator/asterisk/component.rb', line 10

def initialize(component_node, call = nil)
  @component_node, @call = component_node, call
  @call_id = call.id if call
  @id = Adhearsion.new_uuid
  @complete = false
  setup
end

Instance Attribute Details

#callObject (readonly)

Returns the value of attribute call.



8
9
10
# File 'lib/adhearsion/translator/asterisk/component.rb', line 8

def call
  @call
end

#call_idObject (readonly)

Returns the value of attribute call_id.



8
9
10
# File 'lib/adhearsion/translator/asterisk/component.rb', line 8

def call_id
  @call_id
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/adhearsion/translator/asterisk/component.rb', line 8

def id
  @id
end

Instance Method Details

#call_endedObject



45
46
47
# File 'lib/adhearsion/translator/asterisk/component.rb', line 45

def call_ended
  send_complete_event Adhearsion::Event::Complete::Hangup.new
end

#execute_command(command) ⇒ Object



21
22
23
# File 'lib/adhearsion/translator/asterisk/component.rb', line 21

def execute_command(command)
  command.response = Adhearsion::ProtocolError.new.setup 'command-not-acceptable', "Did not understand command for component #{id}", call_id, id
end

#logger_idObject



41
42
43
# File 'lib/adhearsion/translator/asterisk/component.rb', line 41

def logger_id
  "#{self.class}: #{call_id ? "Call ID: #{call_id}, Component ID: #{id}" : id}"
end

#send_complete_event(reason, recording = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/adhearsion/translator/asterisk/component.rb', line 25

def send_complete_event(reason, recording = nil)
  return if @complete
  @complete = true
  event = Adhearsion::Event::Complete.new reason: reason, recording: recording
  send_event event
  call.deregister_component id if call
  translator.deregister_component id
end

#send_event(event) ⇒ Object



34
35
36
37
38
39
# File 'lib/adhearsion/translator/asterisk/component.rb', line 34

def send_event(event)
  event.component_id    = id
  event.target_call_id  = call_id
  event.source_uri      = id
  translator.handle_pb_event event
end

#setupObject



18
19
# File 'lib/adhearsion/translator/asterisk/component.rb', line 18

def setup
end