sse-rails-engine 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8199cc12aecb79f2cf42257959dc6cfe21064c8
4
- data.tar.gz: 93b8d69aecc30216c3168b0de3a7fa2f5b943801
3
+ metadata.gz: 1e920b7f5c24984ee2a13737addac7cc27a8649a
4
+ data.tar.gz: ed5350675bd43869264955774542192abf3d83a5
5
5
  SHA512:
6
- metadata.gz: 5d97b617d68b2c3ff6d2009572cf31c2203b97e201cfc254e3b467173b582313d2d25c9e5acc5d72e9e4f15b6670f781a6072007b036509cf7a52d69fafe8f91
7
- data.tar.gz: 9dc239f25de7ee9abba56329cdb193ba6cb3b5ecb68b1d1c4191ec9590251a1c2fafd88d0a57df9726757cf66dcd177d4f22539079ae64d98689b8b94670736e
6
+ metadata.gz: f7ec726a3b2d2a52ec5477d38516feb4b50c2d9375bb32b6420a87f50057230922b2f879f2fe1fec3af07671680d09964b0e5e04c381eea711e6ecf8410ee940
7
+ data.tar.gz: c1b5081cc1d244619563b441d6ecdb2f6f82712e4c1ff6e51e1d73b196a9204e5cd76a843635d0cf755a6faada48d349ccd3a8aa50d70d7801618417b6cc31de
@@ -1,3 +1,3 @@
1
1
  SseRailsEngine::Engine.routes.draw do
2
- root to: 'sse#connect'
2
+ root to: SseRailsEngine.manager
3
3
  end
@@ -2,17 +2,27 @@ module SseRailsEngine
2
2
  class Manager
3
3
  attr_reader :connections
4
4
 
5
+ SSE_HEADER = ["HTTP/1.1 200 OK\r\n",
6
+ "Content-Type: text/event-stream\r\n",
7
+ "Cache-Control: no-cache, no-store\r\n",
8
+ "Connection: close\r\n",
9
+ "\r\n"].join.freeze
10
+
5
11
  def initialize
6
12
  @mutex = Mutex.new
7
13
  @connections = {}
8
14
  start_heartbeats
9
15
  end
10
16
 
11
- def register(response)
12
- response.headers['Content-Type'] = 'text/event-stream'
13
- response.headers['Cache-Control'] = 'no-cache'
14
- # Perform partial hijack of socket (http://old.blog.phusion.nl/2013/01/23/the-new-rack-socket-hijacking-api/)
15
- response.headers['rack.hijack'] = ->(io) { SseRailsEngine.manager.open_connection(io) }
17
+ def register(env)
18
+ if env['rack.hijack']
19
+ env['rack.hijack'].call
20
+ socket = env['rack.hijack_io']
21
+ # Perform full hijack of socket (http://old.blog.phusion.nl/2013/01/23/the-new-rack-socket-hijacking-api/)
22
+ SseRailsEngine.manager.open_connection(socket)
23
+ else
24
+ raise 'This Rack server does not support hijacking, ensure you are using >= v1.5 of Rack'
25
+ end
16
26
  end
17
27
 
18
28
  def send_event(name, data)
@@ -20,11 +30,13 @@ module SseRailsEngine
20
30
  @connections.dup.each do |stream, sse|
21
31
  begin
22
32
  sse.write(data, event: name)
33
+ stream.flush
23
34
  rescue IOError, Errno::EPIPE, Errno::ETIMEDOUT
24
35
  Rails.logger.debug "SSE Client disconnected: #{stream}"
25
36
  close_connection(stream)
26
37
  rescue => ex
27
38
  Rails.logger.error "Failed to send event to SSE: #{stream} (#{name}, #{data} - #{ex.message} (#{ex.class}"
39
+ close_connection(stream)
28
40
  end
29
41
  end
30
42
  end
@@ -32,11 +44,17 @@ module SseRailsEngine
32
44
 
33
45
  def open_connection(io)
34
46
  Rails.logger.debug "New SSE Client connected: #{io}"
47
+ io.write(SSE_HEADER)
35
48
  @mutex.synchronize do
36
49
  @connections[io] = ActionController::Live::SSE.new(io)
37
50
  end
38
51
  end
39
52
 
53
+ def call(env)
54
+ SseRailsEngine.manager.register(env)
55
+ [ -1, {}, []]
56
+ end
57
+
40
58
  private
41
59
 
42
60
  def close_connection(stream)
@@ -46,7 +64,7 @@ module SseRailsEngine
46
64
  end
47
65
 
48
66
  def start_heartbeats
49
- Rails.logger.debug 'Starting SSE heartbeat thread!!!!!'
67
+ Rails.logger.debug 'Starting SSE heartbeat thread!'
50
68
  Thread.new do
51
69
  loop do
52
70
  sleep SseRailsEngine.heartbeat_interval
