Comments (6)
I wouldn't trust any server side hacks to make this work. There is a bug in the code that needs to be fixed, period.
from eventsource.
I can't speak for why the other polyfills work, but it's recommended that you send back a 2056 character comment at the start of the stream in the case of internet explorer. Try this at the start of each connect:
resp.write(new Array(2057).join(':') + '\n\n')
from eventsource.
@rexxars that's certainly a workaround, but it doesn't explain why the other polyfills work without this server hack.
When Webpack (or Browserify) builds the polyfill, it replaces all of the node http
code with https://github.com/jhiesey/stream-http. That library uses XMLHttpRequest
just like the other polyfills, so there must be a difference in how they're using it.
from eventsource.
I've applied the workaround that @rexxars suggested, and strangely enough, IE receives the messages more frequently but they are delayed still, now the messages are received in a period where 2 or 3 messages are sent.
This is what I do now in the server:
var d = new Date();
resp.write(new Array(2057).join(':') + '\n'); // padding for IE
resp.write('id: ' + d.getMilliseconds() + '\n');
resp.write('event:' + 'message' + '\n');
resp.write('data:' + createMsg(d) + '\n\n'); // Note the extra newline
I also tried to do it only in every new connection:
resp.writeHead(200, {
... // the headers
});
resp.write(new Array(2057).join(':') + '\n'); // padding for IE
but the last one did not work, still the delay of about 2 mins
from eventsource.
Any news on a fix?
from eventsource.
The "server side hack" is also present on other polyfills. I wonder if the issue is the id: d.getMilliseconds()
that would return the same id since it only gives the the current number of milliseconds (from 0 to 999) for the current second. So, it'd be much better to use a increasing unique identifier.
Both IE and Edge buffers the data from the network layer, and that's why you need the padding hack, so the JS callback are called when the buffer is full. If the id fix above doesn't work, I wonder if you should make your event larger so the buffer hits the JS's callback. Typically, it's likely the AJAX connection underneath (in the polyfill implementation) times out, and tries to reconnect. In that case, you'd need to pad the connection again.
That's a real PITA, but since it's bug in the browser, there nothing you can do against.
Please notice that IE/Edge's polyfill emulate a streaming connection with a non-streaming based technology. So it reconnects much more frequently (you can increase the timeout on the browser's library).
from eventsource.
Related Issues (20)
- Who to contact for security issues HOT 9
- util.inherits is not a function HOT 5
- Initial connection timeout
- Error: "URL is not a constructor" HOT 2
- throwing all properties from url.parse into the request options is problematic
- connection failed silently after idle for ~10 mins
- Relative redirects do not work HOT 2
- Event() api HOT 1
- Guidance to add eventsource to vite bundler HOT 1
- [Bug] `dispatchEvent` wrong implementation
- No connection open in Electron HOT 1
- Header Last-Event-ID is not automatically sent on reconnect HOT 3
- Question about eventSourceInitDict HOT 1
- Does your eventsource library override the native node version? HOT 1
- want feature http post request HOT 10
- HTTPS traffic over a proxy is sent unencrypted
- bug: eventsource fails to reject self-signed certs if non-empty options are provided
- Property 'EventSourcePolyfill' does not exist on type 'Window & typeof globalThis'.
- why the EventSourcePolyfill could not get the sse data HOT 1
- Events dropped in streams with mixed CRLF and LF line terminators. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventsource.