chatserver
v0.0.1
Published
Chat server
Downloads
2
Readme
I wanted to create npm package which I could expand in the future and add server which can be listening by xmlrpc protocol. It has got two methods: get instance of creator server and set the listner by jsonrpc protocol. Now It works only by jsonrpc protocol.
I wanted to show the modular structure of the application where each module performs its functions.
chatserver/lib/ChatServerConfig.js - It is module which doing configuration the application. It takes the configuration from administrator, checks it and if something wrong - sets the default values.
chatserver/lib/ChatServerStorage.js - This module works with data. In our case here work with redis. The main thing I would like to draw attention - it is using publish/subscribe in redis. This allows you to scale the application.
chatserver/lib/ChatServer.js - This module creates server instance by configuration, set listner and create builder of responses. When user connects he can send commands using jsonrpc protocol. The program parse messages, and call the command methods. For each connection the program creates storage instance where is created publisher and subscriber. Responses are sending to listner by callbacks where they are being sent to user using web socket. It is basic logic of this program.
I wanted to create flexible mechanism for configuration using yarg package. You can see how I have done it here - (chatserver/lib/constants/config.js) As the result you can give to the program some configuration file like this /path/to/node_chat/chatServer.js --config=configExample.json Run the program with option --help to read more the details.
In db_pool.js I wanted to gather methods for creating a connection to databases. If I had mysql as databases I would have posted it here.
I used "redis": "^0.12.1", "underscore": "^1.8.2", "websocket": "^1.0.17", "yargs": "^3.5.4" you can see the dependencies in package.json.
For create the chat server you have to get instanse and call the method init_jsonrpc() as the example:
var ChatCreator=require('chatserver');
var ChatServer=ChatCreator.getInstance(); ChatServer.init_jsonrpc();