faye 0.8.8 → 0.8.9

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.

Files changed (67) hide show
  1. data/History.txt +16 -10
  2. data/README.rdoc +1 -1
  3. data/lib/faye-browser-min.js +1 -1
  4. data/lib/faye-browser-min.js.map +2 -2
  5. data/lib/faye-browser.js +302 -287
  6. data/lib/faye.rb +21 -21
  7. data/lib/faye/adapters/rack_adapter.rb +50 -48
  8. data/lib/faye/adapters/static_server.rb +22 -22
  9. data/lib/faye/engines/connection.rb +13 -13
  10. data/lib/faye/engines/memory.rb +21 -21
  11. data/lib/faye/engines/proxy.rb +23 -23
  12. data/lib/faye/error.rb +6 -6
  13. data/lib/faye/mixins/logging.rb +12 -12
  14. data/lib/faye/mixins/publisher.rb +6 -6
  15. data/lib/faye/mixins/timeouts.rb +1 -1
  16. data/lib/faye/protocol/channel.rb +24 -24
  17. data/lib/faye/protocol/client.rb +71 -73
  18. data/lib/faye/protocol/extensible.rb +7 -7
  19. data/lib/faye/protocol/grammar.rb +13 -13
  20. data/lib/faye/protocol/server.rb +57 -57
  21. data/lib/faye/protocol/socket.rb +4 -4
  22. data/lib/faye/protocol/subscription.rb +4 -4
  23. data/lib/faye/transport/http.rb +13 -13
  24. data/lib/faye/transport/local.rb +5 -5
  25. data/lib/faye/transport/transport.rb +25 -25
  26. data/lib/faye/transport/web_socket.rb +34 -30
  27. data/lib/faye/util/namespace.rb +4 -4
  28. data/spec/browser.html +5 -5
  29. data/spec/javascript/channel_spec.js +3 -3
  30. data/spec/javascript/client_spec.js +104 -98
  31. data/spec/javascript/engine/memory_spec.js +1 -1
  32. data/spec/javascript/engine_spec.js +70 -70
  33. data/spec/javascript/faye_spec.js +6 -6
  34. data/spec/javascript/grammar_spec.js +12 -12
  35. data/spec/javascript/node_adapter_spec.js +46 -46
  36. data/spec/javascript/publisher_spec.js +4 -4
  37. data/spec/javascript/server/connect_spec.js +21 -21
  38. data/spec/javascript/server/disconnect_spec.js +15 -15
  39. data/spec/javascript/server/extensions_spec.js +6 -6
  40. data/spec/javascript/server/handshake_spec.js +18 -18
  41. data/spec/javascript/server/integration_spec.js +23 -23
  42. data/spec/javascript/server/publish_spec.js +9 -9
  43. data/spec/javascript/server/subscribe_spec.js +30 -30
  44. data/spec/javascript/server/unsubscribe_spec.js +30 -30
  45. data/spec/javascript/server_spec.js +15 -15
  46. data/spec/javascript/transport_spec.js +32 -27
  47. data/spec/node.js +2 -2
  48. data/spec/ruby/channel_spec.rb +2 -2
  49. data/spec/ruby/client_spec.rb +100 -92
  50. data/spec/ruby/engine_examples.rb +51 -51
  51. data/spec/ruby/faye_spec.rb +5 -5
  52. data/spec/ruby/grammar_spec.rb +12 -12
  53. data/spec/ruby/publisher_spec.rb +4 -4
  54. data/spec/ruby/rack_adapter_spec.rb +34 -34
  55. data/spec/ruby/server/connect_spec.rb +22 -22
  56. data/spec/ruby/server/disconnect_spec.rb +16 -16
  57. data/spec/ruby/server/extensions_spec.rb +8 -8
  58. data/spec/ruby/server/handshake_spec.rb +20 -20
  59. data/spec/ruby/server/integration_spec.rb +22 -24
  60. data/spec/ruby/server/publish_spec.rb +9 -9
  61. data/spec/ruby/server/subscribe_spec.rb +31 -31
  62. data/spec/ruby/server/unsubscribe_spec.rb +31 -31
  63. data/spec/ruby/server_spec.rb +17 -17
  64. data/spec/ruby/transport_spec.rb +23 -23
  65. data/spec/testswarm +23 -10
  66. data/spec/thin_proxy.rb +5 -5
  67. metadata +90 -59
