Socket
Socket
Sign inDemoInstall

@codemonument/sse-codec

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @codemonument/sse-codec

A module which provides encoding & decoding functionality for SSE Events (Server Sent Events), as well as some types. Cross-Compiled by deno's dnt module. Also available at https://deno.land/x/sse_codec .


Version published
Weekly downloads
14
decreased by-61.11%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

SSE Codec

A module which provides encoding & decoding functionality for SSE Events (Server Sent Events), as well as providing some types.

Deployed to https://deno.land/x/sse_codec

Cross-Copiled by deno's dnt module and posted to npm as @codemonument/sse-codec

Imports in Deno

// uses 'latest' version 
import { encodeSSEEvent } from "https://deno.land/x/sse_codec"

// uses a specific version
import { encodeSSEEvent } from "https://deno.land/x/sse_codec@0.2.1";

Imports in Node

// install first via npm i -S @codemonument/sse-codec
import { encodeSSEEvent } from "@codemonument/sse-codec" 

Usage (same in Deno & Node)

See the test files for most elaborate usage descriptions. He'res the most important usage information.

Usage encodeSSEEvent

const sseString = encodeSSEEvent({
        name: "custom-event",
        data: "Some simple string data",
        id: "UID5346324874238475",
        retry: 5000,
      });

Usage SSEStream class

  const sseStream = new SSEStream();

  sseStream.emit({ eventName: "event1" });
  sseStream.emit({ eventName: "event2" });

  // Example usage of the sseStream 
  // normally you would not read it yourself 
  // but pass the readable stream to something which uses it for something
  const reader = sseStream.readableStream.getReader();
  const chunk1 = await reader.read();
  const chunk2 = await reader.read();

  console.log(chunk1);
  console.log(chunk2);
  
  // close the sseStream after using it
  sseStream.end();

FAQs

Last updated on 25 May 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc