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

问题描述 投票:0回答:1

在主 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
));
javascript php twilio twilio-php
1个回答
1
投票

这里是 Twilio 的梅根。

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

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

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

您可能需要仔细检查您的

AccessToken
并确保按照以下说明正确使用它们:

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

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.