2017-09-13 7 views
1

REST Api(php)を使用してTwilioでピアツーピアルームを作成しようとしています。コードは以下の通りである:REST APIを使用する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(); 
?> 

で彼らの例ではTwilioによって提供されるように、私はコードのみを使用しています: https://www.twilio.com/docs/api/video/rooms-resource

ピアツーピアルームの作成。

で生成されたウェブ・トークンのデータペイロードをテスト中: 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は反応に時間がかかり、サポートはあまり良くありません。彼らは単純な例を提供しておらず、紛らわしいノードの例だけを提供しています。

ヘルプが必要です。

答えて

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

関連する問題