@@ -1,3 +1,3 @@
1
1
  module SseRailsEngine
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,535 +1,11 @@
1
- ------------------------------
2
- SseRailsEngineTest: test_truth
3
- ------------------------------
4
- ------------------------------
5
- SseRailsEngineTest: test_truth
6
- ------------------------------
7
- -------------------------------------------------
8
- SseRailsEngine::SseController: test_0001_Connects
9
- -------------------------------------------------
10
- -------------------------------------------------
11
- SseRailsEngine::SseController: test_0001_Connects
12
- -------------------------------------------------
13
- ------------------------------
14
- SseRailsEngineTest: test_truth
15
- ------------------------------
16
- -------------------------------------------------
17
- SseRailsEngine::SseController: test_0001_Connects
18
- -------------------------------------------------
19
- ------------------------------
20
- SseRailsEngineTest: test_truth
21
- ------------------------------
22
- ------------------------------
23
- SseRailsEngineTest: test_truth
24
- ------------------------------
25
- -------------------------------------------------
26
- SseRailsEngine::SseController: test_0001_Connects
27
- -------------------------------------------------
28
- ------------------------------
29
- SseRailsEngineTest: test_truth
30
- ------------------------------
31
- -------------------------------------------------
32
- SseRailsEngine::SseController: test_0001_Connects
33
- -------------------------------------------------
34
- Processing by SseRailsEngine::SseController#connect as HTML
35
- Registering new connection
36
- Completed 500 Internal Server Error in 1ms
37
- ----------------------------------------------------------
38
- SseRailsEngine::FoobarControllerTest: test_should_get_test
39
- ----------------------------------------------------------
40
- ------------------------------
41
- SseRailsEngineTest: test_truth
42
- ------------------------------
43
- ----------------------------------------------------------
44
- SseRailsEngine::FoobarControllerTest: test_should_get_test
45
- ----------------------------------------------------------
46
- -------------------------------------------------
47
- SseRailsEngine::SseController: test_0001_Connects
48
- -------------------------------------------------
49
- Processing by SseRailsEngine::SseController#connect as HTML
50
- Registering new connection
51
- Completed 500 Internal Server Error in 1ms
52
- ----------------------------------------------------------
53
- SseRailsEngine::FoobarControllerTest: test_should_get_test
54
- ----------------------------------------------------------
55
- ----------------------------------------------------------
56
- SseRailsEngine::FoobarControllerTest: test_should_get_test
57
- ----------------------------------------------------------
58
- Processing by SseRailsEngine::FoobarController#bar as HTML
59
- Completed 500 Internal Server Error in 10ms
60
- ----------------------------------------------------------
61
- SseRailsEngine::FoobarControllerTest: test_should_get_test
62
- ----------------------------------------------------------
63
- Processing by SseRailsEngine::FoobarController#bar as HTML
64
- Completed 500 Internal Server Error in 9ms
65
- ----------------------------------------------------------
66
- SseRailsEngine::FoobarControllerTest: test_should_get_test
67
- ----------------------------------------------------------
68
- Processing by SseRailsEngine::FoobarController#bar as HTML
69
- Completed 500 Internal Server Error in 6ms
70
- ----------------------------------------------------------
71
- SseRailsEngine::FoobarControllerTest: test_should_get_test
72
- ----------------------------------------------------------
73
- Processing by SseRailsEngine::FoobarController#bar as JSON
74
- Completed 500 Internal Server Error in 7ms
75
- ----------------------------------------------------------
76
- SseRailsEngine::FoobarControllerTest: test_should_get_test
77
- ----------------------------------------------------------
78
- Processing by SseRailsEngine::FoobarController#bar as JSON
79
- Completed 500 Internal Server Error in 7ms
80
- ----------------------------------------------------------
81
- SseRailsEngine::FoobarControllerTest: test_should_get_test
82
- ----------------------------------------------------------
83
- Processing by SseRailsEngine::FoobarController#bar as HTML
84
- Rendered /Users/shender/Code/sse-rails-engine/app/views/sse_rails_engine/foobar/bar.html.erb (1.6ms)
85
- Completed 200 OK in 9ms (Views: 9.3ms)
86
- ----------------------------------------------------------
87
- SseRailsEngine::FoobarControllerTest: test_should_get_test
88
- ----------------------------------------------------------
89
- Processing by SseRailsEngine::FoobarController#bar as HTML
90
- Rendered /Users/shender/Code/sse-rails-engine/app/views/sse_rails_engine/foobar/bar.html.erb (1.1ms)
91
- Completed 200 OK in 11ms (Views: 10.8ms)
92
- ----------------------------------------------------------
93
- SseRailsEngine::FoobarControllerTest: test_should_get_test
94
- ----------------------------------------------------------
95
- Processing by SseRailsEngine::FoobarController#bar as HTML
96
- Rendered /Users/shender/Code/sse-rails-engine/app/views/sse_rails_engine/foobar/bar.html.erb (1.2ms)
97
- Completed 200 OK in 11ms (Views: 10.7ms)
98
- -------------------------------------------------
99
- SseRailsEngine::SseController: test_0001_Connects
100
- -------------------------------------------------
101
- Processing by SseRailsEngine::SseController#connect as HTML
102
- Registering new connection
103
- Completed 500 Internal Server Error in 1ms
104
- ------------------------------
105
- SseRailsEngineTest: test_truth
106
- ------------------------------
107
- -------------------------------------------------
108
- SseRailsEngine::SseController: test_0001_Connects
109
- -------------------------------------------------
110
- Processing by SseRailsEngine::SseController#connect as HTML
111
- Registering new connection
112
- Sending: heartbeat to 1 clients
113
- ------------------------------
114
- SseRailsEngineTest: test_truth
115
- ------------------------------
116
- Completed in 5009ms
117
- -------------------------------------------------
118
- SseRailsEngine::SseController: test_0001_Connects
119
- -------------------------------------------------
120
- Processing by SseRailsEngine::SseController#connect as HTML
121
- Sending: heartbeat to 1 clients
122
- Completed in 5004ms
123
- -------------------------------------------------
124
- SseRailsEngine::SseController: test_0001_Connects
125
- -------------------------------------------------
126
- -------------------------------------------------
127
- SseRailsEngine::SseController: test_0001_Connects
128
- -------------------------------------------------
129
- Processing by SseRailsEngine::SseController#connect as HTML
130
- Completed 500 Internal Server Error in 8ms
131
- -------------------------------------------------
132
- SseRailsEngine::SseController: test_0001_Connects
133
- -------------------------------------------------
134
- Processing by SseRailsEngine::SseController#connect as HTML
135
- Completed 200 OK in 0ms (Views: 0.2ms)
136
- ------------------------------------------------------------------
137
- SseRailsEngine::SseController: test_0002_sends event to connection
138
- ------------------------------------------------------------------
139
- Processing by SseRailsEngine::SseController#connect as HTML
140
- Completed 200 OK in 0ms (Views: 0.2ms)
141
- Sending: foo to 1 clients
142
- ------------------------------------------------------------------
143
- SseRailsEngine::SseController: test_0002_sends event to connection
144
- ------------------------------------------------------------------
145
- Processing by SseRailsEngine::SseController#connect as HTML
146
- Completed 200 OK in 0ms (Views: 0.2ms)
147
- ------------------------------------------------------------------
148
- SseRailsEngine::SseController: test_0002_sends event to connection
149
- ------------------------------------------------------------------
150
- Processing by SseRailsEngine::SseController#connect as HTML
151
- Completed 200 OK in 0ms (Views: 0.2ms)
152
- Sending: foo to 1 clients
153
- ------------------------------------------------------------------
154
- SseRailsEngine::SseController: test_0002_sends event to connection
155
- ------------------------------------------------------------------
156
- Processing by SseRailsEngine::SseController#connect as HTML
157
- Completed 200 OK in 0ms (Views: 0.2ms)
158
- Sending: foo to 1 clients
159
- ------------------------------------------------------------------
160
- SseRailsEngine::SseController: test_0002_sends event to connection
161
- ------------------------------------------------------------------
162
- Processing by SseRailsEngine::SseController#connect as HTML
163
- Completed 200 OK in 0ms (Views: 0.2ms)
164
- Sending: foo to 1 clients
165
- ------------------------------------------------------------------
166
- SseRailsEngine::SseController: test_0002_sends event to connection
167
- ------------------------------------------------------------------
168
- Processing by SseRailsEngine::SseController#connect as HTML
169
- Completed 200 OK in 1ms (Views: 0.3ms)
170
- Sending: foo to 1 clients
171
- ------------------------------------------------------------------
172
- SseRailsEngine::SseController: test_0001_registers new connections
173
- ------------------------------------------------------------------
174
- Processing by SseRailsEngine::SseController#connect as HTML
175
- Completed 200 OK in 0ms (Views: 0.2ms)
176
- ------------------------------------------------------------------
177
- SseRailsEngine::SseController: test_0001_registers new connections
178
- ------------------------------------------------------------------
179
- Processing by SseRailsEngine::SseController#connect as HTML
180
- Completed 200 OK in 0ms (Views: 0.2ms)
181
- ------------------------------------------------------------------
182
- SseRailsEngine::SseController: test_0001_registers new connections
183
- ------------------------------------------------------------------
184
- Processing by SseRailsEngine::SseController#connect as HTML
185
- Completed 200 OK in 0ms (Views: 0.2ms)
186
- ------------------------------------------------------------------
187
- SseRailsEngine::SseController: test_0001_registers new connections
188
- ------------------------------------------------------------------
189
- Processing by SseRailsEngine::SseController#connect as HTML
190
- Completed 200 OK in 1ms (Views: 0.6ms)
191
- Sending: foo to 1 clients
192
- Sending: foo to 1 clients
193
- Sending: foo to 1 clients
194
- Sending: foo to 1 clients
195
- Sending: foo to 1 clients
196
- Sending: foo to 1 clients
197
- Sending: foo to 1 clients
198
- Sending: foo to 1 clients
199
- Sending: foo to 1 clients
200
- Sending: foo to 2 clients
201
- Sending: foo to 1 clients
202
- Sending: foo to 2 clients
203
- ------------------------------
204
- SseRailsEngineTest: test_truth
205
- ------------------------------
206
- ------------------------------------------------------------------
207
- SseRailsEngine::SseController: test_0001_registers new connections
208
- ------------------------------------------------------------------
209
- Processing by SseRailsEngine::SseController#connect as HTML
210
- Completed 200 OK in 1ms (Views: 0.2ms)
211
- ------------------------------------------------------------------
212
- SseRailsEngine::SseController: test_0002_sends event to connection
213
- ------------------------------------------------------------------
214
- Processing by SseRailsEngine::SseController#connect as HTML
215
- Completed 200 OK in 0ms (Views: 0.1ms)
216
- Sending: foo to 3 clients
217
- Sending: foo to 5 clients
218
- Sending: foo to 1 clients
219
- ------------------------------------------------------------------
220
- SseRailsEngine::SseController: test_0002_sends event to connection
221
- ------------------------------------------------------------------
222
- Processing by SseRailsEngine::SseController#connect as HTML
223
- Completed 200 OK in 0ms (Views: 0.2ms)
224
- Sending: foo to 1 clients
225
- ------------------------------------------------------------------
226
- SseRailsEngine::SseController: test_0002_sends event to connection
227
- ------------------------------------------------------------------
228
- ------------------------------------------------------------------
229
- SseRailsEngine::SseController: test_0002_sends event to connection
230
- ------------------------------------------------------------------
231
- ------------------------------------------------------------------
232
- SseRailsEngine::SseController: test_0001_registers new connections
233
- ------------------------------------------------------------------
234
- ------------------------------------------------------------------
235
- SseRailsEngine::SseController: test_0001_registers new connections
236
- ------------------------------------------------------------------
237
- Processing by SseRailsEngine::SseController#connect as HTML
238
- Completed 200 OK in 1ms (Views: 0.6ms)
239
- ------------------------------------------------------------------
240
- SseRailsEngine::SseController: test_0002_sends event to connection
241
- ------------------------------------------------------------------
242
- Processing by SseRailsEngine::SseController#connect as HTML
243
- Completed 200 OK in 0ms (Views: 0.2ms)
244
- ------------------------------------------------------------------
245
- SseRailsEngine::SseController: test_0001_registers new connections
246
- ------------------------------------------------------------------
247
- Processing by SseRailsEngine::SseController#connect as HTML
248
- Completed 200 OK in 0ms (Views: 0.2ms)
249
- ------------------------------------------------------------------
250
- SseRailsEngine::SseController: test_0002_sends event to connection
251
- ------------------------------------------------------------------
252
- Processing by SseRailsEngine::SseController#connect as HTML
253
- Completed 200 OK in 0ms (Views: 0.1ms)
254
- ------------------------------
255
- SseRailsEngineTest: test_truth
256
- ------------------------------
257
- ------------------------------
258
- SseRailsEngineTest: test_truth
259
- ------------------------------
260
- ------------------------------------------------------------------
261
- SseRailsEngine::SseController: test_0001_registers new connections
262
- ------------------------------------------------------------------
263
- Processing by SseRailsEngine::SseController#connect as HTML
264
- Completed 200 OK in 0ms (Views: 0.2ms)
265
- ------------------------------------------------------------------
266
- SseRailsEngine::SseController: test_0002_sends event to connection
267
- ------------------------------------------------------------------
268
- Processing by SseRailsEngine::SseController#connect as HTML
269
- Completed 200 OK in 0ms (Views: 0.1ms)
270
- ------------------------------------------------------------------
271
- SseRailsEngine::SseController: test_0001_registers new connections
272
- ------------------------------------------------------------------
273
- Processing by SseRailsEngine::SseController#connect as HTML
274
- Completed 200 OK in 1ms (Views: 0.2ms)
275
- ------------------------------------------------------------------
276
- SseRailsEngine::SseController: test_0002_sends event to connection
277
- ------------------------------------------------------------------
278
- Processing by SseRailsEngine::SseController#connect as HTML
279
- Completed 200 OK in 0ms (Views: 0.1ms)
280
- ------------------------------
281
- SseRailsEngineTest: test_truth
282
- ------------------------------
283
- ------------------------------
284
- SseRailsEngineTest: test_truth
285
- ------------------------------
286
- ------------------------------------------------------------------
287
- SseRailsEngine::SseController: test_0001_registers new connections
288
- ------------------------------------------------------------------
289
- Processing by SseRailsEngine::SseController#connect as HTML
290
- Completed 200 OK in 1ms (Views: 0.3ms)
291
- ------------------------------------------------------------------
292
- SseRailsEngine::SseController: test_0002_sends event to connection
293
- ------------------------------------------------------------------
294
- Processing by SseRailsEngine::SseController#connect as HTML
295
- Completed 200 OK in 0ms (Views: 0.1ms)
296
- ------------------------------------------------------------------
297
- SseRailsEngine::SseController: test_0001_registers new connections
298
- ------------------------------------------------------------------
299
- Processing by SseRailsEngine::SseController#connect as HTML
300
- Completed 200 OK in 0ms (Views: 0.2ms)
301
- ------------------------------------------------------------------
302
- SseRailsEngine::SseController: test_0002_sends event to connection
303
- ------------------------------------------------------------------
304
- Processing by SseRailsEngine::SseController#connect as HTML
305
- Completed 200 OK in 0ms (Views: 0.1ms)
306
- ------------------------------
307
- SseRailsEngineTest: test_truth
308
- ------------------------------
309
- ------------------------------
310
- SseRailsEngineTest: test_truth
311
- ------------------------------
312
- ------------------------------------------------------------------
313
- SseRailsEngine::SseController: test_0002_sends event to connection
314
- ------------------------------------------------------------------
315
- Processing by SseRailsEngine::SseController#connect as HTML
316
- Completed 200 OK in 0ms (Views: 0.3ms)
317
- ------------------------------------------------------------------
318
- SseRailsEngine::SseController: test_0001_registers new connections
319
- ------------------------------------------------------------------
320
- Processing by SseRailsEngine::SseController#connect as HTML
321
- Completed 200 OK in 0ms (Views: 0.2ms)
322
- ------------------------------------------------------------------
323
- SseRailsEngine::SseController: test_0001_registers new connections
324
- ------------------------------------------------------------------
325
- Processing by SseRailsEngine::SseController#connect as HTML
326
- Completed 200 OK in 0ms (Views: 0.2ms)
327
- ------------------------------------------------------------------
328
- SseRailsEngine::SseController: test_0002_sends event to connection
329
- ------------------------------------------------------------------
330
- Processing by SseRailsEngine::SseController#connect as HTML
331
- Completed 200 OK in 0ms (Views: 0.2ms)
332
- ------------------------------
333
- SseRailsEngineTest: test_truth
334
- ------------------------------
335
- ------------------------------------------------------------------
336
- SseRailsEngine::SseController: test_0001_registers new connections
337
- ------------------------------------------------------------------
338
- Processing by SseRailsEngine::SseController#connect as HTML
339
- Completed 200 OK in 1ms (Views: 0.3ms)
340
- ------------------------------------------------------------------
341
- SseRailsEngine::SseController: test_0002_sends event to connection
342
- ------------------------------------------------------------------
343
- Processing by SseRailsEngine::SseController#connect as HTML
344
- Completed 200 OK in 0ms (Views: 0.1ms)
345
- ------------------------------
346
- SseRailsEngineTest: test_truth
347
- ------------------------------
348
- ------------------------------------------------------------------
349
- SseRailsEngine::SseController: test_0001_registers new connections
350
- ------------------------------------------------------------------
351
- Processing by SseRailsEngine::SseController#connect as HTML
352
- Completed 200 OK in 0ms (Views: 0.2ms)
353
- ------------------------------------------------------------------
354
- SseRailsEngine::SseController: test_0002_sends event to connection
355
- ------------------------------------------------------------------
356
- Processing by SseRailsEngine::SseController#connect as HTML
357
- Completed 200 OK in 0ms (Views: 0.1ms)
358
- Starting SSE heartbeat thread!!!!!
359
- ------------------------------------------------------------------
360
- SseRailsEngine::SseController: test_0002_sends event to connection
361
- ------------------------------------------------------------------
362
- Processing by SseRailsEngine::SseController#connect as HTML
363
- Completed 500 Internal Server Error in 0ms
364
- ------------------------------------------------------------------
365
- SseRailsEngine::SseController: test_0001_registers new connections
366
- ------------------------------------------------------------------
367
- Processing by SseRailsEngine::SseController#connect as HTML
368
- Completed 500 Internal Server Error in 0ms
369
- Starting SSE heartbeat thread!!!!!
370
- Starting SSE heartbeat thread!!!!!
371
- New SSE Client connected: #<StringIO:0x007fc3b3512498>
372
- Starting SSE heartbeat thread!!!!!
373
- Starting SSE heartbeat thread!!!!!
374
- New SSE Client connected: #<StringIO:0x007f88b3ad3a20>
375
- SSE Client disconnected: #<StringIO:0x007f88b3ad3a20>
376
- Starting SSE heartbeat thread!!!!!
377
- New SSE Client connected: #<StringIO:0x007fb040de4ed0>
378
- Starting SSE heartbeat thread!!!!!
379
- New SSE Client connected: #<StringIO:0x007f8efcf18b68>
380
- Starting SSE heartbeat thread!!!!!
381
- New SSE Client connected: #<StringIO:0x007fc1ca020358>
382
- New SSE Client connected: #<StringIO:0x007fc1c9dea750>
383
- New SSE Client connected: #<StringIO:0x007fc1c9dba9d8>
384
- Starting SSE heartbeat thread!!!!!
385
- Starting SSE heartbeat thread!!!!!
386
- New SSE Client connected: #<StringIO:0x007f8e3b1e31d0>
387
- Starting SSE heartbeat thread!!!!!
388
- New SSE Client connected: #<StringIO:0x007f8e3b1b3c28>
389
- Starting SSE heartbeat thread!!!!!
390
- Starting SSE heartbeat thread!!!!!
391
- Starting SSE heartbeat thread!!!!!
392
- New SSE Client connected: #<StringIO:0x007f8e3b143248>
393
- Starting SSE heartbeat thread!!!!!
394
- New SSE Client connected: #<StringIO:0x007f8e3b130c60>
395
- Starting SSE heartbeat thread!!!!!
396
- Starting SSE heartbeat thread!!!!!
397
- Starting SSE heartbeat thread!!!!!
398
- New SSE Client connected: #<StringIO:0x007fd622d27378>
399
- Starting SSE heartbeat thread!!!!!
400
- New SSE Client connected: #<StringIO:0x007fd622d04648>
401
- Starting SSE heartbeat thread!!!!!
402
- New SSE Client connected: #<StringIO:0x007fd622cd4da8>
403
- Starting SSE heartbeat thread!!!!!
404
- New SSE Client connected: #<StringIO:0x007fd622c94960>
405
- Starting SSE heartbeat thread!!!!!
406
- Starting SSE heartbeat thread!!!!!
407
- New SSE Client connected: #<StringIO:0x007fd1c25a9560>
408
- Starting SSE heartbeat thread!!!!!
409
- Starting SSE heartbeat thread!!!!!
410
- New SSE Client connected: #<StringIO:0x007f840cd439f0>
411
- Starting SSE heartbeat thread!!!!!
412
- Starting SSE heartbeat thread!!!!!
413
- New SSE Client connected: #<StringIO:0x007f7feb5be3a8>
414
- Starting SSE heartbeat thread!!!!!
415
- New SSE Client connected: #<StringIO:0x007f7feb576288>
416
- SSE Client disconnected: #<StringIO:0x007f7feb576288>
417
- Starting SSE heartbeat thread!!!!!
418
- Starting SSE heartbeat thread!!!!!
419
- New SSE Client connected: #<StringIO:0x007f7feb5279d0>
420
- Starting SSE heartbeat thread!!!!!
421
- New SSE Client connected: #<StringIO:0x007f7feb506b90>
422
- ------------------------------------------------------------------
423
- SseRailsEngine::SseController: test_0001_registers new connections
424
- ------------------------------------------------------------------
425
- Processing by SseRailsEngine::SseController#connect as HTML
426
- Completed 500 Internal Server Error in 0ms
427
- ------------------------------------------------------------------
428
- SseRailsEngine::SseController: test_0001_registers new connections
429
- ------------------------------------------------------------------
430
- Processing by SseRailsEngine::SseController#connect as HTML
431
- Starting SSE heartbeat thread!!!!!
432
- Completed 200 OK in 0ms (Views: 0.2ms)
433
- ------------------------------------------------------------------
434
- SseRailsEngine::SseController: test_0001_registers new connections
435
- ------------------------------------------------------------------
436
- Processing by SseRailsEngine::SseController#connect as HTML
437
- Starting SSE heartbeat thread!!!!!
438
- Completed 200 OK in 0ms (Views: 0.1ms)
439
- ------------------------------------------------------------------
440
- SseRailsEngine::SseController: test_0001_registers new connections
441
- ------------------------------------------------------------------
442
- Processing by SseRailsEngine::SseController#connect as HTML
443
- Starting SSE heartbeat thread!!!!!
444
- Completed 200 OK in 0ms (Views: 0.2ms)
445
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007ff07459b8b8>
446
- ------------------------------------------------------------------
447
- SseRailsEngine::SseController: test_0001_registers new connections
448
- ------------------------------------------------------------------
449
- Processing by SseRailsEngine::SseController#connect as HTML
450
- Starting SSE heartbeat thread!!!!!
451
- Completed 200 OK in 0ms (Views: 0.2ms)
452
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007fd6c12fbf30>
453
- ------------------------------------------------------------------
454
- SseRailsEngine::SseController: test_0001_registers new connections
455
- ------------------------------------------------------------------
456
- ------------------------------------------------------------------
457
- SseRailsEngine::SseController: test_0001_registers new connections
458
- ------------------------------------------------------------------
459
- Processing by SseRailsEngine::SseController#connect as HTML
460
- Starting SSE heartbeat thread!!!!!
461
- Completed 200 OK in 0ms (Views: 0.2ms)
462
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007fb813d73020>
463
- Starting SSE heartbeat thread!!!!!
464
- New SSE Client connected: #<StringIO:0x007f93e9fd9e20>
465
- Starting SSE heartbeat thread!!!!!
466
- New SSE Client connected: #<StringIO:0x007f93e9fd32c8>
467
- Starting SSE heartbeat thread!!!!!
468
- Starting SSE heartbeat thread!!!!!
469
- New SSE Client connected: #<StringIO:0x007f93e9fd11d0>
470
- Starting SSE heartbeat thread!!!!!
471
- New SSE Client connected: #<StringIO:0x007f93e9fc9818>
472
- SSE Client disconnected: #<StringIO:0x007f93e9fc9818>
473
- Starting SSE heartbeat thread!!!!!
474
- ------------------------------------------------------------------
475
- SseRailsEngine::SseController: test_0002_sends event to connection
476
- ------------------------------------------------------------------
477
- Processing by SseRailsEngine::SseController#connect as HTML
478
- Starting SSE heartbeat thread!!!!!
479
- Completed 200 OK in 0ms (Views: 0.1ms)
480
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007f93e9f99d48>
481
- ------------------------------------------------------------------
482
- SseRailsEngine::SseController: test_0001_registers new connections
483
- ------------------------------------------------------------------
484
- Processing by SseRailsEngine::SseController#connect as HTML
485
- Starting SSE heartbeat thread!!!!!
486
- Completed 200 OK in 0ms (Views: 0.1ms)
487
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007f93e9f88700>
488
- Starting SSE heartbeat thread!!!!!
489
- New SSE Client connected: #<StringIO:0x007fc84d982f48>
490
- Starting SSE heartbeat thread!!!!!
491
- Starting SSE heartbeat thread!!!!!
492
- New SSE Client connected: #<StringIO:0x007fc84ca5a1d8>
493
- Starting SSE heartbeat thread!!!!!
494
- New SSE Client connected: #<StringIO:0x007fc84d97ba40>
495
- Starting SSE heartbeat thread!!!!!
496
- New SSE Client connected: #<StringIO:0x007fc84d97a4d8>
497
- SSE Client disconnected: #<StringIO:0x007fc84d97a4d8>
498
- ------------------------------------------------------------------
499
- SseRailsEngine::SseController: test_0001_registers new connections
500
- ------------------------------------------------------------------
501
- Processing by SseRailsEngine::SseController#connect as HTML
502
- Starting SSE heartbeat thread!!!!!
503
- Completed 200 OK in 0ms (Views: 0.1ms)
504
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007fc84d909698>
505
- ------------------------------------------------------------------
506
- SseRailsEngine::SseController: test_0002_sends event to connection
507
- ------------------------------------------------------------------
508
- Processing by SseRailsEngine::SseController#connect as HTML
509
- Starting SSE heartbeat thread!!!!!
510
- Completed 200 OK in 0ms (Views: 0.1ms)
511
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007fc84ca50b38>
512
- ------------------------------------------------------------------
513
- SseRailsEngine::SseController: test_0001_registers new connections
514
- ------------------------------------------------------------------
515
- Processing by SseRailsEngine::SseController#connect as HTML
516
- Starting SSE heartbeat thread!!!!!
517
- Completed 200 OK in 0ms (Views: 0.1ms)
518
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007fa0ec02a320>
519
- ------------------------------------------------------------------
520
- SseRailsEngine::SseController: test_0002_sends event to connection
521
- ------------------------------------------------------------------
522
- Processing by SseRailsEngine::SseController#connect as HTML
523
- Starting SSE heartbeat thread!!!!!
524
- Completed 200 OK in 0ms (Views: 0.1ms)
525
- New SSE Client connected: #<ActionDispatch::Response::Buffer:0x007fa0ec0026b8>
526
- Starting SSE heartbeat thread!!!!!
527
- New SSE Client connected: #<StringIO:0x007fa0ebf79430>
528
- Starting SSE heartbeat thread!!!!!
529
- Starting SSE heartbeat thread!!!!!
530
- New SSE Client connected: #<StringIO:0x007fa0ebf6bf88>
531
- SSE Client disconnected: #<StringIO:0x007fa0ebf6bf88>
532
- Starting SSE heartbeat thread!!!!!
533
- New SSE Client connected: #<StringIO:0x007fa0ebf6a2c8>
534
- Starting SSE heartbeat thread!!!!!
535
- New SSE Client connected: #<StringIO:0x007fa0ebf68c48>
1
+ Starting SSE heartbeat thread!
2
+ Starting SSE heartbeat thread!
3
+ New SSE Client connected: #<StringIO:0x007fa8041d31a8>
4
+ SSE Client disconnected: #<StringIO:0x007fa8041d31a8>
5
+ Starting SSE heartbeat thread!
6
+ New SSE Client connected: #<StringIO:0x007fa8041d0020>
7
+ Starting SSE heartbeat thread!
8
+ New SSE Client connected: #<StringIO:0x007fa8041c9338>
9
+ Starting SSE heartbeat thread!
10
+ Starting SSE heartbeat thread!
11
+ New SSE Client connected: #<StringIO:0x007fa8041c0850>
@@ -1,15 +1,21 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe SseRailsEngine::Manager do
4
- let(:response) { Hashie::Mash.new(stream: StringIO.new, headers: {}) }
5
4
  let(:manager) { SseRailsEngine::manager }
