2017-09-13 2 views
1

REST API (php)를 사용하여 Twilio에서 피어 투 피어 룸을 만들려고합니다. https://www.twilio.com/docs/api/video/rooms-resourceREST API를 사용하는 Twilio 토큰 및 피어 투 피어 룸

피어 - 투 - 피어 룸 생성 : 그들의 예에 Twilio가 제공 한 난 단지 코드를 사용하고

<?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(); 
?> 

다음과 같이 코드입니다.

에서 생성 된 웹 토큰의 데이터 페이로드 테스트하는 동안 : https://jwt.io/

그것은 빈 방을 표시됩니다.

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

다음을 사용하여 회의실을 만드는 경우 정상적으로 작동합니다.

$roomName = "TestRoom"; 

문제는 코드입니다 :

$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' 
]); 

내 Twilio 피어 - 투 - 피어 객실 코드의 문제점은 무엇입니까 ?? Twilio는 너무 많은 시간을 들여 반응하고 지원하지 않습니다. 그것들은 단순한 예제도 제공하지 않았고, 단지 노드 js 예제 만 혼란 스럽다.

도움 요청.

답변

1

방 객체를 setRoom으로 전달하는 것처럼 보이지만 setRoom은 문자열 (방 이름)을 필요로합니다.

당신은 아마 ($roomName$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(); 
+0

너무 많은 감사를! – Pamela