An npm module for creating chat servers and clients.
Check out the examples directory for CLI server and client apps.
NOTE: This has been removed from npm so another developer could use the name. Download and install manually as needed.
var chatter = require('chatter');
var options = {
port: process.env.PORT || 8000
}
var chatter_server = new chatter.server(options);
var chatter = require('chatter');
var chatter_client = new chatter.client("http://chatterjs.herokuapp.com");
// get last 10 messages in transcript
chatter_client.getRecentHistory();
// start listening for new messages
chatter_client.on('message', function(message) {
console.log(message);
});
// send new message with body and user
chatter_client.send('Hello World', 'Jim');
requires "JQuery-like" library for ajax calls. Primary testing done using zepto.js
<script src="http://chatterjs.herokuapp.com/chatter/chatter.js"></script>
// first argument is host server, second is callback for new messages
// last argument is optional for polling interval
chatter.connect('http://chatterjs.herokuapp.com', function(data) {
console.log("handling new message: ", data);
}, 500);
// method to get last 10 messages in room
chatter.getRecentHistory();
// has optional callback to get created message returned
chatter.send("Hello World!", "Client", function(response) {
console.log("new message", response);
});