Saturday, 26 November 2022

How to run Django channels with StreamingHttpResponse in ASGI

I have a simple app that streams images using open cv and the server set in wsgi. But whenever I introduce Django channels to the picture and change from WSGI to ASGI the streaming stops. How can I stream images from cv2 and in the same time use Django channels? Thanks you in advance

My code for streaming:

def camera_feed(request):
    stream = CameraStream()
    frames = stream.get_frames()
    return StreamingHttpResponse(frames, content_type='multipart/x-mixed-replace; boundary=frame')

settings.py:

ASGI_APPLICATION = 'photon.asgi.application'

asgi.py

application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': AuthMiddlewareStack(URLRouter(ws_urlpatterns))
})


from How to run Django channels with StreamingHttpResponse in ASGI

No comments:

Post a Comment