This is the simple chat-server worked via websocket. The server has the next features:
- supporting of conversations in channels
- private messages
- authentication via social networks
You should generate certs with help of the next command (should be run in root dir of the project):
$ mkdir -p ssl && openssl req -nodes -new -x509 -keyout ssl/server.key -out ssl/server.cert
FACEBOOK_CLIENT_ID
- identifier of the facebook's applicationFACEBOOK_CLIENT_SECRET
- facebook's application tokenFACEBOOK_CALLBACK_URL
- valid OAuth redirect URI, default value ishttps://localhost:8081/auth/facebook/callback
CS_POSTGRES_URL
- url for PostgreSQL database, default value isjdbc:postgresql://localhost:5432/testdb
CS_POSTGRES_USERNAME
- username of the database, default value ispostgres
CS_POSTGRES_PASSWORD
- password for this username, default value ispostgres
User can to send special messages for executing of some actions such as create channel, join to there etc. For example:
{
"type": "command",
"action": "create",
"target": "#main"
}
Field action
has the next values: create
, destroy
, join
, leave
for channels.
User's message in websocket has the next format:
{
"type": "message",
"target": "username",
"message": "message"
}
In target
field need to specify channel or username according to the next rules:
- channel specified via
#
as#channelname
- user specified via
@
as@username
Channel's and user's names can't to contain special symbols of course.
Server can send events' messages with the next format:
{
"type": "event",
"emitter": "participant",
"identifier": "dbcf5b4a-c0ef-4ddf-8885-f7b6c0631471",
"event": "join"
}
When emitter
field is:
participant
thenevent
has value ofjoin
orleft
channel
thenevent
iscreate
ordestroy
Some user created a channel:
{
"type": "command",
"action": "create",
"target": "#main"
}
Server responses to all clients of the server:
{
"type": "event",
"emitter": "channel",
"identifier": "#main",
"event": "create"
}
User wants to join into channel:
{
"type": "command",
"action": "join",
"target": "#main"
}
Server responds to all channel's participants:
{
"type": "event",
"emitter": "participant",
"identifier": "dbcf5b4a-c0ef-4ddf-8885-f7b6c0631471",
"event": "join"
}
User sends message into channel:
{
"type": "message",
"target": "#main",
"message": "Hello guys!"
}
Server broadcasts this message to all channel's participants.
{
"type": "message",
"emitter": "participant",
"target": "#main",
"identifier": "dbcf5b4a-c0ef-4ddf-8885-f7b6c0631471",
"message": "Hello guys!"
}
This server's answer needs for client side.
User leaves the specified channel:
{
"type": "command",
"action": "leave",
"target": "#main"
}
Server notify other participants of the channel about this event:
{
"type": "event",
"emitter": "participant",
"identifier": "dbcf5b4a-c0ef-4ddf-8885-f7b6c0631471",
"event": "left"
}
Somebody destroys channel:
{
"type": "command",
"action": "destroy",
"target": "#main"
}
and server notifies all connected clients about it:
{
"type": "event",
"emitter": "channel",
"identifier": "#main",
"event": "destroy"
}