Skip to content

Commit

Permalink
Invoke Socket.IO callbacks with app and request context (Fixes #262)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jun 8, 2019
1 parent 4e0329b commit 75a75d4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ def ping():
if not include_self and not skip_sid:
skip_sid = flask.request.sid
callback = kwargs.pop('callback', None)
if callback:
# wrap the callback so that it sets app app and request contexts
sid = flask.request.sid
original_callback = callback

def _callback_wrapper(*args):
return self._handle_event(original_callback, None, namespace,
sid, *args)

callback = _callback_wrapper
self.server.emit(event, *args, namespace=namespace, room=room,
skip_sid=skip_sid, callback=callback, **kwargs)

Expand Down

0 comments on commit 75a75d4

Please sign in to comment.