Git Product home page Git Product logo

chatserver's Introduction

Quantum SDS ChatServer

Technique Stack

Tornado, websocket, Vue.js, Redis, Django-Rest framework

Setup

1. In Chatserver project, set all required settings in chat/settings.py
2. In Quantum project .env file, set CHAT_SERVER_ADDRESS to be the address of Chatserver
3. In both Quantum proj and Chatserver proj, the redis config should be same
4. Remember to map port 8888 or 8889 to the same port on host machine

Run command

python server.py wss (https)
python server.py     (http)

Example settings

Chatserver chat/setting.py

REDIS_CONFIG = {
    'HOST': '192.168.0.107',
    'PORT': 6379,
    'PASSWORD': None,
    'USER': None
}

ALLOWED_HOSTS = ['demo-3.localhost:8001']
QUANTUM_SERVER_URL = 'http://demo-3.localhost:8001'
CERT_FILE = "/Users/chris/server.crt"
KEY_FILE = "/Users/chris/server.key"

SSL_OPTIONS = {
    'certfile': CERT_FILE,
    'keyfile': KEY_FILE
}

Quantum .env file(only chatserver related fields)

REDIS_HOST=192.168.0.107
REDIS_PASSWORD=
REDIS_PORT=6379
CHAT_SERVER_ADDRESS=192.168.0.107

Docker run command(8888 port for example)

docker build -t t1 .
&& docker run
-p 127.0.0.1:8888:8888
--name ChatServer

Architecture and Authentication

 ----------
|  Quantum |       Store Token, user info, company_info in redis(Encrypted)
|  server  |----------------------   
|          |                     |  
|----------|                     |   
 |        ^                      |
 |Socket  |                      V 
 |        |                   ---------
 |        |                  |  Redis  |
 |        | Rest API          ---------
 |        |                       ^
 V        |                       |
|-------------|                   |
| Chat Server |-------------------
|_____________|       When websocket connected, read token from redis and decrypted 
                      to check auth user

0. Create auth token using python manage.py drf_create_token

1. When User login the quantum server, use request session key, company id and user id
as key, encrypted with base64. User info, auth token as value, store in redis.
When use logout or key expires, redis delete key automatically.

2. In chatServer set ALLOWED_HOSTS to filter invalid request sources.

3. When user use the chat, Quantum server opens a websocket connection to the chat server,
chatserver receieves the encrypted token after connection established. If no encrypted token receives, close connection. 
Otherwise decryptes the token and search from redis. If exists,
the user is authenticated, otherwise close the connection.

4. When user sends message/file, chatserver distributes the message to other users in the same room, 
then call the rest api to persist the message/file into quantum db

Notice that we use Redis as message channel publish/subscribe middleware as well as Auth token storage,
be sure in Qunatum settings and Chatserver settings the address of Redis should be same

chatserver's People

Contributors

chriszhang0222 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.