kneesock

1.0.2 • Public • Published

kneesock

by Jason Yung - http://callmejay.com

a simple pub sub wrapper for websockets/ws

Installing

$ npm install --save kneesock

Basic Usage

var KneeSock = require('kneesock')
var kneesock = new KneeSock({}, function onConnect(clientSpace) {

	kneesock.subscribe('chatroom', clientSpace);

	kneesock.publish('chatroom', "alert to all, a new client has subscribed" })

	clientSpace.client.on('message', function incoming(message) {
		console.log('received: %s', message);

		kneesock.publish('chatroom', message)

	});

});

Using With Express

var express = require('express')
	, app = express()
	, port = 4080

app.get('/', function (req, res) {
	res.render('chatroom');
}

var KneeSock = require('kneesock')
var kneesock = new KneeSock({app:app, port:port}, function onConnect(clientSpace) {
	...
});

kneesock.server.http.listen(port, function () { console.log('Listening on ' + port) });

Demos

To check out an example of a basic chatting service, run the command:

$ node demo/chatroom.js

This will run the demo locally at http://localhost:4080

Readme

Keywords

Package Sidebar

Install

npm i kneesock

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • json2d