diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 82b392e..5886b56 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -5,6 +5,30 @@ Installation pip install flask-sock +Configuration +------------- + +The only configuration option is ``SOCK_SERVER_OPTIONS``. If this option is +present in the application instance's ``config`` object, it must be a +dictionary with configuration options for the WebSocket server. Notable +options include: + +- ``ping_interval``: Send ping packets to clients at the requested interval in + seconds. Set to ``None`` (the default) to disable ping/pong logic. Enable to + prevent disconnections when the line is idle for a certain amount of time, or + to detect unresponsive clients and disconnect them. A recommended interval is + 25 seconds. +- ``max_message_size``: The maximum size allowed for a message, in bytes, or + ``None`` for no limit. The default is ``None``. + +Example:: + + app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25} + +The complete list of available options is documented in the constructor of the +`simple_websocket.Server `_ +class. + Example ------- diff --git a/example/echo-eventlet.py b/example/echo-eventlet.py index 0c6e368..1af94de 100644 --- a/example/echo-eventlet.py +++ b/example/echo-eventlet.py @@ -5,6 +5,7 @@ from flask import Flask, render_template from flask_sock import Sock app = Flask(__name__) +app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25} sock = Sock(app) diff --git a/example/echo-gevent.py b/example/echo-gevent.py index ff5ec39..a33ba1a 100644 --- a/example/echo-gevent.py +++ b/example/echo-gevent.py @@ -5,6 +5,7 @@ from flask import Flask, render_template from flask_sock import Sock app = Flask(__name__) +app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25} sock = Sock(app) diff --git a/example/echo.py b/example/echo.py index d477702..8dbb6e4 100644 --- a/example/echo.py +++ b/example/echo.py @@ -2,6 +2,8 @@ from flask_sock import Sock app = Flask(__name__) +app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 25} + sock = Sock(app) diff --git a/src/flask_sock/__init__.py b/src/flask_sock/__init__.py index 71050b8..3866cbf 100644 --- a/src/flask_sock/__init__.py +++ b/src/flask_sock/__init__.py @@ -1,5 +1,5 @@ from functools import wraps -from flask import Blueprint, request, Response +from flask import Blueprint, request, Response, current_app from simple_websocket import Server, ConnectionClosed @@ -53,7 +53,8 @@ def websocket_route(ws): def decorator(f): @wraps(f) def websocket_route(*args, **kwargs): # pragma: no cover - ws = Server(request.environ) + ws = Server(request.environ, **current_app.config.get( + 'SOCK_SERVER_OPTIONS', {})) try: f(ws, *args, **kwargs) except ConnectionClosed: