Gathering detailed insights and metrics for event-source-polyfill
Gathering detailed insights and metrics for event-source-polyfill
Gathering detailed insights and metrics for event-source-polyfill
Gathering detailed insights and metrics for event-source-polyfill
@types/event-source-polyfill
TypeScript definitions for event-source-polyfill
event-source
EventSource polyfill
@unspezifisch/event-source-polyfill
Fork of yaffle eventsource polyfill without his last commit
tt-event-source-polyfill
A polyfill for http://www.w3.org/TR/eventsource/
a polyfill for http://www.w3.org/TR/eventsource/
npm install event-source-polyfill
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
100
Quality
78.5
Maintenance
100
Vulnerability
100
License
JavaScript (95%)
CSS (2.58%)
HTML (1.28%)
PHP (1.12%)
Batchfile (0.01%)
Total Downloads
169,734,915
Last Day
38,682
Last Week
669,614
Last Month
2,953,338
Last Year
32,651,345
MIT License
2,171 Stars
387 Commits
338 Forks
44 Watchers
1 Branches
33 Contributors
Updated on Jun 21, 2025
Minified
Minified + Gzipped
Latest Version
1.0.31
Package Id
event-source-polyfill@1.0.31
Unpacked Size
56.69 kB
Size
15.99 kB
File Count
6
NPM Version
8.1.2
Node Version
16.13.1
Cumulative downloads
Total Downloads
Last Day
2.2%
38,682
Compared to previous day
Last Week
-7.4%
669,614
Compared to previous week
Last Month
2%
2,953,338
Compared to previous month
Last Year
4.8%
32,651,345
Compared to previous year
3
Пожалуйста не используйте эту обосранную библиотеку!
You can get the code from npm or bower:
npm install event-source-polyfill
bower install event-source-polyfill
Just include src/eventsource.js
or src/eventsource.min.js
in your page to use the polyfill.
Unless a typescript definition file is created for this polyfill, this is how you would use it in an Ionic2 project. It should (in theory) be very similar in an Angular2 project.
npm install event-source-polyfill
Add to (or create) src/app/polyfills.ts (path is relative to where polyfills.ts is) :
import 'path/to/event-source-polyfill/src/eventsource.min.js'
Add anywhere you need access to EventSourcePolyfill class :
declare var EventSourcePolyfill: any;
1import { NativeEventSource, EventSourcePolyfill } from 'event-source-polyfill'; 2 3const EventSource = NativeEventSource || EventSourcePolyfill; 4// OR: may also need to set as global property 5global.EventSource = NativeEventSource || EventSourcePolyfill;
padding=true
query argument)npm install
) and then run the build (npm run build
). It should generate a new version of src/eventsource.min.js
.http://username:password@github.com
.var es = new EventSourcePolyfill('/events', {
headers: {
'X-Custom-Header': 'value'
}
});
lastEventId
var es = new EventSourcePolyfill(hubUrl, {
lastEventIdQueryParameterName: 'Last-Event-Id'
});
1var PORT = 8081; 2 3var http = require("http"); 4var fs = require("fs"); 5var url = require("url"); 6 7http.createServer(function (request, response) { 8 var parsedURL = url.parse(request.url, true); 9 var pathname = parsedURL.pathname; 10 if (pathname === "/events.php") { 11 12 response.writeHead(200, { 13 "Content-Type": "text/event-stream", 14 "Cache-Control": "no-store", 15 "Access-Control-Allow-Origin": "*" 16 }); 17 18 var padding = new Array(2049); 19 response.write(":" + padding.join(" ") + "\n"); // 2kB padding for IE 20 response.write("retry: 2000\n"); 21 22 var lastEventId = Number(request.headers["last-event-id"]) || Number(parsedURL.query.lastEventId) || 0; 23 24 var timeoutId = 0; 25 var i = lastEventId; 26 var c = i + 100; 27 var f = function () { 28 if (++i < c) { 29 response.write("id: " + i + "\n"); 30 response.write("data: " + i + "\n\n"); 31 timeoutId = setTimeout(f, 1000); 32 } else { 33 response.end(); 34 } 35 }; 36 37 f(); 38 39 response.on("close", function () { 40 clearTimeout(timeoutId); 41 }); 42 43 } else { 44 if (pathname === "/") { 45 pathname = "/index.html"; 46 } 47 if (pathname === "/index.html" || pathname === "../src/eventsource.js") { 48 response.writeHead(200, { 49 "Content-Type": pathname === "/index.html" ? "text/html" : "text/javascript" 50 }); 51 response.write(fs.readFileSync(__dirname + pathname)); 52 } 53 response.end(); 54 } 55}).listen(PORT);
1<?php 2 3 header("Content-Type: text/event-stream"); 4 header("Cache-Control: no-store"); 5 header("Access-Control-Allow-Origin: *"); 6 7 $lastEventId = floatval(isset($_SERVER["HTTP_LAST_EVENT_ID"]) ? $_SERVER["HTTP_LAST_EVENT_ID"] : 0); 8 if ($lastEventId == 0) { 9 $lastEventId = floatval(isset($_GET["lastEventId"]) ? $_GET["lastEventId"] : 0); 10 } 11 12 echo ":" . str_repeat(" ", 2048) . "\n"; // 2 kB padding for IE 13 echo "retry: 2000\n"; 14 15 // event-stream 16 $i = $lastEventId; 17 $c = $i + 100; 18 while (++$i < $c) { 19 echo "id: " . $i . "\n"; 20 echo "data: " . $i . ";\n\n"; 21 ob_flush(); 22 flush(); 23 sleep(1); 24 } 25 26?>
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="utf-8" /> 5 <title>EventSource example</title> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <script src="../src/eventsource.js"></script> 8 <script> 9 var es = new EventSource("events.php"); 10 var listener = function (event) { 11 var div = document.createElement("div"); 12 var type = event.type; 13 div.appendChild(document.createTextNode(type + ": " + (type === "message" ? event.data : es.url))); 14 document.body.appendChild(div); 15 }; 16 es.addEventListener("open", listener); 17 es.addEventListener("message", listener); 18 es.addEventListener("error", listener); 19 </script> 20</head> 21<body> 22</body> 23</html>
With some dynamic imports it may work in node.js:
Install the library and the dependency:
npm install @titelmedia/node-fetch
npm install event-source-polyfill
x.js:
1// The @titelmedia/node-fetch is used instead of node-fetch as it supports ReadableStream Web API 2import('@titelmedia/node-fetch').then(function (fetch) { 3 globalThis.fetch = fetch.default; 4 globalThis.Response = fetch.default.Response; 5 import('event-source-polyfill').then(function (x) { 6 var es = new x.default.EventSourcePolyfill('http://localhost:8004/events'); 7 es.onerror = es.onopen = es.onmessage = function (event) { 8 console.log(event.type + ': ' + event.data); 9 }; 10 }); 11});
node --experimental-modules ./x.js
The MIT License (MIT)
Copyright (c) 2012 vic99999@yandex.ru
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/22 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More