Using Asych in Django views to connect to LiveKit Backend throws missing arguments
I'm new to asynch side of django rest framework. I currently have a django rest api with Django v5 with all functions written in synchronous views. However I'm attempting to add a webrtc calling feature using the Livekit server.I'm attempting to connect my django rest api to LiveKit Server(self hosted on ubuntu 22.04) using this documentation(https://github.com/livekit/python-sdks) to create a room before connecting. The documentation clearly states
RoomService uses asyncio and aiohttp to make API calls. It needs to be used with an event loop.
Here is my code for the same :
# Creating a room
# RoomService uses asyncio and aiohttp to make API calls. It needs to be used with an event loop.
async def createLiveKitRoom(self, request):
request_data = request.data.dict()
serializer = CreateLiveKitRoomSerializer(data=request_data)
serializer.is_valid()
data = serializer.validated_data
room_uuid = data.get("room_uuid")
# Will read LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET from environment variables
lkapi = LiveKitAPI(
"http://${nginx_sfu_media_server_intra_chat_ip}:${sfu_media_server_intra_i_chat_port}"
)
room_info = await lkapi.room.create_room(
CreateRoomRequest(name=room_uuid, empty_timeout=10 * 60, max_participants=20)
)
print(room_info)
await lkapi.aclose()
return room_info
asyncio.run(createLiveKitRoom())
I first have to create a room_uuid on my django end using the usual put synchronous call(which I already have) and pass this room_uuid to the above asynch call so that the room is created on livekit end using the same uuid. Both the synchronous and the asynchronous calls are currently part of views.py
However, I'm getting an error on the final line
asyncio.run(createLiveKitRoom())
which states: Its missing 2 arguments.
What's wrong in what I am doing above ?
Kindly note There are more asynch functions that follow similar code flow too as part of the documentation like participant management etc which I need to build as part of the setup.