0.4.5 • Published 7 years ago

osnova-module-socket.io v0.4.5

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Osnova Socket.IO module

bI?

Basic Socket.IO wrapper exported as osnova module.

Install

npm i osnova-module-socket.io

Usage

import OSNOVA from 'osnova';
import socketIoModule from 'osnova-module-socket.io';

const osnova = OSNOVA({
  modules: [ socketIoModule(/* optional options object */) ],
  
  /* rest OSNOVA config */

});

Takes optional opts object as a parameter with properties:

  • http { object } extern http server, if undefined will be used osnova.http.
  • middlewares { array } - Socket.IO middlewares list.

Exports to osnova io object with interface:

  • native() { function } return inner Socket.IO object.
  • on(eventName, callback) { function } - add an event for connected sockets. Callback will be called with (socket, payload) parameters when socket triggers an event.

Passing Socket.IO middlewares

Middlewares should have signature osnova => middleware.

const myMiddleware = (osnova) => (socket, next) => {
 console.log(`Hey, i have access to OSNOVA version ${osnova.__version} here!`);
 next();
}

socketIoModule({
  middlewares: [myMiddleware]
});
0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago