Sha256: 7ac9fcfd502c0fe98b91b96a546265dc5371582987fd7bae508a9cfb371e07bd

Contents?: true

Size: 1011 Bytes

Versions: 22

Compression:

Stored size: 1011 Bytes

Contents

module Artoo
  module Api
    # The Artoo::Api::DeviceEventClient class is how a websocket client can subscribe
    # to event notifications for a specific device.
    # Example: ardrone nav data
    class DeviceEventClient
      include Celluloid
      include Celluloid::Notifications
      include Celluloid::Logger

      attr_reader :topic

      # Create new event client
      # @param [Socket] websocket
      # @param [String] topic
      def initialize(websocket, topic)
        @topic = topic
        info "Streaming #{@topic} to websocket..."
        @socket = websocket
        subscribe(@topic, :notify_event)
      end

      # Event notification
      # @param [String] topic
      # @param [Object] data
      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
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
artoo-1.6.6 lib/artoo/api/device_event_client.rb
artoo-1.6.5 lib/artoo/api/device_event_client.rb
artoo-1.6.4 lib/artoo/api/device_event_client.rb
artoo-1.6.3 lib/artoo/api/device_event_client.rb
artoo-1.6.2 lib/artoo/api/device_event_client.rb
artoo-1.6.1 lib/artoo/api/device_event_client.rb
artoo-1.6.0 lib/artoo/api/device_event_client.rb
artoo-1.5.0 lib/artoo/api/device_event_client.rb
artoo-1.4.1 lib/artoo/api/device_event_client.rb
artoo-1.4.0 lib/artoo/api/device_event_client.rb
artoo-1.3.0 lib/artoo/api/device_event_client.rb
artoo-1.2.2 lib/artoo/api/device_event_client.rb
artoo-1.2.1 lib/artoo/api/device_event_client.rb
artoo-1.2.0 lib/artoo/api/device_event_client.rb
artoo-1.1.1 lib/artoo/api/device_event_client.rb
artoo-1.1.0 lib/artoo/api/device_event_client.rb
artoo-1.1.0.pre lib/artoo/api/device_event_client.rb
artoo-1.0.0 lib/artoo/api/device_event_client.rb
artoo-1.0.0.rc4 lib/artoo/api/device_event_client.rb
artoo-1.0.0.rc3 lib/artoo/api/device_event_client.rb