Class: Punchblock::Component::ComponentNode

Inherits:
Punchblock::CommandNode show all
Includes:
HasGuardedHandlers
Defined in:
lib/punchblock/component/component_node.rb

Instance Attribute Summary

Attributes inherited from RayoNode

#call_id, #client, #component_id, #connection, #domain, #mixer_name, #original_component

Instance Method Summary collapse

Methods inherited from Punchblock::CommandNode

new, #response, #write_attr

Methods inherited from RayoNode

class_from_registration, #eql?, import, #inspect, #inspect_attributes, new, register, #source

Constructor Details

#initialize(*args) ⇒ ComponentNode

Returns a new instance of ComponentNode.



6
7
8
9
10
# File 'lib/punchblock/component/component_node.rb', line 6

def initialize(*args)
  super
  @complete_event_resource = FutureResource.new
  register_internal_handlers
end

Instance Method Details

#add_event(event) ⇒ Object



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

def add_event(event)
  trigger_handler :internal, event
end

#complete_event(timeout = nil) ⇒ Object



44
45
46
# File 'lib/punchblock/component/component_node.rb', line 44

def complete_event(timeout = nil)
  @complete_event_resource.resource timeout
end

#complete_event=(other) ⇒ Object



48
49
50
51
52
# File 'lib/punchblock/component/component_node.rb', line 48

def complete_event=(other)
  return if @complete_event_resource.set_yet?
  @complete_event_resource.resource = other
  complete!
end

#register_event_handler(*guards, &block) ⇒ Object



27
28
29
# File 'lib/punchblock/component/component_node.rb', line 27

def register_event_handler(*guards, &block)
  register_handler :event, *guards, &block
end

#register_internal_handlersObject



12
13
14
15
16
17
# File 'lib/punchblock/component/component_node.rb', line 12

def register_internal_handlers
  register_handler :internal, Event::Complete do |event|
    self.complete_event = event
    throw :pass
  end
end

#response=(other) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/punchblock/component/component_node.rb', line 36

def response=(other)
  if other.is_a?(Ref)
    @component_id = other.id
    client.register_component self if client
  end
  super
end

#stop!(options = {}) ⇒ Object

Sends an Rayo stop message for the current component

Raises:



66
67
68
69
# File 'lib/punchblock/component/component_node.rb', line 66

def stop!(options = {})
  raise InvalidActionError, "Cannot stop a #{self.class.name.split("::").last} that is not executing" unless executing?
  stop_action.tap { |action| write_action action }
end

#stop_actionStop

Create an Rayo stop message

Returns:

  • (Stop)

    an Rayo stop message



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

def stop_action
  Stop.new :component_id => component_id, :call_id => call_id
end

#trigger_event_handler(event) ⇒ Object



23
24
25
# File 'lib/punchblock/component/component_node.rb', line 23

def trigger_event_handler(event)
  trigger_handler :event, event
end

#write_action(action) ⇒ Object



31
32
33
34
# File 'lib/punchblock/component/component_node.rb', line 31

def write_action(action)
  client.execute_command action, :call_id => call_id, :component_id => component_id
  action
end