faye 0.8.11 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of faye might be problematic. Click here for more details.
- data/{History.txt → CHANGELOG.md} +126 -105
- data/README.md +36 -0
- data/lib/faye-browser-min.js +2 -1
- data/lib/faye-browser-min.js.map +1 -8
- data/lib/faye-browser.js +923 -607
- data/lib/faye.rb +11 -5
- data/lib/faye/adapters/rack_adapter.rb +80 -85
- data/lib/faye/engines/connection.rb +7 -9
- data/lib/faye/engines/memory.rb +1 -0
- data/lib/faye/engines/proxy.rb +7 -6
- data/lib/faye/mixins/deferrable.rb +15 -0
- data/lib/faye/mixins/logging.rb +11 -22
- data/lib/faye/mixins/publisher.rb +9 -20
- data/lib/faye/protocol/channel.rb +2 -1
- data/lib/faye/protocol/client.rb +70 -48
- data/lib/faye/protocol/envelope.rb +24 -0
- data/lib/faye/protocol/extensible.rb +7 -4
- data/lib/faye/protocol/publication.rb +1 -1
- data/lib/faye/protocol/server.rb +8 -11
- data/lib/faye/protocol/socket.rb +6 -4
- data/lib/faye/protocol/subscription.rb +1 -1
- data/lib/faye/transport/http.rb +20 -27
- data/lib/faye/transport/local.rb +5 -5
- data/lib/faye/transport/transport.rb +42 -12
- data/lib/faye/transport/web_socket.rb +71 -38
- metadata +169 -137
- checksums.yaml +0 -7
- data/README.rdoc +0 -83
- data/spec/browser.html +0 -45
- data/spec/encoding_helper.rb +0 -7
- data/spec/install.sh +0 -78
- data/spec/javascript/channel_spec.js +0 -15
- data/spec/javascript/client_spec.js +0 -729
- data/spec/javascript/dispatcher_spec.js +0 -122
- data/spec/javascript/engine/memory_spec.js +0 -7
- data/spec/javascript/engine_spec.js +0 -417
- data/spec/javascript/faye_spec.js +0 -34
- data/spec/javascript/grammar_spec.js +0 -66
- data/spec/javascript/node_adapter_spec.js +0 -314
- data/spec/javascript/publisher_spec.js +0 -27
- data/spec/javascript/server/connect_spec.js +0 -168
- data/spec/javascript/server/disconnect_spec.js +0 -121
- data/spec/javascript/server/extensions_spec.js +0 -60
- data/spec/javascript/server/handshake_spec.js +0 -145
- data/spec/javascript/server/integration_spec.js +0 -131
- data/spec/javascript/server/publish_spec.js +0 -85
- data/spec/javascript/server/subscribe_spec.js +0 -247
- data/spec/javascript/server/unsubscribe_spec.js +0 -245
- data/spec/javascript/server_spec.js +0 -121
- data/spec/javascript/transport_spec.js +0 -135
- data/spec/node.js +0 -55
- data/spec/phantom.js +0 -17
- data/spec/ruby/channel_spec.rb +0 -17
- data/spec/ruby/client_spec.rb +0 -741
- data/spec/ruby/engine/memory_spec.rb +0 -7
- data/spec/ruby/engine_examples.rb +0 -427
- data/spec/ruby/faye_spec.rb +0 -30
- data/spec/ruby/grammar_spec.rb +0 -68
- data/spec/ruby/publisher_spec.rb +0 -27
- data/spec/ruby/rack_adapter_spec.rb +0 -241
- data/spec/ruby/server/connect_spec.rb +0 -170
- data/spec/ruby/server/disconnect_spec.rb +0 -120
- data/spec/ruby/server/extensions_spec.rb +0 -68
- data/spec/ruby/server/handshake_spec.rb +0 -143
- data/spec/ruby/server/integration_spec.rb +0 -133
- data/spec/ruby/server/publish_spec.rb +0 -81
- data/spec/ruby/server/subscribe_spec.rb +0 -247
- data/spec/ruby/server/unsubscribe_spec.rb +0 -247
- data/spec/ruby/server_spec.rb +0 -121
- data/spec/ruby/transport_spec.rb +0 -136
- data/spec/spec_helper.rb +0 -11
- data/spec/testswarm +0 -42
- data/spec/thin_proxy.rb +0 -37
data/spec/ruby/server_spec.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Faye::Server do
|
4
|
-
let(:engine) { mock "engine" }
|
5
|
-
let(:server) { Faye::Server.new }
|
6
|
-
|
7
|
-
before do
|
8
|
-
Faye::Engine.stub(:get).and_return engine
|
9
|
-
end
|
10
|
-
|
11
|
-
describe :process do
|
12
|
-
let(:handshake) {{"channel" => "/meta/handshake", "data" => "handshake" }}
|
13
|
-
let(:connect) {{"channel" => "/meta/connect", "data" => "connect" }}
|
14
|
-
let(:disconnect) {{"channel" => "/meta/disconnect", "data" => "disconnect" }}
|
15
|
-
let(:subscribe) {{"channel" => "/meta/subscribe", "data" => "subscribe" }}
|
16
|
-
let(:unsubscribe) {{"channel" => "/meta/unsubscribe", "data" => "unsubscribe"}}
|
17
|
-
let(:publish) {{"channel" => "/some/channel", "data" => "publish" }}
|
18
|
-
|
19
|
-
before do
|
20
|
-
engine.stub(:interval).and_return(0)
|
21
|
-
engine.stub(:timeout).and_return(60)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns an empty response for no messages" do
|
25
|
-
response = nil
|
26
|
-
server.process([], false) { |r| response = r }
|
27
|
-
response.should == []
|
28
|
-
end
|
29
|
-
|
30
|
-
it "ignores invalid messages" do
|
31
|
-
response = nil
|
32
|
-
server.process([{}, {"channel" => "invalid"}], false) { |r| response = r }
|
33
|
-
response.should == [
|
34
|
-
{ "successful" => false,
|
35
|
-
"error" => "405::Invalid channel"
|
36
|
-
},
|
37
|
-
{ "channel" => "invalid",
|
38
|
-
"successful" => false,
|
39
|
-
"error" => "405:invalid:Invalid channel"
|
40
|
-
}
|
41
|
-
]
|
42
|
-
end
|
43
|
-
|
44
|
-
it "rejects unknown meta channels" do
|
45
|
-
response = nil
|
46
|
-
server.process([{"channel" => "/meta/p"}], false) { |r| response = r }
|
47
|
-
response.should == [
|
48
|
-
{ "channel" => "/meta/p",
|
49
|
-
"successful" => false,
|
50
|
-
"error" => "403:/meta/p:Forbidden channel"
|
51
|
-
}
|
52
|
-
]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "routes single messages to appropriate handlers" do
|
56
|
-
server.should_receive(:handshake).with(handshake, false)
|
57
|
-
server.process(handshake, false) {}
|
58
|
-
end
|
59
|
-
|
60
|
-
it "routes a list of messages to appropriate handlers" do
|
61
|
-
server.should_receive(:handshake).with(handshake, false)
|
62
|
-
server.should_receive(:connect).with(connect, false)
|
63
|
-
server.should_receive(:disconnect).with(disconnect, false)
|
64
|
-
server.should_receive(:subscribe).with(subscribe, false)
|
65
|
-
server.should_receive(:unsubscribe).with(unsubscribe, false)
|
66
|
-
|
67
|
-
engine.should_not_receive(:publish).with(handshake)
|
68
|
-
engine.should_not_receive(:publish).with(connect)
|
69
|
-
engine.should_not_receive(:publish).with(disconnect)
|
70
|
-
engine.should_not_receive(:publish).with(subscribe)
|
71
|
-
engine.should_not_receive(:publish).with(unsubscribe)
|
72
|
-
engine.should_receive(:publish).with(publish)
|
73
|
-
|
74
|
-
server.process([handshake, connect, disconnect, subscribe, unsubscribe, publish], false)
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "handshaking" do
|
78
|
-
before do
|
79
|
-
response = {"channel" => "/meta/handshake", "successful" => true}
|
80
|
-
server.should_receive(:handshake).with(handshake, false).and_yield(response)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "returns the handshake response with advice" do
|
84
|
-
server.process(handshake, false) do |response|
|
85
|
-
response.should == [
|
86
|
-
{ "channel" => "/meta/handshake",
|
87
|
-
"successful" => true,
|
88
|
-
"advice" => {"reconnect" => "retry", "interval" => 0, "timeout" => 60000}
|
89
|
-
}
|
90
|
-
]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "connecting for messages" do
|
96
|
-
let(:messages) { [{"channel" => "/a"}, {"channel" => "/b"}] }
|
97
|
-
|
98
|
-
before do
|
99
|
-
server.should_receive(:connect).with(connect, false).and_yield(messages)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "returns the new messages" do
|
103
|
-
server.process(connect, false) { |r| r.should == messages }
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe :flush_connection do
|
109
|
-
let(:message) {{"clientId" => "fakeclientid"}}
|
110
|
-
|
111
|
-
it "flushes the connection when given one message" do
|
112
|
-
engine.should_receive(:flush).with("fakeclientid")
|
113
|
-
server.flush_connection(message)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "flushes the connection when given a list of messages" do
|
117
|
-
engine.should_receive(:flush).with("fakeclientid")
|
118
|
-
server.flush_connection([message])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
data/spec/ruby/transport_spec.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Faye::Transport do
|
4
|
-
before do
|
5
|
-
Faye.ensure_reactor_running!
|
6
|
-
end
|
7
|
-
|
8
|
-
let :client do
|
9
|
-
mock("client", :endpoint => "http://example.com/", :endpoints => {}, :transports => {})
|
10
|
-
end
|
11
|
-
|
12
|
-
describe :get do
|
13
|
-
before do
|
14
|
-
Faye::Transport::Local.stub(:usable?).and_yield(false)
|
15
|
-
Faye::Transport::Http.stub(:usable?).and_yield(false)
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_transport(connection_types)
|
19
|
-
transport = nil
|
20
|
-
Faye::Transport.get(client, connection_types, []) { |t| transport = t }
|
21
|
-
transport
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:transport) { get_transport ["long-polling", "in-process"] }
|
25
|
-
let(:local_transport) { get_transport ["in-process"] }
|
26
|
-
let(:http_transport) { get_transport ["long-polling"] }
|
27
|
-
|
28
|
-
describe "when no transport is usable" do
|
29
|
-
it "raises an exception" do
|
30
|
-
lambda { transport }.should raise_error
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "when a less preferred transport is usable" do
|
35
|
-
before do
|
36
|
-
Faye::Transport::Http.stub(:usable?).and_yield(true)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "returns a transport of the usable type" do
|
40
|
-
transport.should be_kind_of(Faye::Transport::Http)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "rasies an exception of the usable type is not requested" do
|
44
|
-
lambda { local_transport }.should raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it "allows the usable type to be specifically selected" do
|
48
|
-
http_transport.should be_kind_of(Faye::Transport::Http)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "when all transports are usable" do
|
53
|
-
before do
|
54
|
-
Faye::Transport::Local.stub(:usable?).and_yield(true)
|
55
|
-
Faye::Transport::Http.stub(:usable?).and_yield(true)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns the most preferred type" do
|
59
|
-
transport.should be_kind_of(Faye::Transport::Local)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "allows types to be specifically selected" do
|
63
|
-
local_transport.should be_kind_of(Faye::Transport::Local)
|
64
|
-
http_transport.should be_kind_of(Faye::Transport::Http)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe :send do
|
70
|
-
include EM::RSpec::FakeClock
|
71
|
-
before { clock.stub }
|
72
|
-
after { clock.reset }
|
73
|
-
|
74
|
-
before do
|
75
|
-
client.stub(:client_id).and_return("abc123")
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "for batching transports" do
|
79
|
-
before do
|
80
|
-
transport_klass = Class.new(Faye::Transport) do
|
81
|
-
def batching?
|
82
|
-
true
|
83
|
-
end
|
84
|
-
end
|
85
|
-
@transport = transport_klass.new(client, "")
|
86
|
-
end
|
87
|
-
|
88
|
-
it "does not make an immediate request" do
|
89
|
-
@transport.should_not_receive(:request)
|
90
|
-
@transport.send({"batch" => "me"}, 60)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "queues the message to be sent after a timeout" do
|
94
|
-
@transport.should_receive(:request).with([{"batch" => "me"}], 60)
|
95
|
-
@transport.send({"batch" => "me"}, 60)
|
96
|
-
clock.tick(0.01)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "allows multiple messages to be batched together" do
|
100
|
-
@transport.should_receive(:request).with([{"id" => 1}, {"id" => 2}], 60)
|
101
|
-
@transport.send({"id" => 1}, 60)
|
102
|
-
@transport.send({"id" => 2}, 60)
|
103
|
-
clock.tick(0.01)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "adds advice to connect messages sent with others" do
|
107
|
-
@transport.should_receive(:request).with([{"channel" => "/meta/connect", "advice" => {"timeout" => 0}}, {}], 60)
|
108
|
-
@transport.send({"channel" => "/meta/connect"}, 60)
|
109
|
-
@transport.send({}, 60)
|
110
|
-
clock.tick(0.01)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "adds no advice to connect messages sent alone" do
|
114
|
-
@transport.should_receive(:request).with([{"channel" => "/meta/connect"}], 60)
|
115
|
-
@transport.send({"channel" => "/meta/connect"}, 60)
|
116
|
-
clock.tick(0.01)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "for non-batching transports" do
|
121
|
-
before do
|
122
|
-
transport_klass = Class.new(Faye::Transport) do
|
123
|
-
def batching?
|
124
|
-
false
|
125
|
-
end
|
126
|
-
end
|
127
|
-
@transport = transport_klass.new(client, "")
|
128
|
-
end
|
129
|
-
|
130
|
-
it "makes a request immediately" do
|
131
|
-
@transport.should_receive(:request).with([{"no" => "batch"}], 60)
|
132
|
-
@transport.send({"no" => "batch"}, 60)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
dir = File.expand_path(File.dirname(__FILE__))
|
3
|
-
require dir + '/../lib/faye'
|
4
|
-
require dir + '/../vendor/em-rspec/lib/em-rspec'
|
5
|
-
require 'rack/test'
|
6
|
-
|
7
|
-
Faye.logger = lambda { |*| }
|
8
|
-
|
9
|
-
require 'encoding_helper'
|
10
|
-
require 'ruby/engine_examples'
|
11
|
-
|
data/spec/testswarm
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "rubygems"
|
4
|
-
require "bundler/setup"
|
5
|
-
require "testswarm/client"
|
6
|
-
|
7
|
-
server = ENV["TESTSWARM_SERVER"]
|
8
|
-
key = ENV["TESTSWARM_KEY"]
|
9
|
-
root = ENV["TESTSWARM_ROOT"]
|
10
|
-
bundle = ENV["BUNDLE_DIRECTORY"]
|
11
|
-
|
12
|
-
client = TestSwarm::Client.new(server)
|
13
|
-
project = client.project("faye", :auth => key)
|
14
|
-
|
15
|
-
job = TestSwarm::Job.create(
|
16
|
-
:rcs => {
|
17
|
-
:type => "git",
|
18
|
-
:url => "git://github.com/faye/faye.git",
|
19
|
-
:branch => "master"
|
20
|
-
},
|
21
|
-
:directory => File.join(root, "changeset", project.name),
|
22
|
-
:diff => ["javascript", "spec/javascript"],
|
23
|
-
:build => [
|
24
|
-
"mkdir -p vendor",
|
25
|
-
"ln -s #{bundle} vendor/bundle",
|
26
|
-
"bundle install --path vendor/bundle",
|
27
|
-
"npm install",
|
28
|
-
"rm -rf build",
|
29
|
-
"bundle exec jake"
|
30
|
-
],
|
31
|
-
:inject => "spec/browser.html"
|
32
|
-
)
|
33
|
-
|
34
|
-
exit unless job.new?
|
35
|
-
|
36
|
-
path = "#{client.url}/changeset/#{project.name}/#{job.revision}"
|
37
|
-
job.add_suite "Faye tests", "#{path}/spec/browser.html"
|
38
|
-
|
39
|
-
project.submit_job "Faye Commit #{job.revision}", job,
|
40
|
-
:browsers => "all",
|
41
|
-
:max => 5
|
42
|
-
|
data/spec/thin_proxy.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'rack/proxy'
|
2
|
-
|
3
|
-
# This only exists so we can use Rack::Test to test the
|
4
|
-
# RackAdapter class, which assumes it's running on Thin
|
5
|
-
|
6
|
-
class ThinProxy < Rack::Proxy
|
7
|
-
HOST = 'localhost'
|
8
|
-
PORT = '8282'
|
9
|
-
|
10
|
-
def initialize(rack_app)
|
11
|
-
Thin::Logging.silent = true
|
12
|
-
handler = Rack::Handler.get('thin')
|
13
|
-
|
14
|
-
EM.stop if EM.reactor_running?
|
15
|
-
Thread.pass while EM.reactor_running?
|
16
|
-
|
17
|
-
Thread.new {
|
18
|
-
handler.run(rack_app, :Host => HOST, :Port => PORT) do |server|
|
19
|
-
@server = server
|
20
|
-
end
|
21
|
-
}
|
22
|
-
Thread.pass until EM.reactor_running?
|
23
|
-
end
|
24
|
-
|
25
|
-
def stop
|
26
|
-
EM.stop
|
27
|
-
@server.stop
|
28
|
-
Thread.pass while EM.reactor_running?
|
29
|
-
end
|
30
|
-
|
31
|
-
def rewrite_env(env)
|
32
|
-
env['HTTP_HOST'] = HOST
|
33
|
-
env['SERVER_PORT'] = PORT
|
34
|
-
env[Faye::RackAdapter::HTTP_X_NO_CONTENT_LENGTH] = '1'
|
35
|
-
env
|
36
|
-
end
|
37
|
-
end
|