em-eventsource 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em-eventsource.rb +15 -12
- metadata +12 -12
data/lib/em-eventsource.rb
CHANGED
@@ -87,21 +87,15 @@ module EventMachine
|
|
87
87
|
# Cancel subscription
|
88
88
|
def close
|
89
89
|
@ready_state = CLOSED
|
90
|
-
@
|
90
|
+
@conn.close('requested') if @conn
|
91
91
|
end
|
92
92
|
|
93
93
|
protected
|
94
94
|
|
95
95
|
def listen
|
96
|
-
@req = prepare_request
|
97
|
-
@req.errback
|
98
|
-
|
99
|
-
@ready_state = CONNECTING
|
100
|
-
@errors.each { |error| error.call("Connection lost. Reconnecting.") }
|
101
|
-
EM.add_timer(@retry) do
|
102
|
-
listen
|
103
|
-
end
|
104
|
-
end
|
96
|
+
@conn, @req = prepare_request
|
97
|
+
@req.errback(&method(:handle_reconnect))
|
98
|
+
@req.callback(&method(:handle_reconnect))
|
105
99
|
@req.headers do |headers|
|
106
100
|
if headers.status != 200
|
107
101
|
close
|
@@ -127,6 +121,15 @@ module EventMachine
|
|
127
121
|
end
|
128
122
|
end
|
129
123
|
|
124
|
+
def handle_reconnect(*args)
|
125
|
+
return if @ready_state == CLOSED
|
126
|
+
@ready_state = CONNECTING
|
127
|
+
@errors.each { |error| error.call("Connection lost. Reconnecting.") }
|
128
|
+
EM.add_timer(@retry) do
|
129
|
+
listen
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
130
133
|
def handle_stream(stream)
|
131
134
|
data = ""
|
132
135
|
name = nil
|
@@ -164,8 +167,8 @@ module EventMachine
|
|
164
167
|
}
|
165
168
|
headers = @headers.merge({'Cache-Control' => 'no-cache'})
|
166
169
|
headers.merge!({'Last-Event-Id' => @last_event_id }) if not @last_event_id.nil?
|
167
|
-
conn.get({ :query => @query,
|
168
|
-
|
170
|
+
[conn, conn.get({ :query => @query,
|
171
|
+
:head => headers})]
|
169
172
|
end
|
170
173
|
end
|
171
174
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-eventsource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &17007600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0.beta3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17007600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: em-http-request
|
27
|
-
requirement: &
|
27
|
+
requirement: &17007020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17007020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &17006480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *17006480
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &17005880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *17005880
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &17005080 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *17005080
|
69
69
|
description: ! " em-eventsource is an eventmachine library to consume Server-Sent
|
70
70
|
Events streaming API.\n You can find the specification here: http://dev.w3.org/html5/eventsource/\n"
|
71
71
|
email: francois@2metz.fr
|