Class: Punchblock::Translator::Freeswitch::Component::Component

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

Direct Known Subclasses

AbstractOutput, Input, Record

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.



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

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.



21
22
23
# File 'lib/punchblock/translator/freeswitch/component.rb', line 21

def call
  @call
end

#call_idObject (readonly)

Returns the value of attribute call_id.



21
22
23
# File 'lib/punchblock/translator/freeswitch/component.rb', line 21

def call_id
  @call_id
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/punchblock/translator/freeswitch/component.rb', line 21

def id
  @id
end

Instance Method Details

#application(appname, options = nil) ⇒ Object



67
68
69
# File 'lib/punchblock/translator/freeswitch/component.rb', line 67

def application(appname, options = nil)
  call.application appname, "%[punchblock_component_id=#{id}]#{options}"
end

#call_endedObject



63
64
65
# File 'lib/punchblock/translator/freeswitch/component.rb', line 63

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

#execute_command(command) ⇒ Object



34
35
36
# File 'lib/punchblock/translator/freeswitch/component.rb', line 34

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

#handle_es_event(event) ⇒ Object



38
39
40
# File 'lib/punchblock/translator/freeswitch/component.rb', line 38

def handle_es_event(event)
  trigger_handler :es, event
end

#logger_idObject



59
60
61
# File 'lib/punchblock/translator/freeswitch/component.rb', line 59

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

#send_complete_event(reason, recording = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/punchblock/translator/freeswitch/component.rb', line 42

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



53
54
55
56
57
# File 'lib/punchblock/translator/freeswitch/component.rb', line 53

def send_event(event)
  event.component_id    = id
  event.target_call_id  = call_id
  safe_from_dead_actors { translator.handle_pb_event event }
end

#setupObject



31
32
# File 'lib/punchblock/translator/freeswitch/component.rb', line 31

def setup
end