Class: Travis::Client::Listener::Socket

Inherits:
PusherClient::Socket
  • Object
show all
Defined in:
lib/travis/client/listener.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_key, options = {}) ⇒ Socket

Returns a new instance of Socket.



16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



15
16
17
# File 'lib/travis/client/listener.rb', line 15

def session
  @session
end

#signaturesObject

Returns the value of attribute signatures.



15
16
17
# File 'lib/travis/client/listener.rb', line 15

def signatures
  @signatures
end

Instance Method Details

#fetch_auth(*channels) ⇒ Object



32
33
34
35
# 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) ⇒ Object



37
38
39
40
# File 'lib/travis/client/listener.rb', line 37

def get_private_auth(channel)
  fetch_auth(channel.name)
  signatures[channel.name]
end

#handle_error(data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Object



53
54
55
56
57
# 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_allObject



26
27
28
29
30
# File 'lib/travis/client/listener.rb', line 26

def subscribe_all
  # bulk auth on connect
  fetch_auth(*channels.channels.keys)
  super
end