Created
October 21, 2012 03:58
-
-
Save googya/3925624 to your computer and use it in GitHub Desktop.
faye server
This file contains hidden or 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
| require 'faye' | |
| require File.expand_path('../config/initializers/faye_token.rb', __FILE__) | |
| require 'logger' | |
| class ServerAuth | |
| def incoming(message, callback) | |
| if message['channel'] !~ %r{^/meta/} | |
| if message['ext']['auth_token'] != FAYE_TOKEN | |
| message['error'] = 'Invalid authentication token' | |
| end | |
| end | |
| callback.call(message) | |
| end | |
| end | |
| faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45) | |
| log = Logger.new(STDOUT) | |
| log.level = Logger::INFO | |
| faye_server.bind(:handshake) do |client_id| | |
| log.info("[handshake] - client: + '#{client_id}'") | |
| end | |
| faye_server.bind(:subsribe) do |client_id, channel| | |
| log.info("[subscribe] - client: '#client_id', channel: '#{channel}'") | |
| end | |
| faye_server.bind(:unsubscribe) do |client_id, channel| | |
| log.info("[unsubscribe] - client: '#{client_id}, channel: '#{channel}' ") | |
| end | |
| faye_server.bind(:publish) do |client_id, channel, data| | |
| log.info("[publish] - client: '#{client_id}', channel: '#{channel}', data: '#{data}") | |
| end | |
| faye_server.bind(:disconnect) do |client_id| | |
| log.info("[disconnect] - client: '#{client_id}") | |
| end | |
| faye_server.add_extension(ServerAuth.new) | |
| run faye_server | |
| #rackup faye_server.ru --timeout 25 -s thin -E production |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment