Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

252 [Back] Add flask socketio #269

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions server/scratchy_server/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Flask
from flask_cors import CORS
from flask_restful import Api
from flask_socketio import SocketIO
from flask_apispec.extension import FlaskApiSpec
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
Expand Down Expand Up @@ -29,6 +30,7 @@

app = Flask(__name__)
CORS(app)
socketio = SocketIO(app)

# main configuration from config data (file)
app.config.update(config_data)
Expand Down Expand Up @@ -66,5 +68,8 @@
list(map(lambda res: app.add_url_rule(res["url"], view_func=res["ressource"].as_view(res["name"])), ressource))
list(map(lambda res: docs.register(res["ressource"], endpoint=res["name"]), ressource))

socketio.on_namespace(RoomRes('/room/<string:roomId>'))

socketio.run(app, port=5000, host='0.0.0.0')

logging.info("scratchy is up and ready")
6 changes: 5 additions & 1 deletion server/scratchy_server/resources/roomres.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import make_response
from flask_socketio import Namespace
from flask_apispec import marshal_with, use_kwargs, doc
from flask_apispec.views import MethodResource
from marshmallow import fields
Expand All @@ -8,7 +9,7 @@


@doc(tags=['Room'])
class RoomRes(MethodResource):
class RoomRes(MethodResource, Namespace):
decorators = [validation]

@marshal_with(RoomSchema, code=200)
Expand All @@ -27,6 +28,9 @@ def delete(self, roomId):
RoomModel.objects().get_or_404(id=roomId).delete()
return make_response('', 204)

def on_get(self, *args, **kwargs):
self.get(*args, **kwargs)


@doc(tags=['Room'])
class AllRoomRes(MethodResource):
Expand Down
2 changes: 1 addition & 1 deletion server/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

# Merci Sam & Max : http://sametmax.com/creer-un-setup-py-et-mettre-sa-bibliotheque-python-en-ligne-sur-pypi/
# Merci Sam & Max : http://sametmax2.com/creer-un-setup-py-et-mettre-sa-bibliotheque-python-en-ligne-sur-pypi/

setup(
name='scratchy_server',
Expand Down