helper functions

Usage no npm install needed!

<script type="module">
  import socketIoUtils from '';

README adds functions to the main object in order to ease common operations. It was inspired by my annoyance during a hackathon when dealing with room specific operations.


$ npm install


Initialization can be flexibly incorporated into any project. It was designed to not interfere with any pre-existing usage of to allow painless incorporation at any stage of development.

To use with a preexisting usage, just pass in the io object to the initialization.

var io = require('')();

Alternatively, you can do it this way.

var io = require('')(require('')());

These options are useful if you want to control which version of you're using. However, you can also simply require and the latest version of will be utilized.

var io = require('')();

Function Usage

Incorporating adds functions to the io object by sticking them onto a utils property of it.

To call a function, the format is:



getRoomData(roomName:string, propName:string)
Returns the value of the @propName property in the @roomName room.

setRoomData(roomName:string, propName:string, propValue:value)
Sets the @propName property with @propValue in the @roomName room.

delRoomData(roomName:string, propName:string)
Deletes the @propName property from the @roomName room.

Returns all of the data in the @roomName room.

setAllRoomData(roomName:string, roomData:object)
Adds all of the data in the @roomData object to the @roomName room.

Removes all custom data from the @roomName room.

Returns an object containing all of the sockets in the @roomName room.

Returns an object containing all of the current rooms.

Loading Custom Functions

If you have your own functions you'd like to use, you can load them into and they'll also be attached to the utils property. This is done during initialization.

var io = require('')(null, customFunctions);

Acceptable inputs as custom functions are either an array of functions or an object with function properties.

Array Example

When using a function array, you have to be sure to define the functions with a name.

var customFunctions = [
    foo = function foo(){}
var io = require('')(null, customFunctions);

Object Example

Passing in an object is much cleaner and should be the preferred method.

var customFunctions = {
    foo: function(){}
var io = require('')(null, customFunctions);