Does your artifact manager get in the way? Join us on Oct. 8 at 10am PT, to discuss how npm can help.Sign up »


1.4.0 • Public • Published


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.


$ npm install --save inra-server-socket


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.


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

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

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



.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).



.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) => {
  // …


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 instance.







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.


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


Instance from the initial socket from


Reference to the namespace the actual socket comes from.


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.


Adds a custom middleware to the actual namespace.


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.


Unique id (name) for the actual namespace.


Instance of the initial room from


Reference to the server the actual namespace comes from.


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.


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


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


$ 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




npm i inra-server-socket

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability