Class: Travis::Client::Listener::Socket
- Inherits:
-
PusherClient::Socket
- Object
- PusherClient::Socket
- Travis::Client::Listener::Socket
- Defined in:
- lib/travis/client/listener.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
-
#signatures ⇒ Object
Returns the value of attribute signatures.
Instance Method Summary collapse
- #fetch_auth(*channels) ⇒ Object
- #get_private_auth(channel) ⇒ Object
- #handle_error(data) ⇒ Object
-
#initialize(application_key, options = {}) ⇒ Socket
constructor
A new instance of Socket.
- #reconnect(delay = nil) ⇒ Object
- #subscribe_all ⇒ Object
Constructor Details
#initialize(application_key, options = {}) ⇒ Socket
Returns a new instance of Socket.
19 20 21 22 23 24 25 26 27 |
# File 'lib/travis/client/listener.rb', line 19 def initialize(application_key, = {}) @session = .fetch(:session) @signatures = {} super bind('pusher:error') do |data| handle_error(data) end end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
17 18 19 |
# File 'lib/travis/client/listener.rb', line 17 def session @session end |
#signatures ⇒ Object
Returns the value of attribute signatures.
17 18 19 |
# File 'lib/travis/client/listener.rb', line 17 def signatures @signatures end |
Instance Method Details
#fetch_auth(*channels) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/travis/client/listener.rb', line 35 def fetch_auth(*channels) channels.select! { |c| signatures[c].nil? if c.start_with? 'private-' } return unless channels.any? signatures.merge! session.post_raw('/pusher/auth', channels:, socket_id:)['channels'] end |
#get_private_auth(channel) ⇒ Object
43 44 45 46 |
# File 'lib/travis/client/listener.rb', line 43 def get_private_auth(channel) fetch_auth(channel.name) signatures[channel.name] end |
#handle_error(data) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/travis/client/listener.rb', line 48 def handle_error(data) if data.is_a? Hash code = data['code'] = data['message'] end ||= data.inspect case code when 4100 then reconnect(1) when 4200, 4201, 4202 then reconnect else raise Travis::Client::Error, format('Pusher error: %s (code: %p)', , code) end end |
#reconnect(delay = nil) ⇒ Object
62 63 64 65 66 |
# File 'lib/travis/client/listener.rb', line 62 def reconnect(delay = nil) disconnect if connected sleep delay if delay&.positive? connect end |
#subscribe_all ⇒ Object
29 30 31 32 33 |
# File 'lib/travis/client/listener.rb', line 29 def subscribe_all # bulk auth on connect fetch_auth(*channels.channels.keys) super end |