diff --git a/api/api.py b/api/api.py index 6c795b8..78efbbb 100644 --- a/api/api.py +++ b/api/api.py @@ -1,7 +1,5 @@ from flask import Blueprint, request, jsonify, session from .users.user_endpoint import UserEndpoint -from app import socketio -from flask_socketio import emit api = Blueprint('api', __name__, url_prefix='/api') @@ -17,13 +15,3 @@ def api_users(): @api.route('/user') def api_user(): return jsonify(UserEndpoint.user()) - -@socketio.on('connect') -def handle_connection(): - print('connected') - socketio.emit('connect', payload={'data':'connection'}) - -@socketio.on('message') -def handle_message(message): - print(message) - emit('message return', {'data':'a message was sent'}) \ No newline at end of file diff --git a/server.py b/server.py index 23b7e45..bebf6c1 100644 --- a/server.py +++ b/server.py @@ -1,9 +1,12 @@ -from app import create_app, db, socketio +from app import create_app, db # Blueprints from api.api import api from auth.auth import auth +# Web sockets +from websockets.socket import socketio + import configuration.models_mount from flask_migrate import Migrate @@ -14,4 +17,4 @@ if __name__ == '__main__': app.register_blueprint(api) app.register_blueprint(auth) migrate = Migrate(app, db) - socketio.run(app) \ No newline at end of file + socketio.run(app, debug=True) \ No newline at end of file diff --git a/websockets/__init__.py b/websockets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/websockets/socket.py b/websockets/socket.py new file mode 100644 index 0000000..5de2d8c --- /dev/null +++ b/websockets/socket.py @@ -0,0 +1,17 @@ +from app import socketio +from flask_socketio import send, emit + +@socketio.on('connect') +def handle_connection(): + print(''' + + wow, there was a socketio connection! + + cool + ''') + send({'data':'connection'}) + +@socketio.on('message') +def handle_message(message): + print(message) + emit('message return', {'data':'a message was sent'}) \ No newline at end of file