1.0.5 • Published 4 years ago

magicws-api v1.0.5

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Magic WebSocket API

Library for creating WebSocket servers with JSON support

How to install

With NPM

npm i magicws-api --save

with yarn

yarn add magicws-api

Import

ES5

const WebSocketAPI = require('magicws-api').default;

ES6

import WebSocketAPI from 'magicws-api';

Example

Simple example with scheme validation

let server = new WebSocketAPI({ port: 1241 });
server.on('message', {
    required: [ 'text' ],
    schema: {
        text: 'string'
    }
}, context => {
    console.log(context.message.text);
    context.reply({ hello: 'world' });
});

With middleware and with out validation

server.on('message', {}, () => console.log('test middleware'), context => {
    console.log('todo');
});

License