A multi-user chat server, client module, and sample client CLI.
npm i chat-server
chat-server [OPTIONS]
Options:
-h ip ip to bind to default: 127.0.0.1
-p port port to bind to default: 11746
-m bytes max input size per client default: 1MB
-l level log level default: error
client-al.js
var client = require('chat-server').connect();
client.nick('Al');
client.join('jokes');
client.say('jokes', 'what did the hat say to the hat rack?');
client-bob.js
var client = require('chat-server').connect();
client.nick('Bob');
client.join('jokes');
client.on('say', function (channel, who, message) {
console.log(new Date(), channel, who, message);
});
Connect to a running chat server on host:port.
Set the client's nickname. Must be the first call made.
Join a channel.
Leave/part a channel.
List all active channels.
List all members of a channel. 'callback' is passed an array of nicknames.
Say something in a channel. Must already have joined the channel.
Client I/O error talking to server (e.g. ECONNREFUSED).
Something you tried to do did not go so well (e.g. nickname already in use).
Shouldn't happen. The server sent a malformed protocol message.
Someone joined a channel we joined.
Someone parted a channel we joined.
Someone said something in a channel we joined.
Someone changed their nickname in a channel we joined.
The client/server protocol is based on CRLF-delimited JSON objects.
{ "nick": "unique-nickname" }
{ "list": "channel-prefix" }
{ "join": "channel-name" }
{ "members": "channel-name" }
{ "say": "channel-name", "what": "message" }
{ "part": "channel-name", "why": "reason" }
{ "info": true }
A subset of client requests elicit a response.
{ "error": "error-message" }
{ "list": ["channel-name", ...] }
{ "members": "channel-name", "nicks": ["nick", ...] }
{ "info": { "channels": int, "users": int, "uptime": int } }
Something happened server-side that the client might be interested in.
{ "join": "channel-name", "who": "nick" }
{ "part": "channel-name", "who": "nick", "why": "reason" }
{ "say": "channel-name", "who": "nick", "what": "message" }
{ "nick": "channel-name", "old_nick": "nick", "new_nick": "new-nick" }
Any client wrongdoing results in an immediate disconnection.
This server does not connect to other servers like a IRC network.
Brian Hammond brian@fictorial.com (http://fictorial.com)
Copyright (c) 2011 Fictorial LLC.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.