README.rdoc in pusher-client-0.2.0 vs README.rdoc in pusher-client-0.2.1

- old
+ new

@@ -1,32 +1,36 @@ -= PusherClient += pusher-client (Ruby) -pusher-client is a ruby gem for consuming WebSockets from the Pusher webservice[http://pusherapp.com] +pusher-client is a ruby gem for consuming WebSockets from the Pusher[http://pusherapp.com] web service. -The connection to Pusher can optionally be maintained in its own thread (see Asynchronous Usage) +The connection to Pusher can optionally be maintained in its own thread (see Asynchronous Usage). -This gem no longer depends on em-http, and is compatible with jruby as of 0.2. +This gem no longer depends on em-http, and is compatible with jruby since 0.2. +When binding to a global event, note that you still must be subscribed to the channels the event +may be sent on. You can't just bind a global event without subscribing to any channels and call it a day. + == Installation gem install pusher-client -== Evented Usage +== Single-Threaded Usage The application will pause at socket.connect and handle events from Pusher as they happen. require 'pusher-client' PusherClient.logger = Logger.new(STDOUT) socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY) - # Bind to a global event + # Subscribe to two channels + socket.subscribe('channel1') + socket.subscribe('channel2') + + # Bind to a global event (can occur on either channel1 or channel2) socket.bind('globalevent') do |data| puts data end - # Subscribe to a channel - socket.subscribe('mychannel') - - # Bind to a channel event - socket['mychannel'].bind('channelevent') do |data| + # Bind to a channel event (can only occur on channel1) + socket['channel1'].bind('channelevent') do |data| puts data end socket.connect @@ -37,24 +41,25 @@ require 'pusher-client' PusherClient.logger = Logger.new(STDOUT) socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY) socket.connect(true) # Connect asynchronously - # Bind to a global event + # Subscribe to two channels + socket.subscribe('channel1') + socket.subscribe('channel2') + + # Bind to a global event (can occur on either channel1 or channel2) socket.bind('globalevent') do |data| puts data end - # Subscribe to a channel - socket.subscribe('mychannel') - - # Bind to a channel event - socket['mychannel'].bind('channelevent') do |data| + # Bind to a channel event (can only occur on channel1) + socket['channel1'].bind('channelevent') do |data| puts data end loop do - sleep(1) + sleep(1) # Keep your main thread running end For further documentation, read the source & test suite. Some features of the JavaScript client are not yet implemented.