twilio视频通话错误 - 无法将参与者添加到对话中

时间:2016-03-18 10:44:31

标签: javascript php twilio-php

在主twilio帐户中,我创建了两个帐户,以便我可以在两者之间建立视频通话。但是每次我尝试这样做都会给我一个错误,上面写着“未能将参与者添加到对话twilio视频聊天”。但是,当我从twilio测试工具中调用这些帐户时,呼叫已成功连接。我不知道我在这里做的错误是什么。我的代码是:

THIS IS MY SCRIPT:
var conversationsClient;
var activeConversation;
var previewMedia;
var identity;
var accessManager;
var localEndpoint;
var uid = document.getElementById('uid').value;
var key = document.getElementById('key').value;

if (!navigator.webkitGetUserMedia && !navigator.mozGetUserMedia) {
alert('WebRTC is not available in your browser.');
}

$.getJSON('/video/token.php?uid=' + uid + '&key=' + key, function (data) {
identity = data.identity;
accessManager = new Twilio.AccessManager(data.token);


console.log(identity);

localEndpoint = identity;
var endpointOptions = {wsServer: 'wss://' + data.sid + '.endpoint.twilio.com'};

conversationsClient = new Twilio.Conversations.Client(accessManager, endpointOptions);
conversationsClient.listen().then(clientConnected, function (error) {
    log('Could not connect to Twilio: ' + error.message);
});
});


function clientConnected() {
document.getElementById('invite-controls').style.display = 'block';
log("Connected to Twilio. Listening for incoming Invites as '" + conversationsClient.identity + "'");

conversationsClient.on('invite', function (invite) {
    log('Incoming invite from: ' + invite.from);
    invite.accept().then(conversationStarted);
});


document.getElementById('button-invite').onclick = function () {
    var inviteTo = document.getElementById('invite-to').value;
    if (!inviteTo) {
        alert('Enter User ID');
        return false;
    }
    if (activeConversation) {

        activeConversation.invite(inviteTo);
    } else {

        var options = {};
        if (previewMedia) {
            options.localMedia = new Twilio.Conversations.LocalMedia();
        }


        conversationsClient.inviteToConversation(inviteTo, options).then(conversationStarted, function (error) {
            log('Unable to create conversation');
            console.error('Unable to create conversation', error.message);
        });


    }
};
}


function conversationStarted(conversation) {
log('In an active Conversation');
activeConversation = conversation;

if (!previewMedia) {
    conversation.localMedia.attach('#local-media');
}


conversation.on('participantConnected', function (participant) {
    log("Participant '" + participant.identity + "' connected");
    participant.media.attach('#remote-media');
});


conversation.on('participantDisconnected', function (participant) {
    log("Participant '" + participant.identity + "' disconnected");
});


conversation.on('disconnected', function (conversation) {
    log("Connected to Twilio. Listening for incoming Invites as '" + conversationsClient.identity + "'");
    conversation.localMedia.stop();
    conversation.disconnect();
    activeConversation = null;
});
}


document.getElementById('button-preview').onclick = function () {
if (!previewMedia) {
    previewMedia = new Twilio.Conversations.LocalMedia();
    Twilio.Conversations.getUserMedia().then(
        function (mediaStream) {
            previewMedia.addStream(mediaStream);
            previewMedia.attach('#local-media');
        },
        function (error) {
            console.error('Unable to access local media', error);
            log('Unable to access Camera and Microphone');
        });
}
};


function log(message) {
document.getElementById('log-content').innerHTML = message;
}

THIS IS MY PHP FILE
$sid = "AC63406acac5aa7bd54e231ab631bc26d6";
$token = "5430f5320bae6f6099b2ab550eff13fc";
$client = new Services_Twilio($sid, $token);

$uid = $_GET['uid'];
$key = $_GET['key'];


$keyq = $client->account->keys->get($uid);


//$key = $client->account->keys->create(array("FriendlyName" => "ajay"));
//echo $key->sid.'<br>';
//echo $key->secret;
//die('');
//var_dump($client->account);exit;
// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$identity = $keyq->friendly_name;


//$token = new Services_Twilio_AccessToken($sid,'SKf91ca28602e5eff8357583cb052b24f4','2kvqUiBplMieCdwwYC7ijRT8tFvzeQIt',3600,$identity);
//$token->addEndpointGrant($sid);
//$token->enableNTS();

//$grant = new Services_Twilio_Auth_ConversationsGrant();
//$grant->setConfigurationProfileSid('AC63406acac5aa7bd54e231ab631bc26d6');
////$token->addGrant($grant);

$token = new Services_Twilio_AccessToken($uid,$sid, $key);
$token->addEndpointGrant($identity);
$token->enableNTS();


echo json_encode(array(
'identity' => $identity,
'token' => $token->toJWT(),
'sid' => $sid
));

1 个答案:

答案 0 :(得分:1)

来自Twilio的梅根在这里。

首先,打开调试非常有用:

conversationsClient = new Twilio.Conversations.Client(accessManager, {logLevel: 'debug'});

然后检查控制台中的输出。

您可能需要仔细检查AccessToken并确保按照以下说明正确使用它们:

https://www.twilio.com/docs/api/video/guide/identity

希望这有帮助!