我看到留档https://www.twilio.com/docs/video/api/rooms-resource#rooms-list-resource
但是我找不到如何设置mediaRegion。你能告诉我怎么做吗?
这是我尝试,但它不起作用:
use Symfony\Component\HttpFoundation\Request;
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
use Twilio\Rest\Client;
class VideoconferencingController extends Controller
{
public function createAction(Request $request, $roomName)
{
$user = $this->getUser();
// An identifier for your app - can be anything you'd like
$identity = $user->getFullName();
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$twilioAccountSid,
$twilioApiKey,
$twilioApiSecret,
3600,
$identity
);
// Create Video grant
$videoGrant = new VideoGrant();
$videoGrant->setRoom($roomName);
// Add grant to token
$token->addGrant($videoGrant);
$twilio = new Client($twilioApiKey, $twilioApiSecret, $twilioAccountSid);
$room = $twilio
->video
->v1
// ->rooms($roomName)
->rooms('RM2900c0f08a237f6e978fc413cb997403')
->mediaRegion('ie1')
->update('completed')
;
error_log(print_r($room,1));
// render token to string
return [
'token' => $token->toJWT(),
'roomName' => $roomName,
];
}
最好的问候,布鲁诺
我找到了我需要做的。
使用mediaRegion创建房间:
use Symfony\Component\HttpFoundation\Request;
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
use Twilio\Rest\Client;
class VideoconferencingController extends Controller
{
public function createAction(Request $request, $twilioRoomSid, $staffId, $roomName)
{
$twilioRoomSid = ('undefined' == $twilioRoomSid) ? null : $twilioRoomSid;
$user = $this->getUser();
$twilioAccountSid = $this->getParameter('twilio_account_sid');
$twilioApiKey = $this->getParameter('twilio_api_key');
$twilioApiSecret = $this->getParameter('twilio_api_secret');
$now = new \DateTime();
// Get or create room
$twilio = new Client($twilioApiKey, $twilioApiSecret, $twilioAccountSid);
if ($twilioRoomSid) {
$room = $twilio
->video
->v1
->rooms($twilioRoomSid)
->fetch()
;
}
$createRoom = (!$twilioRoomSid || 'completed' == $room->status) ? true : false;
if ($createRoom) {
$room = $twilio
->video
->v1
->rooms
->create([
'mediaRegion' => 'ie1',
'uniqueName' => $roomName
]
)
;
$twilioRoomSid = $room->sid;
$staff = $this->findOr404('App:Staff', $staffId);
$staff->setTwilioRoomSid($twilioRoomSid);
$this->flush();
}
// Authorize room
$identity = $user->getFullName();
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$twilioAccountSid,
$twilioApiKey,
$twilioApiSecret,
3600,
$identity
);
// Create Video grant
$videoGrant = new VideoGrant();
$videoGrant->setRoom($twilioRoomSid);
// Add grant to token
$token->addGrant($videoGrant);
// render token to string
return [
'token' => $token->toJWT(),
'roomName' => $roomName,
];
}
}