em-eventsource 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +46 -22
  2. data/lib/em-eventsource.rb +6 -1
  3. metadata +12 -12
data/README.md CHANGED
@@ -18,52 +18,76 @@ If you use bundler, add it to your Gemfile:
18
18
 
19
19
  Basic usage:
20
20
 
21
- require "em-eventsource"
22
- EM.run do
23
- source = EventMachine::EventSource.new("http://example.com/streaming")
24
- source.message do |message|
25
- puts "new message #{message}"
26
- end
27
- source.start # Start listening
28
- end
21
+ ```ruby
22
+ require "em-eventsource"
23
+ EM.run do
24
+ source = EventMachine::EventSource.new("http://example.com/streaming")
25
+ source.message do |message|
26
+ puts "new message #{message}"
27
+ end
28
+ source.start # Start listening
29
+ end
30
+ ```
29
31
 
30
32
  Listening specific event name:
31
33
 
32
- source.on "eventname" do |message|
33
- puts "eventname #{message}"
34
- end
34
+ ```ruby
35
+ source.on "eventname" do |message|
36
+ puts "eventname #{message}"
37
+ end
38
+ ```
35
39
 
36
40
  Handle error:
37
41
 
38
- source.error do |error|
39
- puts "error #{error}"
40
- end
42
+ ```ruby
43
+ source.error do |error|
44
+ puts "error #{error}"
45
+ end
46
+ ```
41
47
 
42
48
  Handle open stream:
43
49
 
44
- source.open do
45
- puts "opened"
46
- end
50
+ ```ruby
51
+ source.open do
52
+ puts "opened"
53
+ end
54
+ ```
47
55
 
48
56
  Close the stream:
49
57
 
50
- source.close
58
+ ```ruby
59
+ source.close
60
+ ```
51
61
 
52
62
  Current status of the connection:
53
63
 
54
- source.ready_state # Can be EM::EventSource::CLOSED, EM::EventSource::CONNECTING, EM::EventSource::OPEN
64
+ ```ruby
65
+ source.ready_state # Can be EM::EventSource::CLOSED, EM::EventSource::CONNECTING, EM::EventSource::OPEN
66
+ ```
55
67
 
56
68
  Override the default retry value (if the connection is lost):
57
69
 
58
- source.retry = 5 # in seconds
70
+ ```ruby
71
+ source.retry = 5 # in seconds (default 3)
72
+ ```
59
73
 
60
74
  Get Last-Event-Id value:
61
75
 
62
- source.last_event_id
76
+ ```ruby
77
+ source.last_event_id
78
+ ```
63
79
 
64
80
  Attach middleware:
65
81
 
66
- source.use EM::Middleware::JSONResponse
82
+ ```ruby
83
+ source.use EM::Middleware::JSONResponse
84
+ ```
85
+
86
+ Set the inactivity timeout. Set to 0 to disable the timeout.
87
+
88
+ ```ruby
89
+ source.inactivity_timeout = 120 # in seconds (default: 60).
90
+ ```
67
91
 
68
92
  ## Licence
69
93
 
@@ -17,6 +17,10 @@ module EventMachine
17
17
  attr_writer :retry
18
18
  # Get value of last event id
19
19
  attr_reader :last_event_id
20
+ # Get the inactivity timeout
21
+ attr_reader :inactivity_timeout
22
+ # Set the inactivity timeout
23
+ attr_writer :inactivity_timeout
20
24
  # Ready state
21
25
  # The connection has not yet been established, or it was closed and the user agent is reconnecting.
22
26
  CONNECTING = 0
@@ -37,6 +41,7 @@ module EventMachine
37
41
 
38
42
  @last_event_id = nil
39
43
  @retry = 3 # seconds
44
+ @inactivity_timeout = 60 # seconds
40
45
 
41
46
  @opens = []
42
47
  @errors = []
@@ -152,7 +157,7 @@ module EventMachine
152
157
  end
153
158
 
154
159
  def prepare_request
155
- conn = EM::HttpRequest.new(@url)
160
+ conn = EM::HttpRequest.new(@url, :inactivity_timeout => @inactivity_timeout)
156
161
  @middlewares.each { |middleware|
157
162
  block = middleware.pop
158
163
  conn.use *middleware, &block
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
4
+ version: 0.1.5
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: 2011-09-01 00:00:00.000000000Z
12
+ date: 2011-09-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &8006620 !ruby/object:Gem::Requirement
16
+ requirement: &21570940 !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: *8006620
24
+ version_requirements: *21570940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: em-http-request
27
- requirement: &8006140 !ruby/object:Gem::Requirement
27
+ requirement: &21570460 !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: *8006140
35
+ version_requirements: *21570460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &8005680 !ruby/object:Gem::Requirement
38
+ requirement: &21570000 !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: *8005680
46
+ version_requirements: *21570000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &8005300 !ruby/object:Gem::Requirement
49
+ requirement: &21569620 !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: *8005300
57
+ version_requirements: *21569620
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &8004840 !ruby/object:Gem::Requirement
60
+ requirement: &21569160 !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: *8004840
68
+ version_requirements: *21569160
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.de.metz@af83.com