django-channels-with-socket.io icon indicating copy to clipboard operation
django-channels-with-socket.io copied to clipboard

Role of channels?

Open BoPeng opened this issue 1 year ago • 0 comments

I am looking into integrating an existing socketio app into an django asgi server and came across your repository. It looks like you are using channels to "connect" django and socketio app, but is there any reason why you cannot directly use socketio app with django?

I mean, according to socket io documentation, we can create an application

sio = socketio.AsyncServer(async_mode='asgi')
app = socketio.ASGIApp(sio)

and then, from django's asgi.py, cannot we simply use

async def application(scope, receive, send):
    if scope["type"] == "http":
        await django_application(scope, receive, send)
    elif scope["type"] == "websocket":
        await app(scope, receive, send)
    else:
        raise NotImplementedError(f"Unknown scope type {scope['type']}")

where app is the ASGIApp?

BoPeng avatar Dec 22 '23 06:12 BoPeng