Since I wasn't able to find a solution using javascript/react, I have decided to solve it from the backend which is using an old Laravel version(4.2). I created a route that all participants will call whenever someone joins in the room or turns on/off their camera:
// routes.php
Route::get('room/{name}/participants/all', function ($name) {
$twilioConfig = \Config::get('app.twilio.video');
$twilioApiKey = $twilioConfig['apiKey'];
$twilioApiSecret = $twilioConfig['apiSecret'];
$client = new \Twilio\Rest\Client($twilioApiKey, $twilioApiSecret);
$participants = $client->video->rooms($name)
->participants->read(["status" => "connected"]);
$allParticipants = [];
$count = count($participants);
foreach ($participants as $participant) {
$publishedTracks = $client->video->rooms($name)
->participants($participant->sid)
->publishedTracks->read();
$videoOn = false;
foreach ($publishedTracks as $publishedTrack) {
if ('video' === $publishedTrack->kind && $publishedTrack->enabled) {
$videoOn = true;
break;
}
}
$format = 'H:i:s';
$allParticipants[$participant->sid] = [
'identity' => $participant->identity,
'created' => $participant->dateCreated->format($format),
'updated' => $participant->dateUpdated->format($format),
'started' => $participant->startTime->format($format),
'videoOn' => $videoOn,
'order' => $count--,
];
}
return \Illuminate\Support\Facades\Response::json($allParticipants);
});
The order is set to be in descending order because that's how the response I get from the Twilio's participants list per room (last joining participant first), which for me doesn't matter because it can be easily parsed in the frontend side.
Basically:
- get the list of all participants in the room
- for every participant, get all tracks it is publishing
- get the status of the
video
track in particular
- return the full list of participants to the react app
Response looks like this:
[
{
"identity": "morcen1@example.com",
"created": "17:05:17",
"updated": "17:07:11",
"started": "17:05:17",
"videoOn": true,
"order": 4
},
{
"identity": "morcen2@example.com",
"created": "17:05:16",
"updated": "17:07:08",
"started": "17:05:16",
"videoOn": true,
"order": 3
},
{
"identity": "morcen3@example.com",
"created": "17:05:15",
"updated": "17:07:04",
"started": "17:05:15",
"videoOn": true,
"order": 2
},
{
"identity": "morcen4@example.com",
"created": "16:46:32",
"updated": "17:07:14",
"started": "16:46:32",
"videoOn": true,
"order": 1
}
]
This script can also be useful for determining the status of audio
track.