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

extended-eventsource

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extended-eventsource

Spec compliant EventSource implementation for browsers and Node.JS

  • 1.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.3K
increased by29.35%
Maintainers
0
Weekly downloads
 
Created
Source

EventSource

https://www.npmjs.com/package/extended-eventsource https://www.npmjs.com/package/extended-eventsource NPM

This is a custom EventSource implementation that is fully compliant with the WHATWG Server-Sent Events specification but takes more arguments like request headers.

It can be used in both web and Node.js environments.

The motivation for this library is that the native browser EventSource does not offer options for changing the request that is sent to the server. This means that e.g. you can not send an authorization header. This is fixed by this library.

Features

  • Supports both web and Node.js environments
  • Follows the WHATWG Server-Sent Events specification and can be uses everywhere where the native EventSource would be used.

Installation

Install the package using npm:

npm i extended-eventsource

Usage

The package exposes a single class called EventSource. To use it, create a new instance of EventSource with the URL of the server-sent events endpoint, and an optional configuration object.

Web

import { EventSource } from 'extended-eventsource';

const eventSource = new EventSource('/events', {
  headers: {
    Authorization: 'Bearer token',
  },
  retry: 3000,
});

eventSource.onopen = () => {
  console.log('Connection opened');
};

eventSource.onmessage = (event: MessageEvent) => {
  console.log('Message received:', event.data);
};

eventSource.onerror = (error) => {
  console.error('Error occurred:', error);
};


Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 03 Oct 2024

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