2
votes

I am creating a twilio video room using the rest api and setting up a statusCallback:

classroomRouter.route('/room/:id')
.get(function (req, res) {
  client.video.rooms
  .create({
    uniqueName: req.params.id,
    statusCallback: 'localhost:3000/classrooms/listen'
  })
  .then(function (room) {
    console.log('room.sid');
    console.log(room.sid);
  });
});

Twilio will be sending requests to the statusCallback whenever an event happens in the room right? To the best of my knowledge, refreshing the window on which the room is rendered constitutes a participantdisconnected and participantConnected event.

But the route I setup(localhost:3000/classrooms/listen) didnt recieve any requests when i refreshed the window. Why is this?

I have a few other queries too: Q1: Can two rooms have the same uniqueName?

(The twilio docs say that you can query a list of rooms using their uniquename. If the names are unique, how can it be a 'list' of rooms?)

Q2: If the names are indeed unique, what happens if a room already exists with uniquename I provide? Will it return the already existing room?

Q3: How can I issue this command only if the room doesnt exist?

1

1 Answers

2
votes

Twilio developer evangelist here.

Twilio can't reach localhost:3000 on your machine as that is not a public address. When developing Twilio apps, we recommend you use a tool like ngrok that can tunnel into your machine and expose your application. I wrote a blog post up a while back on why I like using ngrok.

Q1: Can two rooms have the same uniqueName? (The twilio docs say that you can query a list of rooms using their uniquename. If the names are unique, how can it be a 'list' of rooms?)

Two rooms cannot have the same uniqueName. If you filter a list response by uniqueName then you will still get a list returned, it will just contain one room.

Q2: If the names are indeed unique, what happens if a room already exists with uniquename I provide? Will it return the already existing room?

If you are creating a room with a uniqueName that already exists, you will receive an error which you should handle with a catch function on your Promise.

Q3: How can I issue this command only if the room doesnt exist?

You could query the API for the room by the uniqueName first, and then decide to create it based on whether you get a response. Or you can catch the error after you try to create it and handle it that way instead.