francois2metz / em-eventsource Goto Github PK
View Code? Open in Web Editor NEWem-eventsource is an eventmachine library to consume Server-Sent Events streaming API.
License: MIT License
em-eventsource is an eventmachine library to consume Server-Sent Events streaming API.
License: MIT License
I'm convinced this gem is utterly broken:
EM.run do
source = EventMachine::EventSource.new "http://nas:2347/sse", {}, {'Accept' => 'text/event-stream'}
source.inactivity_timeout = 0
source.message do |message|
puts message
end
source.on "notification" do |message|
puts "notification #{message}"
end
source.error do |error|
puts "error #{error}"
end
source.open do
puts "opened"
end
source.start # Start listening
end
opened
error Connection lost. Reconnecting.
opened
error Connection lost. Reconnecting.
opened
error Connection lost. Reconnecting.
...
Sinatra server output:
I, [2018-05-15T09:24:00.199421 #12430] INFO -- : 10.0.0.2 - - "SSE /sse HTTP/1.1" 200 -
W, [2018-05-15T09:24:00.200600 #12430] WARN -- : closed stream
I, [2018-05-15T09:24:03.205054 #12430] INFO -- : 10.0.0.2 - - "SSE /sse HTTP/1.1" 200 -
W, [2018-05-15T09:24:03.210790 #12430] WARN -- : closed stream
I, [2018-05-15T09:24:06.211593 #12430] INFO -- : 10.0.0.2 - - "SSE /sse HTTP/1.1" 200 -
W, [2018-05-15T09:24:06.212589 #12430] WARN -- : closed stream
I've spent two hours trying to debug this, and I'm none the wiser.
While using this gem with Bundler 1.1.rc7 I've run into this issue while trying to update some unrelated gem:
$ bundle update somegem
Fetching gem metadata from http://rubygems.org/.
Unfortunately, the gem em-eventsource (0.1.1) has an invalid gemspec. As a result, Bundler cannot install this Gemfile. Please ask the gem author to yank the bad version to fix this issue. For more information, see http://bit.ly/syck-defaultkey.
Could you please yank 0.1.1 gem version or provide some other workaround except using Bundler 1.0?
The em-http-request
gem recently published a new version (1.1.6) which highlights a CVE around a Man in the Middle attack: igrigorik/em-http-request#339. Is it possible to have the gem use TLS by default?
I am getting this warning when using this gem in various projects:
[WARNING; em-http-request] TLS hostname validation is disabled (use 'tls: {verify_peer: true}'), see CVE-2020-13482 and https://github.com/igrigorik/em-http-request/issues/339 for details
I'm not very familiar with SSE and where to look for the reasons behind disconnections. I'm trying to connect to https://horizon.stellar.org/operations:
Modifying examples/simple.rb
:
require 'em-eventsource'
EM.run do
source = EM::EventSource.new("https://horizon.stellar.org/operations")
source.retry = 3
source.message do |message|
puts "new message #{message}"
# puts "New Message"
end
source.error do |error|
puts "error #{error}"
end
source.start
end
It disconnects immediately, and then retries 1 second later (the server has a retry header of 1000).
Mind pointing me to the right direction to figure out why it's getting disconnected?
I noticed that I'd disconnected and a retry wouldn't happen. I checked the headers and the retry of the server is set to 1000. This gem reads that as 1000 seconds. Reading https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-reconnection-time, I think this gem should divide the time by 1000.
Is my understanding correct?
I'm trying to stream events from Nest as shown here: https://developers.nest.com/documentation/cloud/rest-streaming-guide
In general im doing:
source = EventMachine::EventSource.new(event_url, query = {}, headers=
{'Authorization' => "Bearer #{@token}",
'Accept' => 'text/event-stream',
'Cache-Control' => 'no-cache' })
where event url is "https://developer-api.nest.com/". I get a 401 Unauthorized Error and is addressed by Nest at: https://developers.nest.com/documentation/cloud/how-to-handle-redirects which suggests that eventsource is not handling redirects properly. This is confirmed when I swap the event_url with the final redirect address and the stream works fine. Any way to add the ability to handle redirects to the library? Thanks alot!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.