Skip to content

Instantly share code, notes, and snippets.

@mariusbutuc
Created April 28, 2013 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariusbutuc/5477442 to your computer and use it in GitHub Desktop.
Save mariusbutuc/5477442 to your computer and use it in GitHub Desktop.
Private_pub binding faye unsubscribe
# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"
require "active_support/core_ext"
Faye::WebSocket.load_adapter('thin')
PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
wts_pubsub = PrivatePub.faye_app
wts_pubsub.bind(:subscribe) do |client_id, channel|
puts "[#{Time.now}] Client #{client_id} joined #{channel}"
end
wts_pubsub.bind(:unsubscribe) do |client_id, channel|
puts "[#{Time.now}] Client #{client_id} disconnected from #{channel}"
PrivatePub.publish_to channel, { marius_says: 'quitter' }
end
run wts_pubsub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment