require 'faye'
require 'pry'
#require File.expand_path('../config/initializers/faye_token.rb', __FILE__)
setproctitle('mozo_faye') if respond_to?(:setproctitle)
VALID_TOKENS = ['6be65f9b5e7d21b8ca8de4ccfad5ba24cf40d440b370af79']
class ServerAuth
  def incoming(message, callback)
    if message['channel'] !~ %r{^/meta/}
      message['error'] = 'Invalid authentication token' unless message['ext'] && VALID_TOKENS.include?(message['ext']['auth_token'])
    end
    callback.call(message)
  end
end

Faye::WebSocket.load_adapter('thin')
faye_server = Faye::RackAdapter.new(mount: '/faye', timeout: 45)
#faye_server.listen 9296
faye_server.add_extension(ServerAuth.new)
run faye_server
