New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chat

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chat

Eventually consistent chat rooms via CRDT

  • 0.6.0
  • npm
  • Socket score

Version published
Weekly downloads
118
decreased by-38.22%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Transport Free

Obviously, this isn't the first chat implementation written in Node. It is, however, one of the first to be written that isn't tied to a specific transport implementation (usually WebSockets).

An example of a pure socket level chat server and client can be found in the examples directory.

FAQs

Package last updated on 28 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc