Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# WebSocketServer
WebSocket server created for a chat application.
WebSocket server created this [chat application](https://github.com/ablogo/ChatService).

This project must be used in conjunction with at least two others, one that is an authentication microservice that manage the users, and another microservice that manages chat functions.

It is necessary to develop a WebSocket client, or you can use the one found in the next repository.
It is necessary to develop a WebSocket client, or you can use the one found in [this repository](https://github.com/ablogo/WebSocketClient).

When connecting to the server, a token must be sent, which is obtained from the authentication microservice.
When connecting to the server, a token must be sent, which is obtained from this [authentication microservice](https://github.com/ablogo/AuthFastApi).

All logs are sent to a MongoDB database.

## Requirements
- Python 3.12+
- MongoDB (local server or remote server)
- MongoDB database

## Installing
1. Create a virtual environment
Expand All @@ -22,7 +22,7 @@ python -m venv .venv
```bash
source .venv/bin/activate
```
Activate it (Windows PowerShell)
- Activate it (Windows PowerShell)
```bash
.venv\Scripts\Activate.ps1
```
Expand All @@ -38,7 +38,4 @@ The address and port of the websocket server, the connection string of the datab
```bash
python main.py
```
6. Open the next url in a browser to see the Swagger UI
```bash
h
```
6. Use this [websocket client](https://github.com/ablogo/WebSocketClient) to connect and test the websocket server
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os, http, json
from websockets.sync.server import serve
from dotenv import load_dotenv
from log2mongo import log2mongo

from src.message_service import get_current_user, remove_connection, try_to_save_message, validate_message
from src.user_service import verify_token, update_status, get_messages
from src.mongo_logging import MongoLogger

users = dict()
load_dotenv()
log = MongoLogger(os.environ["LOG_DB_URL"], os.environ["LOG_DATABASE_NAME"], "", os.environ["LOG_LEVEL"])
log = log2mongo(os.environ["LOG_DB_URL"], os.environ["LOG_DATABASE_NAME"], level = os.environ["LOG_LEVEL"])

def handler(websocket):
try:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pip
websockets
requests
pymongo[srv]
dotenv
4 changes: 2 additions & 2 deletions src/message_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from datetime import datetime
import os, json
from dotenv import load_dotenv
from log2mongo import log2mongo

from src.user_service import save_message
from src.message_model import Message
from src.mongo_logging import MongoLogger

load_dotenv()
log = MongoLogger(os.environ["LOG_DB_URL"], os.environ["LOG_DATABASE_NAME"], "", os.environ["LOG_LEVEL"])
log = log2mongo(os.environ["LOG_DB_URL"], os.environ["LOG_DATABASE_NAME"], "", os.environ["LOG_LEVEL"])

def to_message(dct) -> Message | None:
try:
Expand Down
51 changes: 0 additions & 51 deletions src/mongo_logging.py

This file was deleted.

41 changes: 0 additions & 41 deletions src/mongodb_service.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/user_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os, requests, json
from log2mongo import log2mongo
from dotenv import load_dotenv

from src.message_model import Message
from src.mongo_logging import MongoLogger

load_dotenv()
log = MongoLogger(os.environ["LOG_DB_URL"], os.environ["LOG_DATABASE_NAME"], "", os.environ["LOG_LEVEL"])
log = log2mongo(os.environ["LOG_DB_URL"], os.environ["LOG_DATABASE_NAME"], "", os.environ["LOG_LEVEL"])

def verify_token(token: str):
result = False
Expand Down