6
-
7
- before { SseRailsEngine.instance_variable_set(:@manager, nil) }
5
+ let(:env) {
6
+ Hashie::Mash.new('rack.hijack?' => true,
7
+ 'rack.hijack' => ->() { },
8
+ 'rack.hijack_io' => StringIO.new)
9
+ }
10
+
11
+ before do
12
+ SseRailsEngine.instance_variable_set(:@manager, nil)
13
+ SseRailsEngine::Manager.stubs(:start_heartbeats).returns(true)
14
+ end
8
15
 
9
16
  it 'registers new response streams' do
10
17
  manager.connections.size.must_equal 0
11
- manager.register(response)
12
- response.headers['rack.hijack'].call(response.stream)
18
+ manager.register(env)
13
19
  manager.connections.size.must_equal 1
14
20
  end
15
21
 
@@ -20,24 +26,21 @@ describe SseRailsEngine::Manager do
20
26
  it 'closes connection when client disconnects' do
21
27
  ActionController::Live::SSE.any_instance.stubs(:write).raises(IOError)
22
28
 
23
- manager.register(response)
24
- response.headers['rack.hijack'].call(response.stream)
29
+ manager.register(env)
25
30
  manager.connections.size.must_equal 1
26
31
  manager.send_event('foo', 'bar')
