Sha256: 23cab194d3afe7dddfd6a85b90c798e76899f7e3232e8a2b6fec4b20e0fbfc0c

Contents?: true

Size: 1.45 KB

Versions: 16

Compression:

Stored size: 1.45 KB

Contents

require 'faye/websocket'
require 'eventmachine'

module Slack
  module RealTime
    module Concurrency
      module Eventmachine
        class Client < Faye::WebSocket::Client
          attr_reader :logger
          protected :logger

          def initialize(url, protocols = nil, options = {})
            @logger = options.delete(:logger) || Slack::RealTime::Config.logger || Slack::Config.logger
            super
          end

          def parse(data)
            logger.debug("#{self.class}##{__method__}") { data }
            super data
          end

          def write(data)
            logger.debug("#{self.class}##{__method__}") { data }
            super data
          end
        end

        class Socket < Slack::RealTime::Socket
          def start_async(client)
            thread = ensure_reactor_running

            client.run_loop

            thread
          end

          def send_data(message)
            logger.debug("#{self.class}##{__method__}") { message }
            driver.send(message)
          end

          protected

          # @return [Thread]
          def ensure_reactor_running
            return if EventMachine.reactor_running?

            reactor = Thread.new { EventMachine.run }
            Thread.pass until EventMachine.reactor_running?
            reactor
          end

          def connect
            @driver = Client.new(url, nil, options.merge(logger: logger))
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
slack-ruby-client-0.12.0 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.11.1 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.11.0 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.10.0 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.9.1 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.9.0 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.8.1 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.8.0 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.9 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.8 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.7 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.6 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.5 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.4 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.3 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.7.2 lib/slack/real_time/concurrency/eventmachine.rb