Skip to content

alevor657/socketio-chat-server

Repository files navigation

Build Status Code Coverage Build Status

Socketio chat server

This is a simple chat server built with socket.io

Usage

import Chat from 'socketio-chat-server'
...
// You must set a port
new Chat(require('http').createServer().listen(port))
// Aaaand its running

Chat listens to emits of type:

  • waits for: 'new user' - you can pass your user data here emits: 'update usernames' and passes all usernames to clients

  • waits for: 'disconnect' emits: 'update usernames' and passes all usernames to clients

  • waits for: 'message' - you can pass your user data here emits: 'message' and passes message to clients OR if you add /w ${username} ${message} it will emit only to one user specified as ${username}

Testing

npm test

Environment

You can set DBWEBB_SOCKETIO_PORT to test server on whatever port you like. Defaults to 1340 otherways.