27
32
  manager.connections.size.must_equal 0
28
33
  end
29
34
 
30
35
  it 'writes string event to stream' do
31
- manager.register(response)
32
- response.headers['rack.hijack'].call(response.stream)
36
+ manager.register(env)
33
37
  manager.send_event('foo', 'bar')
34
- response.stream.string.must_equal "event: foo\ndata: bar\n\n"
38
+ env['rack.hijack_io'].string.must_equal(SseRailsEngine::Manager::SSE_HEADER + "event: foo\ndata: bar\n\n")
35
39
  end
36
40
 
37
41
  it 'writes event object to stream' do
38
- manager.register(response)
39
- response.headers['rack.hijack'].call(response.stream)
42
+ manager.register(env)
40
43
  manager.send_event('foo', { a: 123, 'b' => 'abc', c: { foo: 'bar' } })
41
- response.stream.string.must_equal "event: foo\ndata: {\"a\":123,\"b\":\"abc\",\"c\":{\"foo\":\"bar\"}}\n\n"
44
+ env['rack.hijack_io'].string.must_equal(SseRailsEngine::Manager::SSE_HEADER + "event: foo\ndata: {\"a\":123,\"b\":\"abc\",\"c\":{\"foo\":\"bar\"}}\n\n")
42
45
  end
43
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sse-rails-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Hender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,8 +90,6 @@ files:
90
90
  - LICENSE
91
91
  - README.md
92
92
  - Rakefile
93
- - app/controllers/sse_rails_engine/application_controller.rb
94
- - app/controllers/sse_rails_engine/sse_controller.rb
95
93
  - config/initializers/sse_rails_engine.rb
96
94
  - config/routes.rb
97
95
  - lib/sse-rails-engine.rb
@@ -99,7 +97,6 @@ files:
99
97
  - lib/sse_rails_engine/manager.rb
100
98
  - lib/sse_rails_engine/version.rb
101
99
  - lib/tasks/sse_rails_engine_tasks.rake
102
- - test/controllers/sse_rails_engine/sse_controller_test.rb
103
100
  - test/dummy/Rakefile
104
101
  - test/dummy/app/assets/javascripts/application.js
105
102
  - test/dummy/app/assets/stylesheets/application.css
@@ -127,13 +124,11 @@ files:
127
124
  - test/dummy/config/locales/en.yml
128
125
  - test/dummy/config/routes.rb
129
126
  - test/dummy/config/secrets.yml
130
- - test/dummy/log/development.log
131
127
  - test/dummy/log/test.log
132
128
  - test/dummy/public/404.html
133
129
  - test/dummy/public/422.html
