cookiecutter-django/{{cookiecutter.project_slug}}/config/websocket.py

14 lines
439 B
Python
Raw Normal View History

async def websocket_application(scope, receive, send):
while True:
event = await receive()
2020-03-24 23:12:47 +03:00
if event["type"] == "websocket.connect":
await send({"type": "websocket.accept"})
2020-03-24 23:12:47 +03:00
if event["type"] == "websocket.disconnect":
break
2020-03-24 23:12:47 +03:00
if event["type"] == "websocket.receive":
if event["text"] == "ping":
await send({"type": "websocket.send", "text": "pong!"})