Class: SSE::EventSource
- Inherits:
-
Object
- Object
- SSE::EventSource
- Defined in:
- lib/sse-client.rb
Constant Summary collapse
- CONNECTING =
The connection has not yet been established, or it was closed and the user agent is reconnecting.
0
- OPEN =
The user agent has an open connection and is dispatching events as it receives them.
1
- CLOSED =
The connection is not open, and the user agent is not trying to reconnect. Either there was a fatal error or the close() method was invoked.
2
Instance Attribute Summary collapse
-
#ready_state ⇒ Object
readonly
Get ready state.
-
#url ⇒ Object
readonly
Get API url.
Instance Method Summary collapse
- #error(&block) ⇒ Object
-
#initialize(url, query = {}, headers = {}, before_execution_proc: nil) ⇒ EventSource
constructor
A new instance of EventSource.
- #message(&block) ⇒ Object
- #on(name, &block) ⇒ Object
- #open(&block) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(url, query = {}, headers = {}, before_execution_proc: nil) ⇒ EventSource
Returns a new instance of EventSource.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sse-client.rb', line 19 def initialize(url, query = {}, headers = {}, before_execution_proc: nil) @url = url @headers = headers @headers['params'] = query @ready_state = CLOSED @before_execution_proc = before_execution_proc @opens = [] @errors = [] @messages = [] @on = {} end |
Instance Attribute Details
#ready_state ⇒ Object (readonly)
Get ready state
10 11 12 |
# File 'lib/sse-client.rb', line 10 def ready_state @ready_state end |
#url ⇒ Object (readonly)
Get API url
8 9 10 |
# File 'lib/sse-client.rb', line 8 def url @url end |
Instance Method Details
#error(&block) ⇒ Object
50 51 52 |
# File 'lib/sse-client.rb', line 50 def error(&block) @errors << block end |
#message(&block) ⇒ Object
46 47 48 |
# File 'lib/sse-client.rb', line 46 def (&block) @messages << block end |
#on(name, &block) ⇒ Object
41 42 43 44 |
# File 'lib/sse-client.rb', line 41 def on(name, &block) @on[name] ||= [] @on[name] << block end |
#open(&block) ⇒ Object
37 38 39 |
# File 'lib/sse-client.rb', line 37 def open(&block) @opens << block end |
#start ⇒ Object
32 33 34 35 |
# File 'lib/sse-client.rb', line 32 def start @ready_state = CONNECTING listen end |