134
130
  - test/dummy/public/500.html
135
131
  - test/dummy/public/favicon.ico
136
- - test/integration/navigation_test.rb
137
132
  - test/lib/sse_rails_engine/manager_test.rb
138
133
  - test/lib/sse_rails_engine_test.rb
139
134
  - test/test_helper.rb
@@ -163,7 +158,6 @@ specification_version: 4
163
158
  summary: Provides SSE connection tracking and broadcasting of events from anywhere
164
159
  in Rails app
165
160
  test_files:
166
- - test/controllers/sse_rails_engine/sse_controller_test.rb
167
161
  - test/dummy/app/assets/javascripts/application.js
168
162
  - test/dummy/app/assets/stylesheets/application.css
169
163
  - test/dummy/app/controllers/application_controller.rb
@@ -190,14 +184,12 @@ test_files:
190
184
  - test/dummy/config/routes.rb
191
185
  - test/dummy/config/secrets.yml
192
186
  - test/dummy/config.ru
193
- - test/dummy/log/development.log
194
187
  - test/dummy/log/test.log
195
188
  - test/dummy/public/404.html
196
189
  - test/dummy/public/422.html
197
190
  - test/dummy/public/500.html
198
191
  - test/dummy/public/favicon.ico
199
192
  - test/dummy/Rakefile
