【发布时间】:2020-10-28 06:19:08
【问题描述】:
每次参与者 2 出现时,他们的音频和摄像记录都会显示在参与者 1 的屏幕上。但是参与者 1 的音频/视频没有显示在参与者 2 的屏幕上。那么谁是第一个加入他们的视频和音频的人不会传输给其他参与者?
<h1>Hi there!</h1>
<div class="videos">
<div id="video-container"></div>
</div>
<div id="remote-media-div">
</div>
<?php
include('./vendor/autoload.php');
include('./config.php');
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
// Use identity and room from query string if provided
$identity = isset($_GET["identity"]) ? $_GET["identity"] : "identity" . rand();
$room = isset($_GET["room"]) ? $_GET["room"] : "testingreal";
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$TWILIO_ACCOUNT_SID,
$TWILIO_API_KEY,
$TWILIO_API_SECRET,
3600,
$identity
);
// Grant access to Video
$grant = new VideoGrant();
$grant->setRoom($room);
$token->addGrant($grant);
echo $token->toJWT();
?>
<script src="//media.twiliocdn.com/sdk/js/video/releases/2.7.3/twilio-video.min.js"></script>
<script>
var Video = Twilio.Video;
console.log(Video);
var connect = Video.connect;
Video.connect('<?=$token->toJWT()?>', { name: 'testingreal' }).then(room => {
console.log('Conmnected to Room "%s"', room.name);
room.on('participantConnected', participant => {
console.log(`Participant "${participant.identity}" connected`);
console.log('testing 213');
participant.tracks.forEach(publication => {
if (publication.isSubscribed) {
const track = publication.track;
document.getElementById('remote-media-div').appendChild(track.attach());
}
});
participant.on('trackSubscribed', track => {
document.getElementById('remote-media-div').appendChild(track.attach());
});
});
});
我在 room.on('participantConnected',participant => { //code } 中插入的日志在我第一次作为参与者 1 加入房间时没有显示。但是我注意到一旦参与者 2 显示了日志确实出现了。所以我想知道如何将 room.on('participantConnected') 代码设置为在第一个参与者加入时执行,而不是第二个。
【问题讨论】:
标签: javascript php twilio twilio-php