UNPKG

2.96 kBMarkdownView Raw
1
2# Chat service
3
4[![Build Status](https://travis-ci.org/an-sh/chat-service.svg?branch=master)](https://travis-ci.org/an-sh/chat-service)
5[![Coverage Status](https://coveralls.io/repos/an-sh/chat-service/badge.svg?branch=master&service=github)](https://coveralls.io/github/an-sh/chat-service?branch=master)
6[![Dependency Status](https://david-dm.org/an-sh/chat-service.svg)](https://david-dm.org/an-sh/chat-service)
7
8Server side chat based on top of socket.io focused on scalability and
9extensibility.
10
11
12### Features
13
14- Simple network layer using socket.io and json based messages.
15- Room and user2user chatting with permissions management.
16- Allows a single user to have multiple connected sockets.
17- Runs as a stateless service with built-in Redis state storage.
18- Can be extened via command hooks.
19- Can use external state storage implementations.
20- Extensive unit test coverage (95%+).
21
22
23### Basic usage
24
25```javascript
26var chatServer = new ChatService({ port : port },
27 { auth : auth, onConnect : onConnect },
28 'redis');
29```
30Here we have created a new server instance. It is ruuning _`port`_
31according to options argument. The second argument represents hooks,
32that will run during server lifetime. _`auth`_ hook is simular to the
33one that is described in socket.io documentation, and _`onConnect`_
34hook will run when client is connected. These hook are intended for
35integration to existing user authentication systems. The last argument
36is a state storage.
37
38Connection from a client side is trivial:
39```javascript
40socket = ioClient.connect(url1, params);
41socket.on('loginConfirmed', function(username) {
42 // code
43});
44```
45A conneted client can send `UserCommands` to a server:
46```javascript
47socket.emit('roomJoin', 'someRoom', function(error, data) {
48 // code
49});
50```
51A server reply is send as a socket.io ack and has a standart node
52(error, data) callback arguments format. Semantics of most commands is
53very straitforward and simple. Only for room commands a client must
54join a room to succesfully execute them.
55
56```javascript
57socket.on('roomMessage', function(room, user, msg) {
58});
59```
60Also a server will send `ServerMessages`. Note that these messages
61don't require any reply.
62
63
64### Documentation
65
66Run `npm install -g codo` and `codo` to generate documentation. Public
67API consists of public methods of the following classes:
68
69- Class: `ServerMessages` - represents socket.io messages sent from a
70server to a client. No client reply is requered.
71- Class: `UserCommands` - represents socket.io messages sent from a
72client to a server. Server will send back a socket.io ack reply with
73(error, data) arguments.
74- Class: `ChatService` - is a server instance.
75- Class: `Room` - represents a room.
76- Class: `User` - represents an user.
77
78Look in the test directory, for socket.io-client messages, server
79setup and hooks usage.
80
81
82### TODO
83
84- API for adding custom messages.
85
86
87### License
88
89MIT