Code Monkey home page Code Monkey logo

node-chat's Introduction

NodeChat

NodeChat is a simple, scalable web-based chat server built on Node.js.

Server

Creating a chat server is super simple.

// create a server at http://localhost:8001
var chat = require("lib/server");
var chatServer = chat.createServer();
chatServer.listen(8001);

Once you've created a server, you can add channels.

// create a channel at http://localhost:8001/chat
var channel = chatServer.addChannel({ basePath: "/chat" });

Channels have three options:

  • basePath (required) - the URL to use for the channel
  • messageBacklog (default 200) - how many message to keep in memory
  • sessionTimeout (default 60) - how many seconds to wait before killing inactive sessions

Client

NodeChat comes with a client library built on jQuery to make it easy to connect to a NodeChat server.

// connect to a channel
var channel = nodeChat.connect("http://localhost:8001/chat");

// join the channel
channel.join("my-nick");

// send a message to the channel
channel.send("hello");

// leave the channel
channel.part();

Events

The server and client both emit events on the channel objects.

  • join - emitted when someone joins the channel.
  • msg - emitted when someone sends a message to the channel.
  • part - emitted when someone leaves the channel.

Each event receives an object with the following properties:

  • id - unique id for the event (unique per channel).
  • nick - the nick of the user who performed the action.
  • type - the type of action (will be same as the event type).
  • text - text associated with the action.
  • timestamp - when the action occurred.

In addition, the client emits a connectionerror event if the connection to the server is lost.

Installation & Demo

To install:

git clone http://github.com/scottgonzalez/node-chat.git

To run the demo:

./node-chat/demo/chat.js

Then open http://localhost:8001 in a browser.

License

Copyright 2013 Scott González. Released under the terms of the MIT license.

node-chat's People

Contributors

scottgonzalez avatar dcneiner avatar seutje avatar weepy avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.