Sha256: a5269ade7a857a04e7f0810758c58396c578d9fd1bf1a4817525fb67cc93145a

Contents?: true

Size: 1.46 KB

Versions: 12

Compression:

Stored size: 1.46 KB

Contents

# encoding: utf-8

module Punchblock
  class Client
    extend ActiveSupport::Autoload

    autoload :ComponentRegistry

    include HasGuardedHandlers

    attr_reader :connection, :component_registry

    delegate :run, :stop, :send_message, :new_call_uri, :to => :connection

    # @param [Hash] options
    # @option options [Connection::XMPP] :connection The Punchblock connection to use for this session
    #
    def initialize(options = {})
      @connection = options[:connection]
      @connection.event_handler = lambda { |event| self.handle_event event } if @connection
      @component_registry = ComponentRegistry.new
    end

    def handle_event(event)
      event.client = self
      if event.source
        event.source.add_event event
      else
        trigger_handler :event, event
      end
    end

    def register_event_handler(*guards, &block)
      register_handler :event, *guards, &block
    end

    def register_component(component)
      component_registry << component
    end

    def find_component_by_uri(uri)
      component_registry.find_by_uri uri
    end

    def delete_component_registration(component)
      component_registry.delete component
    end

    def execute_command(command, options = {})
      command.client = self
      if command.respond_to?(:register_handler)
        command.register_handler :internal do |event|
          trigger_handler :event, event
        end
      end
      connection.write command, options
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/client.rb
punchblock-2.7.3 lib/punchblock/client.rb
punchblock-2.7.2 lib/punchblock/client.rb
punchblock-2.7.1 lib/punchblock/client.rb
punchblock-2.7.0 lib/punchblock/client.rb
punchblock-2.6.0 lib/punchblock/client.rb
punchblock-2.5.3 lib/punchblock/client.rb
punchblock-2.5.2 lib/punchblock/client.rb
punchblock-2.5.1 lib/punchblock/client.rb
punchblock-2.5.0 lib/punchblock/client.rb
punchblock-2.4.2 lib/punchblock/client.rb
punchblock-2.4.0 lib/punchblock/client.rb