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

loopback-component-changestreamer

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loopback-component-changestreamer

Stream model changes by SSE

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-25%
Maintainers
5
Weekly downloads
 
Created
Source

loopback-component-changestreamer

The component observes a number specified models and notifies about the changes by SSE.

The main difference with Loopback /change-stream channels is that this implementation creates only two observers (after save and after delete) per model and then streams the changes to keep-alive registered connections. In contrast Loopback creates two same observers for each connection.

Install and Setup

Install the company: npm install --save loopback-component-changestreamer

Important! Disable compression middleware in middleware.json files like this:

{
  ...
  "compression": {
    "enabled":false
	},
	...
}

Add the following configuration to component-config.json:

{
  ...
  "loopback-component-changestreamer": {
    "mountPath": "/api/updates",
    "reconnectTimeout": 3000,
    "responseTimeout": 120000,
    "models": [
      "Foo",
      "Bar",
      "Baz"
    ],
    "headers": [
      "x-auth-request-user"
    ]
  },
  ...
}

See e2e/ directory as an example for how to make project configuration.

The configuration parameters:

  • mountPath - base URL to subscribe for updates;
  • reconnectTimeout - instruct Browser to reconnect after this timeout if connection is lost;
  • responseTimeout - the response socket will be closed after this timeout;
  • models - array of model names to observe.
    • headers - headers and values to embed in the stream metadata.

The component configuration above adds 3 middleware rules:

  • GET "/api/updates" to connect some SourceEvent listener;
  • GET "/api/updates/stat" to see a statistics about number of current connections;
  • DELETE "/api/updates" to close all registered connections.

The following snippet can be used on client side to connect:

var src = new EventSource('//<host>:<port>/api/updates');
src.addEventListener('message', function(message) {
  ...
});

Keywords

FAQs

Package last updated on 31 Jan 2018

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