socketio-server
A tool to easily create and use SocketIO-Rooms inside nodejs-express-routes.
Please Note
This package was built upon the great socket.io. Know the api especially the socket section to get the best out of it.
Installation
use your http server as parameter
var http = ;http debug: true;
or your server instance of express
var http = ;var server = http;server debug: true;
Usage
In the client of your application, the first step is to emit an event named register with an identifier that you keep track. In the example bellow I've used my username as the identifier:
// this can be found laying in some Angular directive frontend application // an socket for the room 'chat'let socket = io;socket;
And inside the Node server, the socket of the registered identifier can be retrieved at any time using the
var express = ;var router = express;var socket = ;var chatRoom = ; router; moduleexports = router;
Reference
params[, options])
require('socketio-server')(return function(id, callback)
The main entry point of this module.
Constructor argument: params
type string or object
If you need to initialize the module, you should supply the server as argument:
var http = ;var server = http;server debug: true;
If you are in the use stage, the params argument could serve as Room identifier:
var socket = ;var chatRoom = ; //creates (if not created) and exposes a room named 'chat'var mainRoom = ; //creates (if not created) and exposes the default '/' room
Constructor argument: options
type object
key | description | type | default |
---|---|---|---|
debug | Enable verbosity for debuggin (very handy) | boolean | false |
require('socketio-server')('room name')(id, callback)
This function is the goal of the module. Within this function, you can specifically get the socket of the desired ID defined in your client-side.
id
type string
The identifier of the socket that you want to retrieve.
callback
type function(err, socket)
This callback function exposes a socket object relative to the identifier above.
Dependencies
socket.io
Contact-me
License
MIT