Class: Adhearsion::Rayo::Client
- Inherits:
-
Object
- Object
- Adhearsion::Rayo::Client
show all
- Includes:
- HasGuardedHandlers
- Defined in:
- lib/adhearsion/rayo/client.rb,
lib/adhearsion/rayo/client/component_registry.rb
Defined Under Namespace
Classes: ComponentRegistry
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
18
19
20
21
22
|
# File 'lib/adhearsion/rayo/client.rb', line 18
def initialize(options = {})
@connection = options[:connection]
@connection.event_handler = lambda { |event| self.handle_event event } if @connection
@component_registry = ComponentRegistry.new
end
|
Instance Attribute Details
#component_registry ⇒ Object
Returns the value of attribute component_registry.
11
12
13
|
# File 'lib/adhearsion/rayo/client.rb', line 11
def component_registry
@component_registry
end
|
#connection ⇒ Object
Returns the value of attribute connection.
11
12
13
|
# File 'lib/adhearsion/rayo/client.rb', line 11
def connection
@connection
end
|
Instance Method Details
#delete_component_registration(component) ⇒ Object
45
46
47
|
# File 'lib/adhearsion/rayo/client.rb', line 45
def delete_component_registration(component)
component_registry.delete component
end
|
#execute_command(command, options = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/adhearsion/rayo/client.rb', line 49
def execute_command(command, options = {})
command.client = self
if command.respond_to?(:register_handler)
command.register_handler :internal do |event|
trigger_handler :event, event
end
end
connection.write command, options
end
|
#find_component_by_uri(uri) ⇒ Object
41
42
43
|
# File 'lib/adhearsion/rayo/client.rb', line 41
def find_component_by_uri(uri)
component_registry.find_by_uri uri
end
|
#handle_event(event) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/adhearsion/rayo/client.rb', line 24
def handle_event(event)
event.client = self
if event.source
event.source.add_event event
else
trigger_handler :event, event
end
end
|
#register_component(component) ⇒ Object
37
38
39
|
# File 'lib/adhearsion/rayo/client.rb', line 37
def register_component(component)
component_registry << component
end
|
#register_event_handler(*guards, &block) ⇒ Object
33
34
35
|
# File 'lib/adhearsion/rayo/client.rb', line 33
def register_event_handler(*guards, &block)
register_handler :event, *guards, &block
end
|