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

标签 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
));

最佳答案

来自 Twilio 的梅根在这里。

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

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

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

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

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

希望这有帮助!

关于javascript - twilio 视频通话错误 - 无法将参与者添加到对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36082311/

相关文章:

命令行中的 SMS Twilio API 错误但浏览器中没有错误但不发送消息

php - 使用 Twilio 接收短信并将其存储在数据库中

javascript - 辅助功能 - 如何找到对比度问题?

javascript - 在 FOR 循环中等待上一个 AJAX 调用

javascript - 检查元素是否合法支持 src 属性或innerHTML

php - 数据库全选

c# - 如何使用 Web 浏览器获取用 JavaScript 编写的网页中的超链接

php - xcode ios 将 nsarray 对象拆分为两个单独的对象

php - 我正在尝试使用 php 和 mysql OOP 将记录添加到数据库

php - Twilio Ajax 响应始终触发 'Fail' ,尽管成功调用电话