- Copy
.env.example
to.env
& fill up env below
# if you have your own RTSP URL
RTSP_URL=
- Add
INSTALLED_APPS
INSTALLED_APPS = [
...
'channels',
]
- Add
ASGI_APPLICATION
andCHANNEL_LAYERS
- Must change
<YOUR_DJANGO_PROJECT_NAME>.asgi.application
below
- Must change
ASGI_APPLICATION = 'realtime_video_stream.asgi.application'
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer"
},
}
- Refer to
livestreaming/consumers.py
- StreamConsumer class will be served as ASGI.
- Refer to
livestreaming/routing.py
- Regex is used to route to Consumer class
re_path(r'ws/stream/$', consumers.StreamConsumer.as_asgi()),
- http request: route to main
urls.py
- websocket request: route to
routing.py
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": URLRouter(livestreaming.routing.websocket_urlpatterns),
})
- Refer to
video_stream_view
inlivestreaming/views.py
- Frontend websocket to stream video