2

I am trying to create a peer-to-peer room in Twilio using REST Api (php). The code is as follows:

<?php
require_once 'Twilio/autoload.php';
use Twilio\Rest\Client;
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
include_once  'config.inc.php';
$identity = "alice";
$client = new Client($TWILIO_API_KEY, $TWILIO_API_SECRET);
$roomName = $client->video->rooms->create([
    'uniqueName' => 'TestRoom2',
    'type' => 'peer-to-peer',
    'enableTurn' => false,
    'Duration'   => 300,
    'MaxParticipants'  => 2,
    'statusCallback' => 'http://example.org'
]);
//echo $roomName->status;
//token
$token= new AccessToken($TWILIO_ACCOUNT_SID, $TWILIO_API_KEY, $TWILIO_API_SECRET, 300, $identity);
// Create Video grant
$videoGrant = new VideoGrant();
$videoGrant->setRoom($roomName);
// Add grant to token
$token->addGrant($videoGrant);
// return serialized token
 echo $token->toJWT();
?>

I am only using the code as provided by Twilio in their example at: https://www.twilio.com/docs/api/video/rooms-resource

Peer-to-Peer Room creation.

While testing the data payload of web token generated at: https://jwt.io/

It is displaying Room Blank.

{
  "jti": "SK1ddcfb6782fa358cb5e2306f8875ac1d-1505266888",
  "iss": "SK1ddcfb6782fa358cb5e2306f8875ac1d",
  "sub": "AC6c23ea48bd7d6bd681d21301f35c22b6",
  "exp": 1505267188,
  "grants": {
    "identity": "alice",
    "video": {
      "room": {}
    }
  }
}

If i create a room using the following, it works fine.

$roomName = "TestRoom";

The issue is with the code:

$client = new Client($TWILIO_API_KEY, $TWILIO_API_SECRET);
$roomName = $client->video->rooms->create([
    'uniqueName' => 'TestRoom2',
    'type' => 'peer-to-peer',
    'enableTurn' => false,
    'Duration'   => 300,
    'MaxParticipants'  => 2,
    'statusCallback' => 'http://example.org'
]);

What is wrong in my Twilio peer-to-peer room code?? Twilio takes too much time to respond and support is not so good. They have not provided simple examples either, only a node js example which is confusing.

Help requested.

Pamela
  • 684
  • 1
  • 7
  • 21

1 Answers1

1

It seems like you're passing a room object to setRoom, but setRoom expects just a string (the name of the room).

You probably want something like this (note the use of $roomName vs. $room):

$roomName = 'TestRoom2';
$room = $client->video->rooms->create([
    'uniqueName' => $roomName,
    'type' => 'peer-to-peer',
    'enableTurn' => false,
    'Duration'   => 300,
    'MaxParticipants'  => 2,
    'statusCallback' => 'http://example.org'
]);
$token = new AccessToken($TWILIO_ACCOUNT_SID, $TWILIO_API_KEY, $TWILIO_API_SECRET, 300, $identity);
$videoGrant = new VideoGrant();
$videoGrant->setRoom($roomName);
$token->addGrant($videoGrant);
echo $token->toJWT();
user94559
  • 59,196
  • 6
  • 103
  • 103