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

@feathersjs/socket-commons

v3.1.5

Published

Shared functionality for websocket providers

Downloads

8,532

Readme

@feathersjs/socket-commons

Greenkeeper badge

Build Status Test Coverage Dependency Status Download Status

Shared functionality for websocket providers like @feathers/socketio and @feathersjs/primus. Only intended to be used internally by other Feathers real-time providers.

About

@feathersjs/socket-commons contains internal shared functionality for Feathers real-time providers (currently Socket.io and Primus).

lib/client.js is a base socket service client lib/index.js returns a configurable function and requires the following options:

  • done - A Promise that resolves once the real-time protocol server has been set up
  • emit - The name of the method to emit data to a socket ('emit' for Socket.io and 'send' for Primus)
  • socketKey - A string or ES6 Symbol which stores the actual socket connection
  • getParams - A function that returns the Feathers connection options for a socket

Channels

Channels provide channel functionality for bi-directional Feathers service providers. It is e.g. used by the Socket.io and Primus provider to quickly determine what messages to send to connected clients.

const channels = require('@feathersjs/socket-commons/lib/channels');

Documentation

app.channel(... names)

Returns a named or combined channel object.

const channel = app.channel('test'); // return a `test` channel

channel.join(connection); // join a channel
channel.leave(connection); // leave a channel

channel.filter(connection => {}) // return a new channel with filtered connections
channel.length // return the number of connections
channel.connections // all connections in this channel

const combined = app.channel('test', 'other'); // return a combined channel

combined.join(connection); // join the `test` and `other` channel
combined.leave(connection); // leave the `test` and `other` channel

channel.filter(connection => {}) // return a new channel with filtered connections (connections will only be iterated once)
combined.length // return the number of connections
combined.connections // all connections in the combined channel (if a connection is in multiple channels it will only show once)

app.service('servicename').publish(event, callback), app.service('servicename').publish(callback)

Register a publishing callback for a service and event (or all events) that returns a (named or combined) channel.

app.use('/test', {
  create(data) {
    return Promise.resolve(data);
  }
});

// `created` event for the `test` service
app.service('test').publish('created', (data, hook) =>
  app.channel('*')
);

// `created` event for the `test` service, sending different data to two different channels
app.service('test').publish('created', (data, hook) => {
  return [
    app.channel('admins'),
    app.channel('users').send(_.omit(data, 'groups', 'email'))
  ];
});

// All events for all services
app.publish((data, hook) =>
  app.channel('*')
);

// All `created` events for all services
app.publish('created', (data, hook) =>
  app.channel('*')
);

// All events for `test` service
app.service('test').publish((data, hook) =>
  app.channel('*')
);

app.on('publish', function(event, channel, hook) {})

An event that will be sent every time a service event that has connections to publish to happens. channel is a combined channel with all connections to publish the event to.

Note: If there are no channels or connections the publish event will not be sent.

app.on('publish', (event, channel, hook) => {
  channel.connections.forEach(connection => {
    // Do something with `connection`
  });
});

License

Copyright (c) 2015

Licensed under the MIT license.