Is there any way to specify the statusCallbackEvent while creating a room using Room API? Like in TwiML we can specify the statusCallbackEvent docs here. Here is the code snippet for room creatiion:
// Create Room using twilio API
const room = await client.video.rooms.create({
type: type, //group-small
uniqueName: req.body.room,
maxParticipants: maxParticipants,
recordParticipantsOnConnect: false,
mediaRegion: "in1",
statusCallback: process.env.URL+"/room/room-ended",
statusCallbackMethod: "POST",
// statusCallbackEvent: ['room-ended'] specifying the room completed event
});
Currently it sends POST request to my backend on every event like 'participant-connected, disconnected...'.
Here is the snippet to handle the POST request
// Method: POST
// deletes room from database after a room is completed
// callback after room completed
router.post('/room-ended', async (req, res)=>{
// Get room model from database and delete it
if(req.body.RoomStatus === "completed")
await Room.deleteOne({sid: req.body.RoomSid});
res.status(200).send("success");
});