def initialize(app_key, options={})
raise ArgumentError, "Missing app_key" if app_key.to_s.empty?
@path = "#{options[:ws_path]}/app/#{app_key}?client=#{CLIENT_ID}&version=#{PusherClient::VERSION}&protocol=#{PROTOCOL}"
@key = app_key.to_s
@secret = options[:secret]
@socket_id = nil
@channels = Channels.new
@global_channel = Channel.new('pusher_global_channel')
@global_channel.global = true
@connected = false
@encrypted = options[:encrypted] || options[:secure] || false
@logger = options[:logger] || PusherClient.logger
@auth_method = options[:auth_method] || options[:private_auth_method]
@cert_file = options[:cert_file]
@ws_host = options[:ws_host] || HOST
@ws_port = options[:ws_port] || WS_PORT
@wss_port = options[:wss_port] || WSS_PORT
@ssl_verify = options.fetch(:ssl_verify, true)
if @encrypted
@url = "wss://#{@ws_host}:#{@wss_port}#{@path}"
else
@url = "ws://#{@ws_host}:#{@ws_port}#{@path}"
end
bind('pusher:connection_established') do |data|
socket = parser(data)
@connected = true
@socket_id = socket['socket_id']
subscribe_all
end
bind('pusher:connection_disconnected') do |data|
@connected = false
@channels.channels.each { |c| c.disconnect }
end
bind('pusher:error') do |data|
logger.fatal("Pusher : error : #{data.inspect}")
end
bind('pusher:ping') do
send_event('pusher:pong', nil)
end
end