Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
clickermonkey-pubsubjs
Advanced tools
A lightweight publish/subscribe server & client written in javascript.
The publish/subscribe model is perfect for making your web application appear real-time. Imagine several people all looking at the same page, when someone makes a change to the page it's instantly reflected to all other viewers of that page. This is pubsub.js
!
A Channel
is a group of subscribers all listening for publish, join, & leave events. Channels are created when needed and are destroyed when there are no subscribers.
A Client
is a connection to the server from a web application that can be subscribed to any number of Channels.
pubsub.js
is built with safety in mind. All data sent to the server is validated before it creates channels, subscribes clients, or publishes to a channel.
The easiest way to install pubsub.js is through bower via bower install clickermonkey-pubsubjs
npm install
node pubsub-server.js
var pubsub = new PubSub('http://localhost:3000');
var channel = pubsub.subscribe('channel ID', 'user token');
channel.onpublish = function(data) {
console.log('data received:', data);
};
channel.onjoin = function(userToken) {
console.log('user join:', userToken);
};
channel.onleave = function(userToken) {
console.log('user leave:', userToken);
};
channel.publish('Hello World!');
channel.unsubscribe();
(see examples/chat.html for a chat demo)
{
/**
* The port the application listens on.
*/
port: 3000,
/**
* Whether or not to send a publish message back to the client who sent it.
*/
echoPublish: false,
/**
* If this server should notify clients when other clients have joined or left
* a channel. The client's token it used to subscribe is sent along with these
* notifications so the client can identify them. If this is set to false
* then tokens are ignored altogether in the system.
*/
sendJoinLeaveEvents: true,
/**
* The maximum number of channels that can be created.
*/
maxChannels: -1,
/**
* The maximum number of clients that may connect.
*/
maxClients: -1,
/**
* If a client has sent an invalid channel ID, join token, or publish data
* this determines whether the client is marked untrused and is no longer
* sent any messages.
*/
ignoreInvalidClients: true,
/**
* The number of previous publishes to keep and send to a client when they join.
*/
sendLastPublishesOnJoin: 10,
/**
* Whether or not to send all of the join tokens of current clients to the
* new client when they first join the channel.
*/
sendExistingClientsOnJoin: true,
/**
* Requires that a client must be subscribed to a channel before they can publish in it.
*/
requireSubscription: true,
/**
* Logs events (comment out console.log to disable)
*/
debug: function()
{
console.log.apply( console, arguments );
},
/****************************************************************************
* C H A N N E L I D V A L I D A T I O N
****************************************************************************/
/**
* The data types that are valid channel IDs.
* If the id is found not to be valid, a channel will not be created.
*/
validIds:
{
'number': true,
'string': true,
'boolean': true,
'object': false,
'undefined': false
},
/**
* A function which does further validation on a channel ID.
* If the id is found not to be valid, a channel will not be created.
*/
validateId: function(id)
{
var promise = new Promise( this );
if ( this.validIds[ typeof id ] )
{
promise.$success();
}
else
{
promise.$failure();
}
return promise;
},
/****************************************************************************
* C L I E N T T O K E N V A L I D A T I O N
****************************************************************************/
/**
* The data types that are valid client tokens.
* If a token is found to be not valid, the user does not join the channel.
*/
validTokens:
{
'number': true,
'string': true,
'boolean': true,
'undefined': true,
'object': false
},
/**
* A function which does further validation on a client token.
* If a token is found to be not valid, the user does not join the channel.
*/
validateToken: function(token)
{
var promise = new Promise( this );
if ( this.validTokens[ typeof token ] )
{
promise.$success();
}
else
{
promise.$failure();
}
return promise;
},
/****************************************************************************
* P U B L I S H V A L I D A T I O N
****************************************************************************/
/**
* The data types that are valid to publish to other clients.
*/
validPublish:
{
'number': true,
'string': true,
'boolean': true,
'undefined': true,
'object': true
},
/**
* A function which validates if a message by a client can be published on a channel.
*/
validatePublish: function(message, client, channel)
{
var promise = new Promise( this );
if ( this.validPublish[ typeof message ] )
{
promise.$success();
}
else
{
promise.$failure();
}
return promise;
}
}
FAQs
pubsub with Socket.io
We found that clickermonkey-pubsubjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.