Class: Punchblock::Translator::Asterisk::Component::Component

Inherits:
Object
  • Object
show all
Includes:
Celluloid, DeadActorSafety
Defined in:
lib/punchblock/translator/asterisk/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DeadActorSafety

#safe_from_dead_actors

Constructor Details

#initialize(component_node, call = nil) ⇒ Component

Returns a new instance of Component.



22
23
24
25
26
27
28
# File 'lib/punchblock/translator/asterisk/component.rb', line 22

def initialize(component_node, call = nil)
  @component_node, @call = component_node, call
  @call_id = safe_from_dead_actors { call.id } if call
  @id = Punchblock.new_uuid
  @complete = false
  setup
end

Instance Attribute Details

#callObject (readonly)

Returns the value of attribute call.



19
20
21
# File 'lib/punchblock/translator/asterisk/component.rb', line 19

def call
  @call
end

#call_idObject (readonly)

Returns the value of attribute call_id.



19
20
21
# File 'lib/punchblock/translator/asterisk/component.rb', line 19

def call_id
  @call_id
end

#idObject (readonly)

Returns the value of attribute id.



19
20
21
# File 'lib/punchblock/translator/asterisk/component.rb', line 19

def id
  @id
end

#internalObject

Returns the value of attribute internal.



20
21
22
# File 'lib/punchblock/translator/asterisk/component.rb', line 20

def internal
  @internal
end

Instance Method Details

#call_endedObject



62
63
64
# File 'lib/punchblock/translator/asterisk/component.rb', line 62

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

#execute_command(command) ⇒ Object



33
34
35
# File 'lib/punchblock/translator/asterisk/component.rb', line 33

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

#logger_idObject



58
59
60
# File 'lib/punchblock/translator/asterisk/component.rb', line 58

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

#send_complete_event(reason, recording = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/punchblock/translator/asterisk/component.rb', line 37

def send_complete_event(reason, recording = nil)
  return if @complete
  @complete = true
  event = Punchblock::Event::Complete.new.tap do |c|
    c.reason = reason
    c << recording if recording
  end
  send_event event
  terminate
end

#send_event(event) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/punchblock/translator/asterisk/component.rb', line 48

def send_event(event)
  event.component_id    = id
  event.target_call_id  = call_id
  if internal
    @component_node.add_event event
  else
    safe_from_dead_actors { translator.handle_pb_event event }
  end
end

#setupObject



30
31
# File 'lib/punchblock/translator/asterisk/component.rb', line 30

def setup
end