faye 0.8.11 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,120 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "server disconnect" 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 :disconnect do
|
12
|
-
let(:client_id) { "fakeclientid" }
|
13
|
-
let(:message) {{"channel" => "/meta/disconnect",
|
14
|
-
"clientId" => "fakeclientid"
|
15
|
-
}}
|
16
|
-
|
17
|
-
describe "with valid parameters" do
|
18
|
-
before do
|
19
|
-
engine.should_receive(:client_exists).with(client_id).and_yield true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "destroys the client" do
|
23
|
-
engine.should_receive(:destroy_client).with(client_id)
|
24
|
-
server.disconnect(message) {}
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns a successful response" do
|
28
|
-
engine.stub(:destroy_client)
|
29
|
-
server.disconnect(message) do |response|
|
30
|
-
response.should == {
|
31
|
-
"channel" => "/meta/disconnect",
|
32
|
-
"successful" => true,
|
33
|
-
"clientId" => client_id
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "with a message id" do
|
39
|
-
before { message["id"] = "foo" }
|
40
|
-
|
41
|
-
it "returns the same id" do
|
42
|
-
engine.stub(:destroy_client)
|
43
|
-
server.disconnect(message) do |response|
|
44
|
-
response.should == {
|
45
|
-
"channel" => "/meta/disconnect",
|
46
|
-
"successful" => true,
|
47
|
-
"clientId" => client_id,
|
48
|
-
"id" => "foo"
|
49
|
-
}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "with an unknown client" do
|
56
|
-
before do
|
57
|
-
engine.should_receive(:client_exists).with(client_id).and_yield false
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not destroy the client" do
|
61
|
-
engine.should_not_receive(:destroy_client)
|
62
|
-
server.disconnect(message) {}
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns an unsuccessful response" do
|
66
|
-
server.disconnect(message) do |response|
|
67
|
-
response.should == {
|
68
|
-
"channel" => "/meta/disconnect",
|
69
|
-
"successful" => false,
|
70
|
-
"error" => "401:fakeclientid:Unknown client"
|
71
|
-
}
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "missing clientId" do
|
77
|
-
before do
|
78
|
-
message.delete("clientId")
|
79
|
-
engine.should_receive(:client_exists).with(nil).and_yield false
|
80
|
-
end
|
81
|
-
|
82
|
-
it "does not destroy the client" do
|
83
|
-
engine.should_not_receive(:destroy_client)
|
84
|
-
server.disconnect(message) {}
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns an unsuccessful response" do
|
88
|
-
server.disconnect(message) do |response|
|
89
|
-
response.should == {
|
90
|
-
"channel" => "/meta/disconnect",
|
91
|
-
"successful" => false,
|
92
|
-
"error" => "402:clientId:Missing required parameter"
|
93
|
-
}
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "with an error" do
|
99
|
-
before do
|
100
|
-
message["error"] = "invalid"
|
101
|
-
engine.should_receive(:client_exists).with(client_id).and_yield true
|
102
|
-
end
|
103
|
-
|
104
|
-
it "does not destroy the client" do
|
105
|
-
engine.should_not_receive(:destroy_client)
|
106
|
-
server.disconnect(message) {}
|
107
|
-
end
|
108
|
-
|
109
|
-
it "returns an unsuccessful response" do
|
110
|
-
server.disconnect(message) do |response|
|
111
|
-
response.should == {
|
112
|
-
"channel" => "/meta/disconnect",
|
113
|
-
"successful" => false,
|
114
|
-
"error" => "invalid"
|
115
|
-
}
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "server extensions" do
|
4
|
-
let(:engine) do
|
5
|
-
engine = mock "engine"
|
6
|
-
engine.stub(:interval).and_return(0)
|
7
|
-
engine.stub(:timeout).and_return(60)
|
8
|
-
engine
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:server) { Faye::Server.new }
|
12
|
-
let(:message) { {"channel" => "/foo", "data" => "hello"} }
|
13
|
-
|
14
|
-
before do
|
15
|
-
Faye::Engine.stub(:get).and_return engine
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "with an incoming extension installed" do
|
19
|
-
before do
|
20
|
-
extension = Class.new do
|
21
|
-
def incoming(message, callback)
|
22
|
-
message["ext"] = {"auth" => "password"}
|
23
|
-
callback.call(message)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
server.add_extension(extension.new)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "passes incoming messages through the extension" do
|
30
|
-
engine.should_receive(:publish).with({"channel" => "/foo", "data" => "hello", "ext" => {"auth" => "password"}})
|
31
|
-
server.process(message, false) {}
|
32
|
-
end
|
33
|
-
|
34
|
-
it "does not pass outgoing messages through the extension" do
|
35
|
-
server.stub(:handshake).and_yield(message)
|
36
|
-
engine.stub(:publish)
|
37
|
-
response = nil
|
38
|
-
server.process({"channel" => "/meta/handshake"}, false) { |r| response = r }
|
39
|
-
response.should == [{"channel" => "/foo", "data" => "hello"}]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "with an outgoing extension installed" do
|
44
|
-
before do
|
45
|
-
extension = Class.new do
|
46
|
-
def outgoing(message, callback)
|
47
|
-
message["ext"] = {"auth" => "password"}
|
48
|
-
callback.call(message)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
server.add_extension(extension.new)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "does not pass incoming messages through the extension" do
|
55
|
-
engine.should_receive(:publish).with({"channel" => "/foo", "data" => "hello"})
|
56
|
-
server.process(message, false) {}
|
57
|
-
end
|
58
|
-
|
59
|
-
it "passes outgoing messages through the extension" do
|
60
|
-
server.stub(:handshake).and_yield(message)
|
61
|
-
engine.stub(:publish)
|
62
|
-
response = nil
|
63
|
-
server.process({"channel" => "/meta/handshake"}, false) { |r| response = r }
|
64
|
-
response.should == [{"channel" => "/foo", "data" => "hello", "ext" => {"auth" => "password"}}]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "server handshake" do
|
4
|
-
let(:engine) { mock "engine" }
|
5
|
-
let(:server) { Faye::Server.new }
|
6
|
-
|
7
|
-
let :connection_types do
|
8
|
-
["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"]
|
9
|
-
end
|
10
|
-
|
11
|
-
before do
|
12
|
-
Faye::Engine.stub(:get).and_return engine
|
13
|
-
end
|
14
|
-
|
15
|
-
describe :handshake do
|
16
|
-
let(:message) {{"channel" => "/meta/handshake",
|
17
|
-
"version" => "1.0",
|
18
|
-
"supportedConnectionTypes" => ["long-polling"]
|
19
|
-
}}
|
20
|
-
|
21
|
-
describe "with valid parameters" do
|
22
|
-
it "creates a client" do
|
23
|
-
engine.should_receive(:create_client)
|
24
|
-
server.handshake(message) {}
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns a successful response" do
|
28
|
-
engine.stub(:create_client).and_yield "clientid"
|
29
|
-
server.handshake(message) do |response|
|
30
|
-
response.should == {
|
31
|
-
"channel" => "/meta/handshake",
|
32
|
-
"successful" => true,
|
33
|
-
"version" => "1.0",
|
34
|
-
"supportedConnectionTypes" => connection_types,
|
35
|
-
"clientId" => "clientid"
|
36
|
-
}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "with a message id" do
|
41
|
-
before { message["id"] = "foo" }
|
42
|
-
|
43
|
-
it "returns the same id" do
|
44
|
-
engine.stub(:create_client).and_yield "clientid"
|
45
|
-
server.handshake(message) do |response|
|
46
|
-
response.should == {
|
47
|
-
"channel" => "/meta/handshake",
|
48
|
-
"successful" => true,
|
49
|
-
"version" => "1.0",
|
50
|
-
"supportedConnectionTypes" => connection_types,
|
51
|
-
"clientId" => "clientid",
|
52
|
-
"id" => "foo"
|
53
|
-
}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "missing version" do
|
60
|
-
before { message.delete "version" }
|
61
|
-
|
62
|
-
it "does not create a client" do
|
63
|
-
engine.should_not_receive(:create_client)
|
64
|
-
server.handshake(message) {}
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns an unsuccessful response" do
|
68
|
-
server.handshake(message) do |response|
|
69
|
-
response.should == {
|
70
|
-
"channel" => "/meta/handshake",
|
71
|
-
"successful" => false,
|
72
|
-
"error" => "402:version:Missing required parameter",
|
73
|
-
"version" => "1.0",
|
74
|
-
"supportedConnectionTypes" => connection_types
|
75
|
-
}
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "missing supportedConnectionTypes" do
|
81
|
-
before { message.delete "supportedConnectionTypes" }
|
82
|
-
|
83
|
-
it "does not create a client" do
|
84
|
-
engine.should_not_receive(:create_client)
|
85
|
-
server.handshake(message) {}
|
86
|
-
end
|
87
|
-
|
88
|
-
it "returns an unsuccessful response" do
|
89
|
-
server.handshake(message) do |response|
|
90
|
-
response.should == {
|
91
|
-
"channel" => "/meta/handshake",
|
92
|
-
"successful" => false,
|
93
|
-
"error" => "402:supportedConnectionTypes:Missing required parameter",
|
94
|
-
"version" => "1.0",
|
95
|
-
"supportedConnectionTypes" => connection_types
|
96
|
-
}
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "with no matching supportedConnectionTypes" do
|
102
|
-
before { message["supportedConnectionTypes"] = ["iframe", "flash"] }
|
103
|
-
|
104
|
-
it "does not create a client" do
|
105
|
-
engine.should_not_receive(:create_client)
|
106
|
-
server.handshake(message) {}
|
107
|
-
end
|
108
|
-
|
109
|
-
it "returns an unsuccessful response" do
|
110
|
-
server.handshake(message) do |response|
|
111
|
-
response.should == {
|
112
|
-
"channel" => "/meta/handshake",
|
113
|
-
"successful" => false,
|
114
|
-
"error" => "301:iframe,flash:Connection types not supported",
|
115
|
-
"version" => "1.0",
|
116
|
-
"supportedConnectionTypes" => connection_types
|
117
|
-
}
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "with an error" do
|
123
|
-
before { message["error"] = "invalid" }
|
124
|
-
|
125
|
-
it "does not createa a client" do
|
126
|
-
engine.should_not_receive(:create_client)
|
127
|
-
server.handshake(message) {}
|
128
|
-
end
|
129
|
-
|
130
|
-
it "returns an unsuccessful response" do
|
131
|
-
server.handshake(message) do |response|
|
132
|
-
response.should == {
|
133
|
-
"channel" => "/meta/handshake",
|
134
|
-
"successful" => false,
|
135
|
-
"error" => "invalid",
|
136
|
-
"version" => "1.0",
|
137
|
-
"supportedConnectionTypes" => connection_types
|
138
|
-
}
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
# encoding=utf-8
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
require "thin"
|
6
|
-
Thin::Logging.silent = true
|
7
|
-
|
8
|
-
IntegrationSteps = EM::RSpec.async_steps do
|
9
|
-
class Tagger
|
10
|
-
def outgoing(message, callback)
|
11
|
-
message["data"]["tagged"] = true if message["data"]
|
12
|
-
callback.call(message)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def server(port, ssl, &callback)
|
17
|
-
shared = File.dirname(__FILE__) + '/../../../examples/shared'
|
18
|
-
|
19
|
-
options = ssl ?
|
20
|
-
{ :key => shared + '/server.key', :cert => shared + '/server.crt' } :
|
21
|
-
nil
|
22
|
-
|
23
|
-
@adapter = Faye::RackAdapter.new(:mount => "/bayeux", :timeout => 25)
|
24
|
-
@adapter.add_extension(Tagger.new)
|
25
|
-
@adapter.listen(port, options)
|
26
|
-
|
27
|
-
@port = port
|
28
|
-
@secure = ssl
|
29
|
-
EM.next_tick(&callback)
|
30
|
-
end
|
31
|
-
|
32
|
-
def stop(&callback)
|
33
|
-
@adapter.stop
|
34
|
-
EM.next_tick(&callback)
|
35
|
-
end
|
36
|
-
|
37
|
-
def client(name, channels, &callback)
|
38
|
-
scheme = @secure ? "https" : "http"
|
39
|
-
@clients ||= {}
|
40
|
-
@inboxes ||= {}
|
41
|
-
@clients[name] = Faye::Client.new("#{scheme}://0.0.0.0:#{@port}/bayeux")
|
42
|
-
@inboxes[name] = {}
|
43
|
-
|
44
|
-
n = channels.size
|
45
|
-
return @clients[name].connect(&callback) if n.zero?
|
46
|
-
|
47
|
-
channels.each do |channel|
|
48
|
-
subscription = @clients[name].subscribe(channel) do |message|
|
49
|
-
@inboxes[name][channel] ||= []
|
50
|
-
@inboxes[name][channel] << message
|
51
|
-
end
|
52
|
-
subscription.callback do
|
53
|
-
n -= 1
|
54
|
-
callback.call if n.zero?
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def publish(name, channel, message, &callback)
|
60
|
-
@clients[name].publish(channel, message)
|
61
|
-
EM.add_timer(0.1, &callback)
|
62
|
-
end
|
63
|
-
|
64
|
-
def check_inbox(name, channel, messages, &callback)
|
65
|
-
inbox = @inboxes[name][channel] || []
|
66
|
-
inbox.should == messages
|
67
|
-
callback.call
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "server integration" do
|
72
|
-
include IntegrationSteps
|
73
|
-
include EncodingHelper
|
74
|
-
|
75
|
-
before do
|
76
|
-
server 8000, server_options[:ssl]
|
77
|
-
client :alice, []
|
78
|
-
client :bob, ["/foo"]
|
79
|
-
end
|
80
|
-
|
81
|
-
after { stop }
|
82
|
-
|
83
|
-
shared_examples_for "message bus" do
|
84
|
-
it "delivers a message between clients" do
|
85
|
-
publish :alice, "/foo", {"hello" => "world", "extra" => nil}
|
86
|
-
check_inbox :bob, "/foo", [{"hello" => "world", "extra" => nil, "tagged" => true}]
|
87
|
-
end
|
88
|
-
|
89
|
-
it "does not deliver messages for unsubscribed channels" do
|
90
|
-
publish :alice, "/bar", {"hello" => "world"}
|
91
|
-
check_inbox :bob, "/foo", []
|
92
|
-
end
|
93
|
-
|
94
|
-
it "delivers multiple messages" do
|
95
|
-
publish :alice, "/foo", {"hello" => "world"}
|
96
|
-
publish :alice, "/foo", {"hello" => "world"}
|
97
|
-
check_inbox :bob, "/foo", [{"hello" => "world", "tagged" => true}, {"hello" => "world", "tagged" => true}]
|
98
|
-
end
|
99
|
-
|
100
|
-
it "delivers multibyte strings" do
|
101
|
-
publish :alice, "/foo", {"hello" => encode("Apple = "), "tagged" => true}
|
102
|
-
check_inbox :bob, "/foo", [{"hello" => encode("Apple = "), "tagged" => true}]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
shared_examples_for "network transports" do
|
107
|
-
describe "with HTTP transport" do
|
108
|
-
before do
|
109
|
-
Faye::Transport::WebSocket.stub(:usable?).and_yield(false)
|
110
|
-
end
|
111
|
-
|
112
|
-
it_should_behave_like "message bus"
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "with WebSocket transport" do
|
116
|
-
before do
|
117
|
-
Faye::Transport::WebSocket.stub(:usable?).and_yield(true)
|
118
|
-
end
|
119
|
-
|
120
|
-
it_should_behave_like "message bus"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "with HTTP server" do
|
125
|
-
let(:server_options) { {:ssl => false} }
|
126
|
-
it_should_behave_like "network transports"
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "with HTTPS server" do
|
130
|
-
let(:server_options) { {:ssl => true} }
|
131
|
-
it_should_behave_like "network transports"
|
132
|
-
end
|
133
|
-
end
|