1
votes

I'm using the REST API to create rooms. In the docs, it says a room will end when empty for 5 minutes. I would like to know what this means when trying to reuse the same room. Can participants rejoin that room again?

My use case is that users make request to join a room via a server endpoint. A check by UniqueName is performed to see if this room exists. If it does not, it is then created using the UniqueName.

There will certainly be cases where a room is created but is empty for more than 5 minutes, and I would like to re-use the same UniqueName to join the room (empty, completed or otherwise). But it's not clear to me that this can be done once a room is completed.

E.g., if another user tries to join the completed room, will the logic from above still work, or will it break b/c the room is in completed status can cannot be joined or re-created? My goal is to always have access to a room with the same UniqueName.

Please advise, thanks.

Edit

I just had a thought to instead retrieve a list of rooms by UniqueName, which would show me a room that has already been created, regardless of its status. However, I would still need to be able to use the same room if its status is completed.

Can the status be updated from completed to in-progress?

Update

It would seem that the status cannot be updated from completed to in-progress. So, when a room is completed, how I can I continue to use the same UniqueName for another room if one already exists with that unique name?

1

1 Answers

2
votes

Answering my own question here as I think I have a solution.

After tinkering with the Twilio quickstart app, I discovered that the UniqueName is unique in the context of rooms that are in-progress. I verified this by joining and leaving a room multiple times within a few seconds. A new room was created every time I left. I wasn't aware of this, but rooms created via client SDK will close instantly after all participants leave. As stated in the docs, rooms created via the REST API remain open for 5 minutes.

When I say "created", I mean that a new room with a new SID is created and can be viewed in the Twilio console, even if the UniqueName has not changed. So you can in fact have multiple rooms with the same UniqueName, but only the room with status in-progress is evaluated against when making REST API calls.

Thus, the answer would be to simply try to create a room with a unique name. Doing so when the room exists results in a 404 error as stated in the docs. Ie:

{ [Error: Room exists]
  status: 400,
  message: 'Room exists',
  code: 53113,
  moreInfo: 'https://www.twilio.com/docs/errors/53113',
  detail: undefined }

However, if a room with that unique name was already completed, a new room with the same unique name can be created. The simplest approach would be to try/catch on creating a room and handle the error.

  let room;

  try {
    room = await client.video.rooms.create({uniqueName: 'test'})
  } catch (e) {
    console.log(e);
  }