Skip to content

Simple hexnut middleware for dealing with connections and messages

License

Notifications You must be signed in to change notification settings

francisrstokes/hexnut-handle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hexnut-handle

hexnut-handle is a hexnut middleware for creating simple message and connection handlers. It can also be used with hexnut-client.

Installing

npm i hexnut-handle

Usage

Handling a connection

handle.connect(middlewareFunction)

const handle = require('hexnut-handle');

app.use(handle.connect(ctx => {
  ctx.send('Welcome!');
}));

Handling a message

handle.message(middlewareFunction)

const handle = require('hexnut-handle');

app.use(handle.message(ctx => {
  ctx.send(`You sent: ${ctx.message}`);
}));

Handling a message with a specific format

handle.matchMessage(messageRecogniserFunction, middlewareFunction)

const handle = require('hexnut-handle');

const messageRecogniser = msg => msg === 'Hello world';

app.use(handle.matchMessage(messageRecogniser, ctx => {
  ctx.send('Hello to you too!');
}));

Handling a connection closing

handle.closing(middlewareFunction)

const handle = require('hexnut-handle');

app.use(handle.closing(ctx => {
  // Do some cleanup here if necessary.
}));

About

Simple hexnut middleware for dealing with connections and messages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published