1.0.2 • Published 7 years ago

kneesock v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago