Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eventsource-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventsource-polyfill

A browser polyfill for W3C EventSource (http://www.w3.org/TR/eventsource/)

  • 0.9.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
254K
decreased by-9.05%
Maintainers
1
Weekly downloads
 
Created

What is eventsource-polyfill?

The eventsource-polyfill npm package provides a polyfill for the EventSource API, which is used for receiving server-sent events (SSE). This is particularly useful for environments that do not natively support EventSource, such as older browsers.

What are eventsource-polyfill's main functionalities?

Basic EventSource Connection

This feature allows you to establish a basic connection to a server that sends events. The code sample demonstrates how to create an EventSource instance and handle incoming messages.

const EventSource = require('eventsource-polyfill');
const es = new EventSource('http://example.com/events');
es.onmessage = function(event) {
  console.log('New message:', event.data);
};

Handling Different Event Types

This feature allows you to listen for specific types of events sent by the server. The code sample shows how to add an event listener for a custom event type.

const EventSource = require('eventsource-polyfill');
const es = new EventSource('http://example.com/events');
es.addEventListener('customEvent', function(event) {
  console.log('Custom event received:', event.data);
});

Error Handling

This feature provides a way to handle errors that may occur during the connection. The code sample demonstrates how to set up an error handler.

const EventSource = require('eventsource-polyfill');
const es = new EventSource('http://example.com/events');
es.onerror = function(event) {
  console.error('Error occurred:', event);
};

Other packages similar to eventsource-polyfill

Keywords

FAQs

Package last updated on 28 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc