npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pryv/socket.io

v2.3.8

Published

Extends `pryv` with Socket.IO transport

Downloads

8

Readme

Socket.IO add-on for pryv

Extends the Pryv JavaScript library with Socket.IO transport and notifications.

Usage

The add-on extends pryv.Connection instances with a socket property.

Importing

NPM

npm install --save pryv @pryv/socket.io, then in your code (the add-on must be loaded once only):

const pryv = require('pryv');
require('@pryv/socket.io')(pryv);

<script> tag

pryv-socket.io.js must be loaded after pryv.js:

<script src="https://api.pryv.com/lib-js/pryv.js"></script>
<script src="https://api.pryv.com/lib-js/pryv-socket.io.js"></script>

Other distributions available:

  • ES6 version: https://api.pryv.com/lib-js-socket.io/pryv-socket.io-es6.js
  • pryv library bundled with Socket.IO and Monitor add-ons: https://api.pryv.com/lib-js/pryv-socket.io-monitor.js.

Using connection.socket

Once the add-on is loaded, pryv.Connection instances expose the socket property.

  • connection.socket.open() (asynchronous) opens the Socket.IO connection. It throws errors on failure.
  • connection.socket.api() is identical to Connection.api() but using the Socket.IO transport (see the library README)
  • connection.socket.on({event-name}, callback) registers an event listener. Possible event names are:
    • eventsChanged: when one or multiples events are deleted, changed or added.
    • streamsChanged: when one or multiples streams are deleted, changed or added.
    • accessChanged: when an access is deleted or added.
    • error: on error. The callback will receive the error as first argument.

Examples

Node.js

const pryv = require('pryv');
require('@pryv/socket.io')(pryv);

const apiEndpoint = 'https://{token}@my-computer.backloop.dev:4443/{username}/';
(async () => {
  const conn = new pryv.Connection(apiEndpoint);
  try {
    await conn.socket.open();
    conn.socket.on('eventsChanged', async () => {
      const res = await conn.socket.api([{method: 'events.get', params: {limit: 2}}]);
    	console.log('Last 2 events: ', JSON.stringify(res, null, 2));
    });
  } catch (e) {
    console.log('An error occured: ', e.message);
  }
})();

Browser

<script src="https://api.pryv.com/lib-js/pryv.js"></script>
<script src="https://api.pryv.com/lib-js-socket.io/pryv-socket.io.js"></script>

<script>
const apiEndpoint = 'https://{token}@my-computer.backloop.dev:4443/{username}/';
(async function () { 
  try {
    await conn.socket.open();
    conn.socket.on('eventsChanged', async () => {
      const res = await conn.socket.api([{method: 'events.get', params: {limit: 2}}]);
    	console.log('Last 2 events: ', JSON.stringify(res, null, 2));
    });
  } catch (e) {
    console.log('An error occured: ', e.message);
  }
})();
</script>

Example web app

See here for a simple app that allows to log in a Pryv.io platform, register to monitor events changes and create notes. You can try it running there.

Contributing

See the Pryv JavaScript library README

License

BSD-3-Clause