Package Exports
- chat
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chat) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Chat
Pure Streaming Chat for Node. This is a simple library which implements the core concepts of chat (rooms and connections) without getting tying chat to any particular transport.
Getting Started
The first thing you are going to want to do is create a room:
var chat = require('chat'),
room = chat.room();Once you have a room, you can then start connecting clients to the room:
var client = chat.client(room);At this point, we should probably start listening for messages in the room:
room.on('message', function(msg) {
if (msg.data) {
console.log(msg.data);
}
});The code above looks specifically for just the data messages that are captured by the room. In addition to the data messages, control messages are also sent which can be captured by examining the type property of the message.
At this point, it's probably worth attempting to communicate with the room. This is done using the write method of the client:
client.write('hello');Strange, we didn't capture any output. This is because as far as the room is concerned, an unknown client is attempting to send messages and this isn't permitted. While the chat package doesn't perform any authentication it does assume that a package using chat (such as iceman) will. So at a base level, it requires identification:
client.identify({ nick: 'Bill' });Calling identify on the client stream kicks off a handshake process with the room, and thus we should wait for the client to become ready before writing any messages:
client.once('ready', function(metadata) {
client.write('hello');
});For the full example, see examples/hello.js.