Skip to content

Commit

Permalink
♻️ #1 Now could able to call socketio events even in other file
Browse files Browse the repository at this point in the history
  • Loading branch information
Balaji-Ganesh committed Jun 12, 2023
1 parent f332473 commit 6ba3d99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 16 additions & 6 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
from flask import Flask
from flask_socketio import SocketIO

# from .middleware.communication import get_cam_feed

socketio: SocketIO = SocketIO


def create_app():
app = Flask(__name__, template_folder='templates')
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, cors_allowed_origins="*")#, logger=True, engineio_logger=True) # to run websockets for this flask app. A new server runs for this.


""" ----------- Register blueprints -----------"""
from .web import web as main_blueprint # for displaying web-pages
# from .feed import feed # for handling camera and ultra-sonic feed

app.register_blueprint(main_blueprint, url_prefix='/')
# app.register_blueprint(feed, url_prefix='/feed')


return socketio, app
global socketio
# , logger=True, engineio_logger=True) # to run websockets for this flask app. A new server runs for this.
socketio = SocketIO(app, cors_allowed_origins="*")

return app


# Create the application..
socketio, app = create_app()
app = create_app()
print("Application created")

# Get the event handlers
from .middleware.communication.web_communicator import handle_connect, handle_stream, handle_disconnect
from .middleware.communication import get_cam_feed
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from app import socketio, app
import cv2
import base64
from app import socketio, app

# FIXME: later figure out the way to place this in some file like, `web` and `feed`
# alternative to socketio.on_event('manual_mode', handler=handle_manual_mode, namespace='/')
Expand All @@ -13,6 +13,11 @@ def handle_manual_mode(data):
# socketio.emit('acknowledgement', "You are connected")
socketio.send('test')

# Event handlers for socketio
# @socketio.on('connect')
# def handle_connect():
# print("Client connected successfully")


if __name__ == '__main__':
socketio.run(app, debug=True)

0 comments on commit 6ba3d99

Please sign in to comment.