Created
April 28, 2013 16:36
-
-
Save mariusbutuc/5477442 to your computer and use it in GitHub Desktop.
Private_pub binding faye unsubscribe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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