lib/pusher-client/socket.rb in pusher-client-0.1.0 vs lib/pusher-client/socket.rb in pusher-client-0.1.1

- old
+ new

@@ -37,11 +37,11 @@ bind('pusher:error') do |data| PusherClient.logger.fatal("Pusher : error : #{data.message}") end end - def connect + def connect(async = false) @connection_thread = Thread.new do EventMachine.run { if @encrypted || @secure url = "wss://#{HOST}:#{WSS_PORT}#{@path}" else @@ -75,27 +75,33 @@ PusherClient.logger.debug "Pusher : dropped connection" } } end @connection_thread.run + if async + sleep(1) + else + @connection_thread.join + end + return self end def disconnect if @connected PusherClient.logger.debug "Pusher : disconnecting" - @connection_thread.kill + @connection_thread.kill if @connection_thread @connected = false else PusherClient.logger.warn "Disconnect attempted... not connected" end end def subscribe(channel_name) channel = @channels << channel_name if @connected send_event('pusher:subscribe', { - 'channel' => channel_name + 'channel' => channel.name }) channel.acknowledge_subscription(nil) end return channel end @@ -122,10 +128,12 @@ @channels << channel_name end end def subscribe_all - @channels.channels.each_with_index { |k,v| subscribe(k) } + @channels.channels.clone.each{ |k,v| + subscribe(k) + } end # For compatibility with JavaScript client API alias :subscribeAll :subscribe_all