@gluedigital/chat-server
v0.1.3
Published
The chat-server core
Downloads
5
Keywords
Readme
Chat Server
A modular chat server for all your chat needs.
Usage
Creating your own chat server is very easy. Just install this module and any other plugins you'd like to use as dependencies, and initialize everything from your main:
const Chat = require('@gluedigital/chat-server')
const FakeAuth = require('@gluedigital//chat-server-plugin-fakeauth').default
const chat = new Chat(process.env.PORT || 5000)
const fakeauth = new FakeAuth(chat)
chat.start()
Protocol
This server uses websockets for all the communication. The message protocol is described below.
NOTE: The protocol is not stable yet, and may change at any time.
These are the message types that can be sent on the Chat protocol:
From Client To Server
Outgoing chat message:
{
type: 'message',
target: 'userB',
text: 'hi, how are you?',
senderId: 123
}
From Server To Client
Incoming chat message:
{
id: 1519389731000,
type: 'message',
target: 'userA',
author: 'userB',
text: 'fine, you?'
}
Notes:
- The id is the canonical date (ie: server timestamp when received) of the message
- When sending a message, you receive it back as incoming, but with the senderId so you can keep track of it
On connection:
{
type: 'initial',
user: 'userA',
rooms: {
'userB': {
stats: { /* to be determined */ },
messages: [
/* similar to incoming messages */
]
},
'#group1': { /* etc... */ }
}
}