class Artoo::Api::DeviceEventClient
The Artoo::Api::DeviceEventClient
class is how a websocket client can subscribe to event notifications for a specific device. Example: ardrone nav data
Attributes
topic[R]
Public Class Methods
new(connection, topic)
click to toggle source
Create new event client @param [Socket] websocket @param [String] topic
# 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
Public Instance Methods
notify_event(topic, *data)
click to toggle source
Event notification @param [String] topic @param [Object] data
# 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