Gathering detailed insights and metrics for tt-event-source-polyfill
Gathering detailed insights and metrics for tt-event-source-polyfill
Gathering detailed insights and metrics for tt-event-source-polyfill
Gathering detailed insights and metrics for tt-event-source-polyfill
EventSource client for Node.js and Browser (polyfill)
npm install tt-event-source-polyfill
Typescript
Module System
Node Version
NPM Version
JavaScript (99.78%)
HTML (0.22%)
Total Downloads
1,761
Last Day
3
Last Week
3
Last Month
16
Last Year
106
MIT License
3 Stars
207 Commits
9 Watchers
2 Branches
77 Contributors
Updated on May 28, 2025
Minified
Minified + Gzipped
Latest Version
0.0.12-tt2
Package Id
tt-event-source-polyfill@0.0.12-tt2
Unpacked Size
169.52 kB
Size
48.69 kB
File Count
24
NPM Version
6.4.1
Node Version
8.11.1
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
-57.1%
3
Compared to previous week
Last Month
60%
16
Compared to previous month
Last Year
-38.7%
106
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.
Original project: https://github.com/Yaffle/EventSource
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;
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'
}
});
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>
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 vulnerabilities detected
Reason
tokens are read-only in GitHub workflows
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
all dependencies are pinned
Details
Reason
no binaries found in the repo
Reason
0 commit(s) out of 30 and 0 issue activity out of 0 found in the last 90 days -- score normalized to 0
Reason
GitHub code reviews found for 1 commits out of the last 30 -- score normalized to 0
Details
Reason
no badge detected
Reason
security policy file not detected
Reason
no update tool detected
Details
Reason
project is not fuzzed
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2022-08-15
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