Class: Artoo::Api::DeviceEventClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(websocket, topic) ⇒ DeviceEventClient

Create new event client

Parameters:

  • websocket (Socket)
  • topic (String)


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

#topicObject (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

Parameters:

  • topic (String)
  • data (Object)


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