• Stars
    star
    113
  • Rank 303,672 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple chat solution build on socket.io

chat.io

chat.io is a simple socket.io based chat solution.

Example:

See example/simple-chat/.

Installation

npm install chat.io

Features

Easy to use

Server:

    require('chat.io').createChat(io.sockets);

    var guestCounter = 0;
    io.set('authorization', function (handshake, accept) {
        return accept(null, handshake.nickname = 'Guest'+ ++guestCounter);
    });

Client:

    var socket = io.connect('http://localhost');

    socket.on('say', function (user, message) {
        messages.append(user+'> '+message);
    });

socket.io namespace compliant

Server:

    require('chat.io').createChat(io.of('/chat'));

    var guestCounter = 0;
    io.of('/chat').authorization(function (handshake, accept) {
        return accept(null, handshake.nickname = 'Guest'+ ++guestCounter);
    });

Client:

    var socket = io.connect('http://localhost/chat');

Channels

Client:

    // beeing notified
    socket.on('join', function (user) {
        message.append(user + ' joined your channel.');
    });

    // joining
    socket.emit('join', 'aChannel', function (err) {
        if (err) messages.append('Error joining aChannel: ' + err);
    });

Whisper

Client:

    // receiving
    socket.on('whisper', function (user, message) {
        messages.append('<i>from '+user+'> '+message+'</i>');
    });
    
    // sending
    socket.emit('whisper', 'aUser', 'Hello, aUser!', function (err) {
        if (err) messages.append('Error whipering aUser: '+err);
    });

Kicking

Server:

    chat.on('connection', function (nickname) {
        if ('badyGuy' === nickname)  {
            chat.kick(nickname);
        }
    });

Channel permission system

Server:

    // deactivate channel switching
    chat.set('channel join permission', false);

    // permission callback
    chat.set('channel join permission', function (user, channel, allow) {
        if ('operator' === user) {
            return allow(true);
        }
        if ('secret' === channel) {
            return allow(false);
        }
        return allow(true);
    });

Server messages

Client:

    socket.on('message', function (message) {
        messages.append(message);
    });

Server:

    // global messages
    chat.sendSystem('Server shutting down in 10 minutes.');

    // channel messages
    chat.sendChannel(aChannel, 'This channel is supervised. Please behave.');

    // user messages
    chat.sendUser(aUser, 'This is your first visit, please read the guidelines.');

Documentation

For now, please see the example and the source code for additional documentation.

Tests

make test

License

Copyright (c) 2012 Daniel Baulig [email protected]

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.

More Repositories

1

node-gettext

An adaption of Joshua I. Miller's Javascript Gettext library for node.js.
JavaScript
73
star
2

sioe-demo

socket.io and Express. Tying it all together. Demo Application
JavaScript
52
star
3

Genetic-Algorithms

A simple C# library for implementing Genetic Algorithms, some demonstration classes and an entire project based on Genetic Algorithms we developed for a university project. Feel free to fork and improve. We might reconsider our licensing model for further versions and switch to LGPL for our library base.
C#
35
star
4

esphome-web-app

A standalone app for flashing, provisioning and controlling of ESPHome devices
JavaScript
32
star
5

vestaboard

Vestaboard Home Assistant integration
Python
10
star
6

esphome-web-js

A Javascript implementation of the ESPHome web server API
JavaScript
8
star
7

first

A tiny flow-control library for node
JavaScript
6
star
8

brainfuck.js

A simple Brainfuck interpreter written in JavaScript
JavaScript
3
star
9

pga

php genetic algorithms - A php library to implement genetic algorithms
PHP
3
star
10

ga.js

A simple libraray for implementing Genetic Algorithms written in Javascript
JavaScript
2
star
11

docker-minecraft

Dockerfile for creating a Minecraft server Docker container.
Makefile
2
star
12

A3O

A web based implementation of the Axis & Allies rules using HTML5, PHP and JavaScript
PHP
1
star
13

git-praesentation

A short introductory presentation on Git (german)
1
star
14

screeps

My screeps code
JavaScript
1
star
15

docker-sqlite3

Recipe to create a minimal docker sqlite3 image
Makefile
1
star
16

A3OTest

PHPUnit Test Suite for A3O
PHP
1
star
17

neewer-controller

A stand-alone ESP32 firmware to control Neewer RGB660 lights via WIFI
Makefile
1
star
18

oneloc-filter

This small script is the result of a bet about if it is possible to write a program that removes blacklisted words from filenames in a single line of code.
Shell
1
star