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");
});
The steps you have in place are correct: set a statusCallback URL when creating the room, and then use logic to handle the specific events you want to process like 'room-created'.
Unfortunately, specifying one or more events for the statusCallback Events is not an option.
Rooms Status Callback Events: https://www.twilio.com/docs/video/api/status-callbacks#rooms-callback-events
Reference : https://www.twilio.com/docs/video/api/status-callbacks