Class: Artoo::Api::DeviceEventClient
- Inherits:
-
Object
- Object
- Artoo::Api::DeviceEventClient
- Includes:
- Celluloid, Celluloid::Logger, Celluloid::Notifications
- Defined in:
- lib/artoo/api/device_event_client.rb
Overview
The Artoo::Api::DeviceEventClient class is how a websocket client can subscribe to event notifications for a specific device. Example: ardrone nav data
Instance Attribute Summary collapse
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(websocket, topic) ⇒ DeviceEventClient
constructor
Create new event client.
-
#notify_event(topic, *data) ⇒ Object
Event notification.
Constructor Details
#initialize(websocket, topic) ⇒ DeviceEventClient
Create new event client
16 17 18 19 20 21 |
# File 'lib/artoo/api/device_event_client.rb', line 16 def initialize(websocket, topic) @topic = topic info "Streaming #{@topic} to websocket..." @socket = websocket subscribe(@topic, :notify_event) end |
Instance Attribute Details
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
11 12 13 |
# File 'lib/artoo/api/device_event_client.rb', line 11 def topic @topic end |
Instance Method Details
#notify_event(topic, *data) ⇒ Object
Event notification
26 27 28 29 30 31 32 |
# File 'lib/artoo/api/device_event_client.rb', line 26 def notify_event(topic, *data) # TODO: send which topic sent the notification @socket << data.last.to_s rescue Reel::SocketError, Errno::EPIPE info "Device event notification #{topic} websocket disconnected" terminate end |