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.
- data/History.txt +16 -10
- data/README.rdoc +1 -1
- data/lib/faye-browser-min.js +1 -1
- data/lib/faye-browser-min.js.map +2 -2
- data/lib/faye-browser.js +302 -287
- data/lib/faye.rb +21 -21
- data/lib/faye/adapters/rack_adapter.rb +50 -48
- data/lib/faye/adapters/static_server.rb +22 -22
- data/lib/faye/engines/connection.rb +13 -13
- data/lib/faye/engines/memory.rb +21 -21
- data/lib/faye/engines/proxy.rb +23 -23
- data/lib/faye/error.rb +6 -6
- data/lib/faye/mixins/logging.rb +12 -12
- data/lib/faye/mixins/publisher.rb +6 -6
- data/lib/faye/mixins/timeouts.rb +1 -1
- data/lib/faye/protocol/channel.rb +24 -24
- data/lib/faye/protocol/client.rb +71 -73
- data/lib/faye/protocol/extensible.rb +7 -7
- data/lib/faye/protocol/grammar.rb +13 -13
- data/lib/faye/protocol/server.rb +57 -57
- data/lib/faye/protocol/socket.rb +4 -4
- data/lib/faye/protocol/subscription.rb +4 -4
- data/lib/faye/transport/http.rb +13 -13
- data/lib/faye/transport/local.rb +5 -5
- data/lib/faye/transport/transport.rb +25 -25
- data/lib/faye/transport/web_socket.rb +34 -30
- data/lib/faye/util/namespace.rb +4 -4
- data/spec/browser.html +5 -5
- data/spec/javascript/channel_spec.js +3 -3
- data/spec/javascript/client_spec.js +104 -98
- data/spec/javascript/engine/memory_spec.js +1 -1
- data/spec/javascript/engine_spec.js +70 -70
- data/spec/javascript/faye_spec.js +6 -6
- data/spec/javascript/grammar_spec.js +12 -12
- data/spec/javascript/node_adapter_spec.js +46 -46
- data/spec/javascript/publisher_spec.js +4 -4
- data/spec/javascript/server/connect_spec.js +21 -21
- data/spec/javascript/server/disconnect_spec.js +15 -15
- data/spec/javascript/server/extensions_spec.js +6 -6
- data/spec/javascript/server/handshake_spec.js +18 -18
- data/spec/javascript/server/integration_spec.js +23 -23
- data/spec/javascript/server/publish_spec.js +9 -9
- data/spec/javascript/server/subscribe_spec.js +30 -30
- data/spec/javascript/server/unsubscribe_spec.js +30 -30
- data/spec/javascript/server_spec.js +15 -15
- data/spec/javascript/transport_spec.js +32 -27
- data/spec/node.js +2 -2
- data/spec/ruby/channel_spec.rb +2 -2
- data/spec/ruby/client_spec.rb +100 -92
- data/spec/ruby/engine_examples.rb +51 -51
- data/spec/ruby/faye_spec.rb +5 -5
- data/spec/ruby/grammar_spec.rb +12 -12
- data/spec/ruby/publisher_spec.rb +4 -4
- data/spec/ruby/rack_adapter_spec.rb +34 -34
- data/spec/ruby/server/connect_spec.rb +22 -22
- data/spec/ruby/server/disconnect_spec.rb +16 -16
- data/spec/ruby/server/extensions_spec.rb +8 -8
- data/spec/ruby/server/handshake_spec.rb +20 -20
- data/spec/ruby/server/integration_spec.rb +22 -24
- data/spec/ruby/server/publish_spec.rb +9 -9
- data/spec/ruby/server/subscribe_spec.rb +31 -31
- data/spec/ruby/server/unsubscribe_spec.rb +31 -31
- data/spec/ruby/server_spec.rb +17 -17
- data/spec/ruby/transport_spec.rb +23 -23
- data/spec/testswarm +23 -10
- data/spec/thin_proxy.rb +5 -5
- metadata +90 -59
@@ -8,7 +8,7 @@ JS.ENV.EngineSteps = JS.Test.asyncSteps({
|
|
8
8
|
resume()
|
9
9
|
})
|
10
10
|
},
|
11
|
-
|
11
|
+
|
12
12
|
connect: function(name, engine, resume) {
|
13
13
|
var clientId = this._clients[name]
|
14
14
|
var inboxes = this._inboxes
|
@@ -20,23 +20,23 @@ JS.ENV.EngineSteps = JS.Test.asyncSteps({
|
|
20
20
|
})
|
21
21
|
setTimeout(resume, 10)
|
22
22
|
},
|
23
|
-
|
23
|
+
|
24
24
|
destroy_client: function(name, resume) {
|
25
25
|
this.engine.destroyClient(this._clients[name], resume)
|
26
26
|
},
|
27
|
-
|
27
|
+
|
28
28
|
check_client_id: function(name, pattern, resume) {
|
29
29
|
this.assertMatch(pattern, this._clients[name])
|
30
30
|
resume()
|
31
31
|
},
|
32
|
-
|
32
|
+
|
33
33
|
check_num_clients: function(n, resume) {
|
34
34
|
var ids = new JS.Set()
|
35
35
|
for (var key in this._clients) ids.add(this._clients[key])
|
36
36
|
this.assertEqual(n, ids.count())
|
37
37
|
resume()
|
38
38
|
},
|
39
|
-
|
39
|
+
|
40
40
|
check_client_exists: function(name, exists, resume) {
|
41
41
|
var tc = this
|
42
42
|
tc.engine.clientExists(tc._clients[name], function(actual) {
|
@@ -44,15 +44,15 @@ JS.ENV.EngineSteps = JS.Test.asyncSteps({
|
|
44
44
|
resume()
|
45
45
|
})
|
46
46
|
},
|
47
|
-
|
47
|
+
|
48
48
|
subscribe: function(name, channel, resume) {
|
49
49
|
this.engine.subscribe(this._clients[name], channel, resume)
|
50
50
|
},
|
51
|
-
|
51
|
+
|
52
52
|
unsubscribe: function(name, channel, resume) {
|
53
53
|
this.engine.unsubscribe(this._clients[name], channel, resume)
|
54
54
|
},
|
55
|
-
|
55
|
+
|
56
56
|
publish: function(messages, resume) {
|
57
57
|
messages = [].concat(messages)
|
58
58
|
for (var i = 0, n = messages.length; i < n; i++) {
|
@@ -61,50 +61,50 @@ JS.ENV.EngineSteps = JS.Test.asyncSteps({
|
|
61
61
|
}
|
62
62
|
setTimeout(resume, 20)
|
63
63
|
},
|
64
|
-
|
64
|
+
|
65
65
|
publish_by: function(name, message, resume) {
|
66
66
|
message = Faye.extend({clientId: this._clients[name], id: Faye.random()}, message)
|
67
67
|
this.engine.publish(message)
|
68
68
|
setTimeout(resume, 10)
|
69
69
|
},
|
70
|
-
|
70
|
+
|
71
71
|
ping: function(name, resume) {
|
72
72
|
this.engine.ping(this._clients[name])
|
73
73
|
resume()
|
74
74
|
},
|
75
|
-
|
75
|
+
|
76
76
|
clock_tick: function(time, resume) {
|
77
77
|
setTimeout(resume, time)
|
78
78
|
},
|
79
|
-
|
79
|
+
|
80
80
|
expect_event: function(name, event, args, resume) {
|
81
81
|
var params = [this._clients[name]].concat(args),
|
82
82
|
handler = function() {}
|
83
|
-
|
83
|
+
|
84
84
|
this.engine.bind(event, handler)
|
85
85
|
this.expect(handler, "apply").given(undefined, params)
|
86
86
|
resume()
|
87
87
|
},
|
88
|
-
|
88
|
+
|
89
89
|
expect_no_event: function(name, event, args, resume) {
|
90
90
|
var params = [this._clients[name]].concat(args),
|
91
91
|
handler = function() {}
|
92
|
-
|
92
|
+
|
93
93
|
this.engine.bind(event, handler)
|
94
94
|
this.expect(handler, "apply").exactly(0)
|
95
95
|
resume()
|
96
96
|
},
|
97
|
-
|
97
|
+
|
98
98
|
expect_message: function(name, messages, resume) {
|
99
99
|
this.assertEqual(messages, this._inboxes[name])
|
100
100
|
resume()
|
101
101
|
},
|
102
|
-
|
102
|
+
|
103
103
|
expect_no_message: function(name, resume) {
|
104
104
|
this.assertEqual([], this._inboxes[name])
|
105
105
|
resume()
|
106
106
|
},
|
107
|
-
|
107
|
+
|
108
108
|
check_different_messages: function(a, b, resume) {
|
109
109
|
this.assertNotSame(this._inboxes[a][0], this._inboxes[b][0])
|
110
110
|
resume()
|
@@ -115,56 +115,56 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
115
115
|
sharedExamplesFor("faye engine", function() { with(this) {
|
116
116
|
include(JS.Test.Helpers)
|
117
117
|
include(EngineSteps)
|
118
|
-
|
118
|
+
|
119
119
|
define("create_engine", function() { with(this) {
|
120
120
|
var opts = Faye.extend(options(), engineOpts)
|
121
121
|
return new Faye.Engine.Proxy(opts)
|
122
122
|
}})
|
123
|
-
|
123
|
+
|
124
124
|
define("options", function() { return {timeout: 1} })
|
125
|
-
|
125
|
+
|
126
126
|
before(function() { with(this) {
|
127
127
|
this.engine = create_engine()
|
128
128
|
create_client("alice")
|
129
129
|
create_client("bob")
|
130
130
|
create_client("carol")
|
131
131
|
}})
|
132
|
-
|
132
|
+
|
133
133
|
describe("createClient", function() { with(this) {
|
134
134
|
it("returns a client id", function() { with(this) {
|
135
135
|
create_client("dave")
|
136
136
|
check_client_id("dave", /^[a-z0-9]+$/)
|
137
137
|
}})
|
138
|
-
|
138
|
+
|
139
139
|
it("returns a different id every time", function() { with(this) {
|
140
140
|
$R(1,7).forEach(function(i) { create_client("client" + i) })
|
141
141
|
check_num_clients(10)
|
142
142
|
}})
|
143
|
-
|
143
|
+
|
144
144
|
it("publishes an event", function() { with(this) {
|
145
145
|
expect(engine, "trigger").given("handshake", match(/^[a-z0-9]+$/))
|
146
146
|
create_client("dave")
|
147
147
|
}})
|
148
148
|
}})
|
149
|
-
|
149
|
+
|
150
150
|
describe("clientExists", function() { with(this) {
|
151
151
|
it("returns true if the client id exists", function() { with(this) {
|
152
152
|
check_client_exists("alice", true)
|
153
153
|
}})
|
154
|
-
|
154
|
+
|
155
155
|
it("returns false if the client id does not exist", function() { with(this) {
|
156
156
|
check_client_exists("anything", false)
|
157
157
|
}})
|
158
158
|
}})
|
159
|
-
|
159
|
+
|
160
160
|
describe("ping", function() { with(this) {
|
161
161
|
define("options", function() { return {timeout: 0.3, gc: 0.08} })
|
162
|
-
|
162
|
+
|
163
163
|
it("removes a client if it does not ping often enough", function() { with(this) {
|
164
164
|
clock_tick(700)
|
165
165
|
check_client_exists("alice", false)
|
166
166
|
}})
|
167
|
-
|
167
|
+
|
168
168
|
it("prolongs the life of a client", function() { with(this) {
|
169
169
|
clock_tick(450)
|
170
170
|
ping("alice")
|
@@ -174,13 +174,13 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
174
174
|
check_client_exists("alice", false)
|
175
175
|
}})
|
176
176
|
}})
|
177
|
-
|
177
|
+
|
178
178
|
describe("destroyClient", function() { with(this) {
|
179
179
|
it("removes the given client", function() { with(this) {
|
180
180
|
destroy_client("alice")
|
181
181
|
check_client_exists("alice", false)
|
182
182
|
}})
|
183
|
-
|
183
|
+
|
184
184
|
it("publishes an event", function() { with(this) {
|
185
185
|
expect_event("alice", "disconnect", [])
|
186
186
|
destroy_client("alice")
|
@@ -191,56 +191,56 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
191
191
|
this.message = {"channel": "/messages/foo", "data": "ok"}
|
192
192
|
subscribe("alice", "/messages/foo")
|
193
193
|
}})
|
194
|
-
|
194
|
+
|
195
195
|
it("stops the client receiving messages", function() { with(this) {
|
196
196
|
connect("alice", engine)
|
197
197
|
destroy_client("alice")
|
198
198
|
publish(message)
|
199
199
|
expect_no_message("alice")
|
200
200
|
}})
|
201
|
-
|
201
|
+
|
202
202
|
it("publishes an event", function() { with(this) {
|
203
203
|
expect_event("alice", "disconnect", [])
|
204
204
|
destroy_client("alice")
|
205
205
|
}})
|
206
206
|
}})
|
207
207
|
}})
|
208
|
-
|
208
|
+
|
209
209
|
describe("subscribe", function() { with(this) {
|
210
210
|
it("publishes an event", function() { with(this) {
|
211
211
|
expect_event("alice", "subscribe", ["/messages/foo"])
|
212
212
|
subscribe("alice", "/messages/foo")
|
213
213
|
}})
|
214
|
-
|
214
|
+
|
215
215
|
describe("when the client is subscribed to the channel", function() { with(this) {
|
216
216
|
before(function() { this.subscribe("alice", "/messages/foo") })
|
217
|
-
|
217
|
+
|
218
218
|
it("does not publish an event", function() { with(this) {
|
219
219
|
expect_no_event("alice", "subscribe", ["/messages/foo"])
|
220
220
|
subscribe("alice", "/messages/foo")
|
221
221
|
}})
|
222
222
|
}})
|
223
223
|
}})
|
224
|
-
|
225
|
-
|
224
|
+
|
225
|
+
|
226
226
|
describe("unsubscribe", function() { with(this) {
|
227
227
|
before(function() { this.subscribe("alice", "/messages/bar") })
|
228
|
-
|
228
|
+
|
229
229
|
it("does not publish an event", function() { with(this) {
|
230
230
|
expect_no_event("alice", "unsubscribe", ["/messages/foo"])
|
231
231
|
unsubscribe("alice", "/messages/foo")
|
232
232
|
}})
|
233
|
-
|
233
|
+
|
234
234
|
describe("when the client is subscribed to the channel", function() { with(this) {
|
235
235
|
before(function() { this.subscribe("alice", "/messages/foo") })
|
236
|
-
|
236
|
+
|
237
237
|
it("publishes an event", function() { with(this) {
|
238
238
|
expect_event("alice", "unsubscribe", ["/messages/foo"])
|
239
239
|
unsubscribe("alice", "/messages/foo")
|
240
240
|
}})
|
241
241
|
}})
|
242
242
|
}})
|
243
|
-
|
243
|
+
|
244
244
|
describe("publish", function() { with(this) {
|
245
245
|
before(function() { with(this) {
|
246
246
|
this.message = {"channel": "/messages/foo", "data": "ok", "blank": null}
|
@@ -248,7 +248,7 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
248
248
|
connect("bob", engine)
|
249
249
|
connect("carol", engine)
|
250
250
|
}})
|
251
|
-
|
251
|
+
|
252
252
|
describe("with no subscriptions", function() { with(this) {
|
253
253
|
it("delivers no messages", function() { with(this) {
|
254
254
|
publish(message)
|
@@ -256,66 +256,66 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
256
256
|
expect_no_message("bob")
|
257
257
|
expect_no_message("carol")
|
258
258
|
}})
|
259
|
-
|
259
|
+
|
260
260
|
it("publishes a :publish event with a clientId", function() { with(this) {
|
261
261
|
expect_event("bob", "publish", ["/messages/foo", "ok"])
|
262
262
|
publish_by("bob", message)
|
263
263
|
}})
|
264
|
-
|
264
|
+
|
265
265
|
it("publishes a :publish event with no clientId", function() { with(this) {
|
266
266
|
expect_event(null, "publish", ["/messages/foo", "ok"])
|
267
267
|
publish(message)
|
268
268
|
}})
|
269
269
|
}})
|
270
|
-
|
270
|
+
|
271
271
|
describe("with a subscriber", function() { with(this) {
|
272
272
|
before(function() { with(this) {
|
273
273
|
subscribe("alice", "/messages/foo")
|
274
274
|
}})
|
275
|
-
|
275
|
+
|
276
276
|
it("delivers multibyte messages correctly", function() { with(this) {
|
277
277
|
message.data = "Apple = "
|
278
278
|
publish(message)
|
279
279
|
expect_message("alice", [message])
|
280
280
|
}})
|
281
|
-
|
281
|
+
|
282
282
|
it("delivers messages to the subscribed client", function() { with(this) {
|
283
283
|
publish(message)
|
284
284
|
expect_message("alice", [message])
|
285
285
|
}})
|
286
|
-
|
286
|
+
|
287
287
|
it("publishes a :publish event with a clientId", function() { with(this) {
|
288
288
|
expect_event("bob", "publish", ["/messages/foo", "ok"])
|
289
289
|
publish_by("bob", message)
|
290
290
|
}})
|
291
291
|
}})
|
292
|
-
|
292
|
+
|
293
293
|
describe("with a subscriber that is removed", function() { with(this) {
|
294
294
|
before(function() { with(this) {
|
295
295
|
subscribe("alice", "/messages/foo")
|
296
296
|
unsubscribe("alice", "/messages/foo")
|
297
297
|
}})
|
298
|
-
|
298
|
+
|
299
299
|
it("does not deliver messages to unsubscribed clients", function() { with(this) {
|
300
300
|
publish(message)
|
301
301
|
expect_no_message("alice")
|
302
302
|
expect_no_message("bob")
|
303
303
|
expect_no_message("carol")
|
304
304
|
}})
|
305
|
-
|
305
|
+
|
306
306
|
it("publishes a :publish event with a clientId", function() { with(this) {
|
307
307
|
expect_event("bob", "publish", ["/messages/foo", "ok"])
|
308
308
|
publish_by("bob", message)
|
309
309
|
}})
|
310
310
|
}})
|
311
|
-
|
311
|
+
|
312
312
|
describe("with multiple subscribers", function() { with(this) {
|
313
313
|
before(function() { with(this) {
|
314
314
|
subscribe("alice", "/messages/foo")
|
315
315
|
subscribe("bob", "/messages/bar")
|
316
316
|
subscribe("carol", "/messages/foo")
|
317
317
|
}})
|
318
|
-
|
318
|
+
|
319
319
|
it("delivers messages to the subscribed clients", function() { with(this) {
|
320
320
|
publish(message)
|
321
321
|
expect_message("alice", [message])
|
@@ -323,14 +323,14 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
323
323
|
expect_message("carol", [message])
|
324
324
|
}})
|
325
325
|
}})
|
326
|
-
|
326
|
+
|
327
327
|
describe("with a single wildcard", function() { with(this) {
|
328
328
|
before(function() { with(this) {
|
329
329
|
subscribe("alice", "/messages/*")
|
330
330
|
subscribe("bob", "/messages/bar")
|
331
331
|
subscribe("carol", "/*")
|
332
332
|
}})
|
333
|
-
|
333
|
+
|
334
334
|
it("delivers messages to matching subscriptions", function() { with(this) {
|
335
335
|
publish(message)
|
336
336
|
expect_message("alice", [message])
|
@@ -338,38 +338,38 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
338
338
|
expect_no_message("carol")
|
339
339
|
}})
|
340
340
|
}})
|
341
|
-
|
341
|
+
|
342
342
|
describe("with a double wildcard", function() { with(this) {
|
343
343
|
before(function() { with(this) {
|
344
344
|
subscribe("alice", "/messages/**")
|
345
345
|
subscribe("bob", "/messages/bar")
|
346
346
|
subscribe("carol", "/**")
|
347
347
|
}})
|
348
|
-
|
348
|
+
|
349
349
|
it("delivers messages to matching subscriptions", function() { with(this) {
|
350
350
|
publish(message)
|
351
351
|
expect_message("alice", [message])
|
352
352
|
expect_no_message("bob")
|
353
353
|
expect_message("carol", [message])
|
354
354
|
}})
|
355
|
-
|
355
|
+
|
356
356
|
it("delivers a unique copy of the message to each client", function() { with(this) {
|
357
357
|
publish(message)
|
358
358
|
check_different_messages("alice", "carol")
|
359
359
|
}})
|
360
360
|
}})
|
361
|
-
|
361
|
+
|
362
362
|
describe("with multiple matching subscriptions for the same client", function() { with(this) {
|
363
363
|
before(function() { with(this) {
|
364
364
|
subscribe("alice", "/messages/*")
|
365
365
|
subscribe("alice", "/messages/foo")
|
366
366
|
}})
|
367
|
-
|
367
|
+
|
368
368
|
it("delivers each message once to each client", function() { with(this) {
|
369
369
|
publish(message)
|
370
370
|
expect_message("alice", [message])
|
371
371
|
}})
|
372
|
-
|
372
|
+
|
373
373
|
it("delivers the message as many times as it is published", function() { with(this) {
|
374
374
|
publish([message, message])
|
375
375
|
expect_message("alice", [message, message])
|
@@ -377,35 +377,35 @@ JS.ENV.EngineSpec = JS.Test.describe("Pub/sub engines", function() { with(this)
|
|
377
377
|
}})
|
378
378
|
}})
|
379
379
|
}})
|
380
|
-
|
380
|
+
|
381
381
|
sharedBehavior("distributed engine", function() { with(this) {
|
382
382
|
include(JS.Test.Helpers)
|
383
383
|
include(EngineSteps)
|
384
|
-
|
384
|
+
|
385
385
|
define("create_engine", function() { with(this) {
|
386
386
|
var opts = Faye.extend(options(), engineOpts)
|
387
387
|
return new Faye.Engine.Proxy(opts)
|
388
388
|
}})
|
389
|
-
|
389
|
+
|
390
390
|
define("options", function() { return {timeout: 1} })
|
391
|
-
|
391
|
+
|
392
392
|
before(function() { with(this) {
|
393
393
|
this.left = create_engine()
|
394
394
|
this.right = create_engine()
|
395
395
|
this.engine = left
|
396
|
-
|
396
|
+
|
397
397
|
create_client("alice")
|
398
398
|
create_client("bob")
|
399
|
-
|
399
|
+
|
400
400
|
connect("alice", left)
|
401
401
|
}})
|
402
|
-
|
402
|
+
|
403
403
|
describe("publish", function() { with(this) {
|
404
404
|
before(function() { with(this) {
|
405
405
|
subscribe("alice", "/foo")
|
406
406
|
publish({channel: "/foo", data: "first"})
|
407
407
|
}})
|
408
|
-
|
408
|
+
|
409
409
|
it("only delivers each message once", function() { with(this) {
|
410
410
|
expect_message("alice", [{channel: "/foo", data: "first"}])
|
411
411
|
publish({channel: "/foo", data: "second"})
|