200
- - test/integration/navigation_test.rb
201
193
  - test/lib/sse_rails_engine/manager_test.rb
202
194
  - test/lib/sse_rails_engine_test.rb
203
195
  - test/test_helper.rb
@@ -1,4 +0,0 @@
1
- module SseRailsEngine
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
@@ -1,11 +0,0 @@
1
- require_dependency "sse_rails_engine/application_controller"
2
-
3
- module SseRailsEngine
4
- class SseController < ApplicationController
5
- def connect
6
- raise 'This Rack server does not support hijacking, ensure you are using >v1.5 of Rack' unless request.env['rack.hijack?']
7
- SseRailsEngine.manager.register(response)
8
- render json: {}
9
- end
10
- end
11
- end
@@ -1,24 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- describe SseRailsEngine::SseController do
4
- before do
5
- SseRailsEngine.instance_variable_set(:@manager, nil)
6
- @routes = SseRailsEngine::Engine.routes
7
- request.env['rack.hijack?'] = 1
8
- end
9
-
10
- it 'registers new connections' do
11
- get :connect
12
- assert_response :success
13
- response.headers['rack.hijack'].call(response.stream)
14
- SseRailsEngine.manager.connections.size.must_equal 1
15
- end
16
-
17
- it 'sends event to connection' do
18
- get :connect
19
- response.headers['rack.hijack'].call(response.stream)
20
- SseRailsEngine.manager.connections.size.must_equal 1
21
- ActionController::Live::SSE.any_instance.expects(:write).with('bar', event: 'foo').once
22
- SseRailsEngine.send_event('foo', 'bar')
23
- end
24
- end
File without changes
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NavigationTest < ActionDispatch::IntegrationTest
4
-
5
- # test "the truth" do
6
- # assert true
7
- # end
8
- end
9
-