class Travis::Client::Listener::Socket

Attributes

session[RW]
signatures[RW]

Public Class Methods

new(application_key, options = {}) click to toggle source
Calls superclass method
# File lib/travis/client/listener.rb, line 16
def initialize(application_key, options = {})
  @session    = options.fetch(:session)
  @signatures = {}
  super

  bind('pusher:error') do |data|
    handle_error(data)
  end
end

Public Instance Methods

fetch_auth(*channels) click to toggle source
# File lib/travis/client/listener.rb, line 32
def fetch_auth(*channels)
  channels.select! { |c| signatures[c].nil? if c.start_with? 'private-' }
  signatures.merge! session.post_raw('/pusher/auth', :channels => channels, :socket_id => socket_id)['channels'] if channels.any?
end
get_private_auth(channel) click to toggle source
# File lib/travis/client/listener.rb, line 37
def get_private_auth(channel)
  fetch_auth(channel.name)
  signatures[channel.name]
end
handle_error(data) click to toggle source
# File lib/travis/client/listener.rb, line 42
def handle_error(data)
  code, message = data["code"], data["message"] if data.is_a? Hash
  message ||= data.inspect

  case code
  when 4100             then reconnect(1)
  when 4200, 4201, 4202 then reconnect
  else raise Travis::Client::Error, "Pusher error: %s (code: %p)" % [message, code]
  end
end
reconnect(delay = nil) click to toggle source
# File lib/travis/client/listener.rb, line 53
def reconnect(delay = nil)
  disconnect if connected
  sleep delay if delay and delay > 0
  connect
end
subscribe_all() click to toggle source
Calls superclass method
# File lib/travis/client/listener.rb, line 26
def subscribe_all
  # bulk auth on connect
  fetch_auth(*channels.channels.keys)
  super
end