@@ -7,14 +7,14 @@ describe "server extensions" do
7
7
  engine.stub(:timeout).and_return(60)
8
8
  engine
9
9
  end
10
-
10
+
11
11
  let(:server) { Faye::Server.new }
12
12
  let(:message) { {"channel" => "/foo", "data" => "hello"} }
13
-
13
+
14
14
  before do
15
15
  Faye::Engine.stub(:get).and_return engine
16
16
  end
17
-
17
+
18
18
  describe "with an incoming extension installed" do
19
19
  before do
20
20
  extension = Class.new do
@@ -25,12 +25,12 @@ describe "server extensions" do
25
25
  end
26
26
  server.add_extension(extension.new)
27
27
  end
28
-
28
+
29
29
  it "passes incoming messages through the extension" do
30
30
  engine.should_receive(:publish).with({"channel" => "/foo", "data" => "hello", "ext" => {"auth" => "password"}})
31
31
  server.process(message, false) {}
32
32
  end
33
-
33
+
34
34
  it "does not pass outgoing messages through the extension" do
35
35
  server.stub(:handshake).and_yield(message)
36
36
  engine.stub(:publish)
@@ -39,7 +39,7 @@ describe "server extensions" do
39
39
  response.should == [{"channel" => "/foo", "data" => "hello"}]
40
40
  end
41
41
  end
42
-
42
+
43
43
  describe "with an outgoing extension installed" do
44
44
  before do
45
45
  extension = Class.new do
@@ -50,12 +50,12 @@ describe "server extensions" do
50
50
  end
51
51
  server.add_extension(extension.new)
52
52
  end
53
-
53
+
54
54
  it "does not pass incoming messages through the extension" do
55
55
  engine.should_receive(:publish).with({"channel" => "/foo", "data" => "hello"})
56
56
  server.process(message, false) {}
57
57
  end
58
-
58
+
59
59
  it "passes outgoing messages through the extension" do
60
60
  server.stub(:handshake).and_yield(message)
61
61
  engine.stub(:publish)
@@ -3,27 +3,27 @@ require "spec_helper"
3
3
  describe "server handshake" do
4
4
  let(:engine) { mock "engine" }
5
5
  let(:server) { Faye::Server.new }
6
-
6
+
7
7
  let :connection_types do
8
8
  ["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"]
9
9
  end
10
-
10
+
11
11
  before do
12
12
  Faye::Engine.stub(:get).and_return engine
13
13
  end
14
-
14
+
15
15
  describe :handshake do
16
16
  let(:message) {{"channel" => "/meta/handshake",
17
17
  "version" => "1.0",
18
18
  "supportedConnectionTypes" => ["long-polling"]
19
19
  }}
20
-
20
+
21
21
  describe "with valid parameters" do
22
22
  it "creates a client" do
23
23
  engine.should_receive(:create_client)
24
24
  server.handshake(message) {}
25
25
  end
26
-
26
+
27
27
  it "returns a successful response" do
28
28
  engine.stub(:create_client).and_yield "clientid"
29
29
  server.handshake(message) do |response|
@@ -36,10 +36,10 @@ describe "server handshake" do
36
36
  }
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe "with a message id" do
41
41
  before { message["id"] = "foo" }
42
-
42
+
43
43
  it "returns the same id" do
44
44
  engine.stub(:create_client).and_yield "clientid"
45
45
  server.handshake(message) do |response|
@@ -55,15 +55,15 @@ describe "server handshake" do
55
55
  end
56
56
  end
57
57
  end
58
-
58
+
59
59
  describe "missing version" do
60
60
  before { message.delete "version" }
