flood-protection

1.0.1 • Public • Published

flood-protection

Flood protection for realtime applications

NPM version Build Status Coverage Status npm

Install

npm install --save flood-protection

Usage

import FloodProtection from 'flood-protection';
 
const floodProtection = new FloodProtection({
    rate: 5, 
    // default: 5, unit: messages
    // IMPORTANT: rate must be >= 1 (greater than or equal to 1)
    
    per: 8, 
    // default: 8, unit: seconds
  });

Basic Example

import FloodProtection from 'flood-protection';
 
// ...
// io is a Socket.io instance...
 
io.on('connection', (client) => {
  client.emit('connected');
 
  const floodProtection = new FloodProtection();
 
  client.on('message', (text) => {
    if (floodProtection.check()) {
      // forward message
      io.emit('message', text);     
    } else {
      // forbid message
      client.emit('flood', {
        text: 'Take it easy!',
      });
    }
  });
});

LICENCE

MIT (c) 2017 Mehmet Yatkı

Package Sidebar

Install

npm i flood-protection

Weekly Downloads

12

Version

1.0.1

License

MIT

Last publish

Collaborators

  • yatki