diff --git a/Gemfile b/Gemfile index b0d110e..99d0af4 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,6 @@ group :development, :test do gem 'em-eventsource' gem 'em-http-request' gem 'sinatra' - gem 'faye' end # debugger for 1.9 only diff --git a/lib/rack/stream/handlers/faye.rb b/lib/rack/stream/handlers/faye.rb deleted file mode 100644 index 1c61bff..0000000 --- a/lib/rack/stream/handlers/faye.rb +++ /dev/null @@ -1,80 +0,0 @@ -begin - require 'faye' -rescue LoadError - $stderr.puts "Faye is required, make sure you add it to your project" -end - -module Rack - class Stream - module Handlers - # Handler for [Faye](http://faye.jcoglan.com/). This handler - # assumes that you have subscribed the the stream you're interested - # in ahead of time, and will start streaming to the channel - # specified by the request header X-FAYE-STREAM. You may also - # optionally specify a request header X-FAYE-CLOSE to be notified - # when the connection is closed. Otherwise, the close channel name - # is the same as X-FAYE-STREAM with '/close' appended to it. - # - # ## Example - # ```ruby - # require 'faye' - # require 'rack/stream/handlers/faye' - # - # # subscribe to channel before we start streaming - # client = Faye::Client.new('http://localhost:9292/faye') - # subscription = client.subscribe('/stream') do |message| - # # do stuff with streamed message - # end - # - # # get notification of when stream is done - # client.subscribe('/stream/close') do |message| - # subscription.cancel # cancel subscription after stream is closed - # end - # - # use Rack::Stream - # ``` - # - # ```sh - # # closes immediately, name stream channel with X-FAYE-STREAM header - # curl -H"X-FAYE-STREAM: /stream" -i -N http://localhost:9292/ - # ``` - class Faye < AbstractHandler - TERM ||= '_FAYE_CHANNEL_CLOSE_'.freeze - - def self.accepts?(app) - app.env['HTTP_X_FAYE_STREAM'] - end - - def open - @body.each do |c| - client.publish(stream_channel, c) - end - - # closes thin connection, potentially give a json response body - # for metadata, or additional headers - @app.env['async.callback'].call [@app.status, @app.headers, []] - end - - def close - @body.callback { - client.publish close_channel, TERM - } - end - - protected - - def client - @app.env['faye.client'] - end - - def stream_channel - @app.env['HTTP_X_FAYE_STREAM'] - end - - def close_channel - @app.env['HTTP_X_FAYE_CLOSE'] || "#{stream_channel}/close" - end - end - end - end -end \ No newline at end of file diff --git a/spec/integration/server_spec.rb b/spec/integration/server_spec.rb index e6711dd..903190d 100644 --- a/spec/integration/server_spec.rb +++ b/spec/integration/server_spec.rb @@ -10,7 +10,6 @@ require 'em-eventsource' require 'capybara' require 'capybara-webkit' - require 'faye' describe 'Integration', :integration => true, :type => :request, :driver => :webkit do EXPECTED = 'HELLO WORLDCHUNKYMONKEYBROWNIEBATTERCLOSING'.freeze @@ -73,8 +72,6 @@ all('#ws li').map(&:text).should =~ ["socket opened", "HELLO", "", "WORLD", "CHUNKY", "MONKEY", "BROWNIE", "BATTER", "CLOSING", "socket closed"] all('#es li').map(&:text).should =~ ["HELLO", "", "WORLD", "CHUNKY", "MONKEY", "BROWNIE", "BATTER", "CLOSING"] - - all('#faye li').map(&:text).should =~ ["HELLO", "", "WORLD", "CHUNKY", "MONKEY", "BROWNIE", "BATTER", "CLOSING", "stream unsubscribed"] end end end diff --git a/spec/integration/sinatra.ru b/spec/integration/sinatra.ru index 1423bf5..4af5151 100644 --- a/spec/integration/sinatra.ru +++ b/spec/integration/sinatra.ru @@ -1,9 +1,6 @@ require 'sinatra/base' require 'rack/stream' -require 'faye' -require 'rack/stream/handlers/faye' -use Faye::RackAdapter, :mount => '/faye', :timeout => 5 use Rack::Stream class App < Sinatra::Base diff --git a/spec/integration/views/index.erb b/spec/integration/views/index.erb index db06979..cd42799 100644 --- a/spec/integration/views/index.erb +++ b/spec/integration/views/index.erb @@ -2,8 +2,6 @@

Rack::Stream Sinatra Example

-

Faye

-

Websocket

@@ -12,7 +10,6 @@ -