有没有办法在使用 Room API 创建房间时指定 statusCallbackEvent?就像在 TwiML 中一样,我们可以在此处指定 statusCallbackEvent文档。这是房间创建的代码片段:
// 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
});
目前,它会在每个事件上向我的后端发送 POST 请求,例如“参与者连接,断开连接......”。
这是处理 POST 请求的片段
// 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");
});