Currently we use SockJS as a transport, but I would like to extend this project to allow any system to be plugged in.
Install the library through NPM, dyuh!
npm install chitchat
var http = require('http'),
sockjs = require('sockjs'),
chitchat = require('chitchat');
/* Instantiate your chitchat server */
var chat = chitchat.createServer();
/* Setup authorize function */
chat.handleAuthorize(function (data, good, bad) {
signobj.valid(data.access_token).then(function (data) {
good(data.username, {meta_data...});
}).fail(function (err) {
bad({invalid: true});
});
});
/* Handle message function */
chat.handleMessage(function (data, good, bad) {
});
/* Hook into your HTTP server */
var server = http.createServer();
chat.installHandlers(server, {prefix: '/chat'});
server.listen(9999, '0.0.0.0');
Create a new chat server.
Handle authorization
Data to validate from the front end.
We authorized the user, you must set an identifier for this user. You may also send some meta data to the front end for the user, perhaps a list of online users!
Could not authorize the user, you can pass meta data along to the front end to tell the user why.
Handle message sending
Send a custom message to a user.
Hook this into your front end chat UI!
States:
connected
disconnected
reconnecting
You may also get a boolean value of each of these states with the following methods.
Connected to the chat server
Disconnected from the chat server
Reconnecting to the chat server, with the reason why we disconnected.
Received a list of chat messages!