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

inra-server-socket

v1.4.0

Published

[![npm](https://img.shields.io/npm/v/inra-server-socket.svg?maxAge=2592000)](https://www.npmjs.com/package/inra-server-socket) [![Dependency Status](https://david-dm.org/project-inra/inra-server.svg?path=packages/inra-server-socket)](https://david-dm.org/

Downloads

6

Readme

inra-server-socket

npm Dependency Status

The purpose of this component is to intercept the manipulation of most of the socket work by creating special wrappers. These wrappers allow the developer to integrate his client with inra-server rapidly, manipulate data, connections and/or namespaces.

Note: full documentation with more examples is published on our Wiki. Please, refer to our Wiki for installation details and API references.

Installation

$ npm install --save inra-server-socket

API

const socket = new Socket(config);

Socket Server

.send(id, event [, data = {}])

Emits an event with data for a specific connection. This is usefll in event listeners on server-side, when you intercept specific events and want to send back a response for the given source.

Example:

socket.on("eventA", (data, connection, namespace) => {
  socket.send(connection.id, "eventB", ...data);
});

.emit(event [, data = {}])

Emits an event with data for every connection in every namespace registered.

Example:

socket.emit("event", ...data);

.broadcast(event [, data = {}])

Emits an event with data for every connection in every namespace registered. Broadcast behaviour is the same as for .emit (in Socket only - it changes for SocketNamespace and SocketConnection).

Example:

socket.broadcast("event", ...data);

.on(event, callback)

Registers a callback for a specific event coming from all the registered namespaces. This means that event will be intercepted even if it was registered only for a specific SocketNamespace.

Note: You can still register events which will be intercepted only by specified namespaces.

socket.on("event", (data, connection, namespace) => {
  // …
});

.create(id)

Creates a new room with id room. Automically resolves new connections and events. Returns the created room instance (SocketNamespace).

const indexNamespace = socket.create("/").listen();
const adminNamespace = socket.create("/admin").use(authMiddleware).listen();

.trigger(event, data, connection, namespace)

Triggers a specific event with data, connection and namespace.

socket.on("event", (data, connection, namespace) => {
  if (/* … */) {
    socket.trigger("another_event", data, connection, namespace);
  }
});

.io

socket.io instance.

.host

.port

.hostname

.config

.callbacks

.connections

Socket Connection

.on(event, callback)

Executes callback on event from the actual socket.

.emit(event [, data = {}])

Emits an event with data from the actual socket.

.broadcast(event [, data = {}])

Emits an event with data to everyone else in the namespace except for the actual socket.

.id

Unique id for actual connection. Same as in Socket.connections<id>. Can be used for Socket.send(id, event, data).

.instance

Instance from the initial socket from socket.io.

.namespace

Reference to the namespace the actual socket comes from.

.server

Reference to the server the actual socket comes from.

Socket Namespace

Returned by Socket.create.

const indexNamespace = socket.create("/").listen();
const adminNamespace = socket.create("/admin").use(authMiddleware).listen();

indexNamespace.on("event", (data, socket) => {
  // accessible for all users
});

adminNamespace.on("event", (data, socket) => {
  // accessible for authenticated users
});

.on(event, callback)

Registers a callback for event for the actual namespace. Events registered with this method are local. This means that those events will not be intercepted by Socket.on.

.broadcast(event [, data = {}])

Emits an event with data to everyone in the actual namespace.

.use(middleware)

Adds a custom middleware to the actual namespace.

.listen()

Registers customs event listeners for the actual namespace. Integrates the actual namespace with socket server. You probably want to always call this method once you've configured your namespace.

.id

Unique id (name) for the actual namespace.

.instance

Instance of the initial room from socket.io.

.server

Reference to the server the actual namespace comes from.

Contributing

Bug reporting

Github Open Issues Github Closed Issues Github Pull Requests

We want contributing to Inra Server to be fun, enjoyable, and educational for anyone, and everyone. Changes and improvements are more than welcome! Feel free to fork and open a pull request. If you have found any issues, please report them here - they are being tracked on GitHub Issues.

License

Inra Server is built and maintained by Bartosz Łaniewski. The full list of contributors can be found here. Inra's code is MIT licensed.

Development

We have prepared multiple commands to help you develop inra-server-socket on your own. Don't forget to install all Node.js dependencies from npm. You will need a local copy of Node.js installed on your machine.

$ sudo npm install

Usage

$ sudo npm run <command>

List of commands

| Command | Description | |---------------|---------------------------------------------------| | build | Builds inra-server-socket | | watch | Re-builds inra-server-socket on changes | | clean | Deletes builds ands cache | | lint | Fixes Lint errors | | flow | Checks Flow errors | | test | Checks Flow errors and runs tests |