Class: Urbit::Receiver
- Inherits:
-
SSE::Client
- Object
- SSE::Client
- Urbit::Receiver
- Defined in:
- lib/urbit/receiver.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#facts ⇒ Object
Returns the value of attribute facts.
Instance Method Summary collapse
- #default_logger ⇒ Object
-
#initialize(channel:) ⇒ Receiver
constructor
A new instance of Receiver.
- #open? ⇒ Boolean
Constructor Details
#initialize(channel:) ⇒ Receiver
Returns a new instance of Receiver.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/urbit/receiver.rb', line 11 def initialize(channel:) super(channel.url, headers: self.headers(channel), logger: self.default_logger) do |rec| # We are now listening on a socket for SSE::Events. This block will be called for each one. rec.on_event do |event| # Wrap the returned event in a Fact. @facts << (f = Fact.collect(channel: channel, event: event)) # We need to acknowlege each message or urbit will eventually disconnect us. # We record the ack with the Fact itself. f.add_ack(ack: (ack = AckMessage.new(channel: channel, sse_message_id: event.id))) channel.send(message: ack) end rec.on_error do |error| self.errors << ["I received an error fact: #{error.class}"] end end @errors = [] @facts = [] @is_open = true end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
9 10 11 |
# File 'lib/urbit/receiver.rb', line 9 def errors @errors end |
#facts ⇒ Object
Returns the value of attribute facts.
9 10 11 |
# File 'lib/urbit/receiver.rb', line 9 def facts @facts end |
Instance Method Details
#default_logger ⇒ Object
34 35 36 37 38 39 |
# File 'lib/urbit/receiver.rb', line 34 def default_logger log = ::Logger.new($stdout) log.level = ::Logger::WARN log.progname = 'ld-eventsource' log end |
#open? ⇒ Boolean
41 42 43 |
# File 'lib/urbit/receiver.rb', line 41 def open? @is_open end |