61
-
61
+
62
62
  it "does not create a client" do
63
63
  engine.should_not_receive(:create_client)
64
64
  server.handshake(message) {}
65
65
  end
66
-
66
+
67
67
  it "returns an unsuccessful response" do
68
68
  server.handshake(message) do |response|
69
69
  response.should == {
@@ -76,15 +76,15 @@ describe "server handshake" do
76
76
  end
77
77
  end
78
78
  end
79
-
79
+
80
80
  describe "missing supportedConnectionTypes" do
81
81
  before { message.delete "supportedConnectionTypes" }
82
-
82
+
83
83
  it "does not create a client" do
84
84
  engine.should_not_receive(:create_client)
85
85
  server.handshake(message) {}
86
86
  end
87
-
87
+
88
88
  it "returns an unsuccessful response" do
89
89
  server.handshake(message) do |response|
90
90
  response.should == {
@@ -97,15 +97,15 @@ describe "server handshake" do
97
97
  end
98
98
  end
99
99
  end
100
-
100
+
101
101
  describe "with no matching supportedConnectionTypes" do
102
102
  before { message["supportedConnectionTypes"] = ["iframe", "flash"] }
103
-
103
+
104
104
  it "does not create a client" do
105
105
  engine.should_not_receive(:create_client)
106
106
  server.handshake(message) {}
107
107
  end
108
-
108
+
109
109
  it "returns an unsuccessful response" do
110
110
  server.handshake(message) do |response|
111
111
  response.should == {
@@ -118,15 +118,15 @@ describe "server handshake" do
118
118
  end
119
119
  end
120
120
  end
121
-
121
+
122
122
  describe "with an error" do
123
123
  before { message["error"] = "invalid" }
124
-
124
+
125
125
  it "does not createa a client" do
126
126
  engine.should_not_receive(:create_client)
127
127
  server.handshake(message) {}
128
128
  end
129
-
129
+
130
130
  it "returns an unsuccessful response" do
131
131
  server.handshake(message) do |response|
132
132
  response.should == {
@@ -139,5 +139,5 @@ describe "server handshake" do
139
139
  end
140
140
  end
141
141
  end
142
- end
142
+ end
143
143
  end
@@ -12,38 +12,38 @@ IntegrationSteps = EM::RSpec.async_steps do
12
12
  callback.call(message)
13
13
  end
14
14
  end
15
-
15
+
16
16
  def server(port, ssl, &callback)
17
17
  shared = File.dirname(__FILE__) + '/../../../examples/shared'
18
-
18
+
19
19
  options = ssl ?
20
20
  { :key => shared + '/server.key', :cert => shared + '/server.crt' } :
21
21
  nil
22
-
22
+
23
23
  @adapter = Faye::RackAdapter.new(:mount => "/bayeux", :timeout => 25)
24
24
  @adapter.add_extension(Tagger.new)
25
25
  @adapter.listen(port, options)
26
-
26
+
27
27
  @port = port
28
28
  @secure = ssl
29
29
  EM.next_tick(&callback)
30
30
  end
31
-
31
+
32
32
  def stop(&callback)
33
33
  @adapter.stop
34
34
  EM.next_tick(&callback)
35
35
  end
36
-
36
+
37
37
  def client(name, channels, &callback)
38
38
  scheme = @secure ? "https" : "http"
39
39
  @clients ||= {}
40
40
  @inboxes ||= {}
41
41
  @clients[name] = Faye::Client.new("#{scheme}://0.0.0.0:#{@port}/bayeux")
42
42
  @inboxes[name] = {}
43
-
43
+
44
44
  n = channels.size
45
45
  return @clients[name].connect(&callback) if n.zero?
46
-
46
+
47
47
  channels.each do |channel|
48
48
  subscription = @clients[name].subscribe(channel) do |message|
49
49
  @inboxes[name][channel] ||= []
@@ -55,12 +55,12 @@ IntegrationSteps = EM::RSpec.async_steps do
55
55
  end
56
56
  end
57
57
  end
58
-
58
+
59
59
  def publish(name, channel, message, &callback)
60
60
  @clients[name].publish(channel, message)
61
61
  EM.add_timer(0.1, &callback)
62
62
  end
63
-
63
+
64
64
  def check_inbox(name, channel, messages, &callback)
65
65
  inbox = @inboxes[name][channel] || []
66
66
  inbox.should == messages
@@ -71,63 +71,61 @@ end
71
71
  describe "server integration" do
72
72
  include IntegrationSteps
73
73
  include EncodingHelper
74
-
74
+
75
75
  before do
76
- Faye.ensure_reactor_running!
77
76
  server 8000, server_options[:ssl]
78
77
  client :alice, []
79
78
  client :bob, ["/foo"]
80
- sync
81
79
  end
82
-
80
+
83
81
  after { stop }
84
-
82
+
85
83
  shared_examples_for "message bus" do
86
84
  it "delivers a message between clients" do
87
85
  publish :alice, "/foo", {"hello" => "world", "extra" => nil}
88
86
  check_inbox :bob, "/foo", [{"hello" => "world", "extra" => nil, "tagged" => true}]
89
87
  end
90
-
88
+
91
89
  it "does not deliver messages for unsubscribed channels" do
92
90
  publish :alice, "/bar", {"hello" => "world"}
93
91
  check_inbox :bob, "/foo", []
94
92
  end
95
-
93
+
96
94
  it "delivers multiple messages" do
97
95
  publish :alice, "/foo", {"hello" => "world"}
98
96
  publish :alice, "/foo", {"hello" => "world"}
99
97
  check_inbox :bob, "/foo", [{"hello" => "world", "tagged" => true}, {"hello" => "world", "tagged" => true}]
100
98
  end
101
-
99
+
102
100
  it "delivers multibyte strings" do
103
101
  publish :alice, "/foo", {"hello" => encode("Apple = "), "tagged" => true}
104
102
  check_inbox :bob, "/foo", [{"hello" => encode("Apple = "), "tagged" => true}]
105
103
  end
106
104
  end
107
-
105
+
108
106
  shared_examples_for "network transports" do
109
107
  describe "with HTTP transport" do
110
108
  before do
111
109
  Faye::Transport::WebSocket.stub(:usable?).and_yield(false)
112
110
  end
113
-
111
+
114
112
  it_should_behave_like "message bus"
115
113
  end
116
-
114
+
117
115
  describe "with WebSocket transport" do
118
116
  before do
119
117
  Faye::Transport::WebSocket.stub(:usable?).and_yield(true)
120
118
  end
121
-
119
+
122
120
  it_should_behave_like "message bus"
123
121
  end
124
122
  end
125
-
123
+
126
124
  describe "with HTTP server" do
127
125
  let(:server_options) { {:ssl => false} }
128
126
  it_should_behave_like "network transports"
129
127
  end
130
-
128
+
131
129
  describe "with HTTPS server" do
132
130
  let(:server_options) { {:ssl => true} }
133
131
  it_should_behave_like "network transports"
@@ -4,17 +4,17 @@ describe "server publish" do
4
4
  let(:engine) { mock "engine" }
5
5
  let(:server) { Faye::Server.new }
6
6
  let(:message) {{ "channel" => "/some/channel", "data" => "publish" }}
7
-
7
+
8
8
  before do
9
9
  Faye::Engine.stub(:get).and_return engine
10
10
  end
11
-
11
+
12
12
  describe "publishing a message" do
13
13
  it "tells the engine to publish the message" do
14
14
  engine.should_receive(:publish).with(message)
15
15
  server.process(message, false) {}
16
16
  end
17
-
17
+
18
18
  it "returns a successful response" do
19
19
  engine.stub(:publish)
20
20
  server.process(message, false) do |response|
@@ -25,15 +25,15 @@ describe "server publish" do
25
25
  ]
26
26
  end
27
27
  end
28
-
28
+
29
29
  describe "with an invalid channel" do
30
30
  before { message["channel"] = "channel" }
31
-
31
+
32
32
  it "does not tell the engine to publish the message" do
33
33
  engine.should_not_receive(:publish)
34
34
  server.process(message, false) {}
35
35
  end
36
-
36
+
37
37
  it "returns an unsuccessful response" do
38
38
  engine.stub(:publish)
39
39
  server.process(message, false) do |response|
@@ -46,15 +46,15 @@ describe "server publish" do
46
46
  end
47
47
  end
48
48
  end
49
-
49
+
50
50
  describe "with an error" do
51
51
  before { message["error"] = "invalid" }
52
-
52
+
53
53
  it "does not tell the engine to publish the message" do
54
54
  engine.should_not_receive(:publish)
55
55
  server.process(message, false) {}
56
56
  end
57
-
57
+
58
58
  it "returns an unsuccessful response" do
59
59
  engine.stub(:publish)
60
60
  server.process(message, false) do |response|
@@ -3,28 +3,28 @@ require "spec_helper"
3
3
  describe "server subscribe" do
4
4
  let(:engine) { mock "engine" }
5
5
  let(:server) { Faye::Server.new }
6
-
6
+
7
7
  before do
8
8
  Faye::Engine.stub(:get).and_return engine
9
9
  end
10
-
10
+
11
11
  describe :subscribe do
12
12
  let(:client_id) { "fakeclientid" }
13
13
  let(:message) {{"channel" => "/meta/subscribe",
14
14
  "clientId" => "fakeclientid",
15
15
  "subscription" => "/foo"
16
16
  }}
17
-
17
+
18
18
  describe "with valid parameters" do
19
19
  before do
20
20
  engine.should_receive(:client_exists).with(client_id).and_yield true
21
21
  end
22
-
22
+
23
23
  it "subscribes the client to the channel" do
24
24
  engine.should_receive(:subscribe).with(client_id, "/foo")
25
25
  server.subscribe(message) {}
26
26
  end
27
-
27
+
28
28
  it "returns a successful response" do
29
29
  engine.stub(:subscribe)
30
30
  server.subscribe(message) do |response|
@@ -36,18 +36,18 @@ describe "server subscribe" do
36
36
  }
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe "with a list of subscriptions" do
41
41
  before do
42
42
  message["subscription"] = ["/foo", "/bar"]
43
43
  end
44
-
44
+
45
45
  it "creates multiple subscriptions" do
46
46
  engine.should_receive(:subscribe).with(client_id, "/foo")
47
47
  engine.should_receive(:subscribe).with(client_id, "/bar")
48
48
  server.subscribe(message) {}
49
49
  end
50
-
50
+
51
51
  it "returns a successful response" do
52
52
  engine.stub(:subscribe)
53
53
  server.subscribe(message) do |response|
@@ -60,17 +60,17 @@ describe "server subscribe" do
60
60
  end
61
61
  end
62
62
  end
63
-
63
+
64
64
  describe "with a subscription pattern" do
65
65
  before do
66
66
  message["subscription"] = "/foo/**"
67
67
  end
68
-
68
+
69
69
  it "subscribes the client to the channel pattern" do
70
70
  engine.should_receive(:subscribe).with(client_id, "/foo/**")
71
71
  server.subscribe(message) {}
72
72
  end
73
-
73
+
74
74
  it "returns a successful response" do
75
75
  engine.stub(:subscribe)
76
76
  server.subscribe(message) do |response|
@@ -84,17 +84,17 @@ describe "server subscribe" do
84
84
  end
85
85
  end
86
86
  end
87
-
87
+
88
88
  describe "with an unknown client" do
89
89
  before do
90
90
  engine.should_receive(:client_exists).with(client_id).and_yield false
91
91
  end
92
-
92
+
93
93
  it "does not subscribe the client to the channel" do
94
94
  engine.should_not_receive(:subscribe)
95
95
  server.subscribe(message) {}
96
96
  end
97
-
97
+
98
98
  it "returns an unsuccessful response" do
99
99
  server.subscribe(message) do |response|
100
100
  response.should == {
@@ -107,18 +107,18 @@ describe "server subscribe" do
107
107
  end
108
108
  end
109
109
  end
110
-
110
+
111
111
  describe "missing clientId" do
112
112
  before do
113
113
  message.delete("clientId")
114
114
  engine.should_receive(:client_exists).with(nil).and_yield false
115
115
  end
116
-
116
+
117
117
  it "does not subscribe the client to the channel" do
118
118
  engine.should_not_receive(:subscribe)
119
119
  server.subscribe(message) {}
120
120
  end
121
-
121
+
122
122
  it "returns an unsuccessful response" do
123
123
  server.subscribe(message) do |response|
124
124
  response.should == {
@@ -130,18 +130,18 @@ describe "server subscribe" do
130
130
  end
131
131
  end
132
132
  end
133
-
133
+
134
134
  describe "missing subscription" do
135
135
  before do
136
136
  message.delete("subscription")
137
137
  engine.should_receive(:client_exists).with(client_id).and_yield true
138
138
  end
139
-
139
+
140
140
  it "does not subscribe the client to the channel" do
141
141
  engine.should_not_receive(:subscribe)
142
142
  server.subscribe(message) {}
143
143
  end
144
-
144
+
145
145
  it "returns an unsuccessful response" do
146
146
  server.subscribe(message) do |response|
147
147
  response.should == {
@@ -154,18 +154,18 @@ describe "server subscribe" do
154
154
  end
155
155
  end
156
156
  end
157
-
157
+
158
158
  describe "with an invalid channel" do
159
159
  before do
160
160
  message["subscription"] = "foo"
161
161
  engine.should_receive(:client_exists).with(client_id).and_yield true
162
162
  end
163
-
163
+
164
164
  it "does not subscribe the client to the channel" do
165
165
  engine.should_not_receive(:subscribe)
166
166
  server.subscribe(message) {}
167
167
  end
168
-
168
+
169
169
  it "returns an unsuccessful response" do
170
170
  server.subscribe(message) do |response|
171
171
  response.should == {
@@ -178,18 +178,18 @@ describe "server subscribe" do
178
178
  end
179
179
  end
180
180
  end
181
-
181
+
182
182
  describe "with a /meta/* channel" do
183
183
  before do
184
184
  message["subscription"] = "/meta/foo"
185
185
  engine.should_receive(:client_exists).with(client_id).and_yield true
186
186
  end
187
-
187
+
188
188
  it "does not subscribe the client to the channel" do
189
189
  engine.should_not_receive(:subscribe)
190
190
  server.subscribe(message) {}
191
191
  end
192
-
192
+
193
193
  it "returns an unsuccessful response" do
194
194
  server.subscribe(message) do |response|
195
195
  response.should == {
@@ -201,12 +201,12 @@ describe "server subscribe" do
201
201
  }
202
202
  end
203
203
  end
204
-
204
+
205
205
  it "subscribes local clients to the channel" do
206
206
  engine.should_receive(:subscribe).with(client_id, "/meta/foo")
207
207
  server.subscribe(message, true) {}
208
208
  end
209
-
209
+
210
210
  it "returns a successful response for local clients" do
211
211
  engine.stub(:subscribe)
212
212
  server.subscribe(message, true) do |response|
@@ -219,18 +219,18 @@ describe "server subscribe" do
219
219
  end
220
220
  end
221
221
  end
222
-
222
+
223
223
  describe "with an error" do
224
224
  before do
225
225
  message["error"] = "invalid"
226
226
  engine.should_receive(:client_exists).with(client_id).and_yield true
227
227
  end
228
-
228
+
229
229
  it "does not subscribe the client to the channel" do
230
230
  engine.should_not_receive(:subscribe)
231
231
  server.subscribe(message) {}
232
232
  end
233
-
233
+
234
234
  it "returns an unsuccessful response" do
235
235
  server.subscribe(message) do |response|
236
236
  response.should == {