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(connection, topic) ⇒ DeviceEventClient
constructor
Create new event client.
-
#notify_event(topic, *data) ⇒ Object
Event notification.
Constructor Details
#initialize(connection, topic) ⇒ DeviceEventClient
Create new event client
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/artoo/api/device_event_client.rb', line 19 def initialize(connection, topic) @io = Reel::Response::Writer.new(connection.socket) connection.detach connection.respond(:ok, { 'Content-Type' => 'text/event-stream', 'Connection' => 'keep-alive', 'Transfer-Encoding' => 'chunked', 'Cache-Control' => 'no-cache' }) subscribe(topic, :notify_event) end |
Instance Attribute Details
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
14 15 16 |
# File 'lib/artoo/api/device_event_client.rb', line 14 def topic @topic end |
Instance Method Details
#notify_event(topic, *data) ⇒ Object
Event notification
37 38 39 |
# File 'lib/artoo/api/device_event_client.rb', line 37 def notify_event(topic, *data) @io.write "data: #{JSON.dump(data[0])}\n\n" end |