secmsg/secmsg/__init__.py

45 lines
968 B
Python

"""
this file is part of secmsg, and is licensed under the AGPL.
please see the terms of the license in the file LICENSE.
copyright 2023 randomuser
"""
import os
from flask import Flask
from flask import send_from_directory
from flask import redirect
from flask_sock import Sock
import simple_websocket
app = Flask(__name__, instance_relative_config=True)
sock = Sock(app)
clients = []
@app.route('/')
def index():
return redirect("/static/app")
@app.route('/static/app')
def app_redirect():
return redirect("/static/app.html")
@app.route('/static/<path:path>')
def static_handler(path):
return send_from_directory('static', path)
@sock.route('/client')
def sock_handler(ws):
clients.append(ws)
try:
while True:
data = ws.receive()
for client in clients:
if not client is ws:
client.send(data)
except simple_websocket.ws.ConnectionClosed:
clients.remove(ws)