Class: Artoo::DeviceEventClient

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger, Celluloid::Notifications
Defined in:
lib/artoo/device_event_client.rb

Overview

The Artoo::DeviceEventClient class is how a websocket client can subscribe to event notifications for a specific device. Example: ardrone nav data

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Celluloid

#timers

Constructor Details

#initialize(websocket, topic) ⇒ DeviceEventClient

Returns a new instance of DeviceEventClient.



12
13
14
15
16
17
# File 'lib/artoo/device_event_client.rb', line 12

def initialize(websocket, topic)
  @topic = topic
  info "Streaming #{@topic} to websocket..."
  @socket = websocket
  subscribe(@topic, :notify_event)
end

Instance Attribute Details

#topicObject (readonly)

Returns the value of attribute topic.



10
11
12
# File 'lib/artoo/device_event_client.rb', line 10

def topic
  @topic
end

Instance Method Details

#notify_event(topic, *data) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/artoo/device_event_client.rb', line 19

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