我正在测试twillio功能。后端(发送令牌,访问权限)工作正常。在前端部分,我从没有声音的远程参与者那里得到视频。我们可以看到对方。我听不到他的声音,他也听不到我的声音。怎么修呢?我想要有声音,我想选择将麦克风静音/取消静音,以便远程参与者听不到我的声音。如果您对我的代码有任何其他建议,请告诉我。
这是我的html的一部分:
<div class="container" id="conversation">
<div>
<video id="localVideo" ></video>
<video id="patientVideo"></video>
<div class="buttons">
<span>
<a href="{% url 'calendar' %}?day={{ request.GET.day }}">
<img class="btn" id="call" src="{% static 'images/conversation/Finish-phone-call.png' %}"
alt="call"/></a>
</span>
<span>
<img class="btn" id="mute" src="{% static 'images/conversation/Icon-microphone-mute-01.png' %}"
alt="mute"/>
<img class="btn" id="unmute" src="{% static 'images/conversation/Icon-microphone-unmute-01.png' %}"
alt="mute"/>
</span>
</div>
</div>
这是我的javascript的一部分。有用。我可以连接到房间,我可以在参与者之间分享视频。:
var local_participant;
var videoRoom;
$("#call").click(function () {
sendNotification("Call canceled");
if(videoRoom) {
videoRoom.disconnect();
}
});
$("#mute").click(function () {
$(this).hide("fast", function () {
$("#unmute").show();
local_participant.audioTracks.forEach(function (audioTrack) {
audioTrack.enable();
});
});
});
$("#unmute").click(function () {
$(this).hide(function () {
$("#mute").show();
});
local_participant.audioTracks.forEach(function (audioTrack) {
audioTrack.disable();
});
});
Twilio.Video.connect(doctor_token, {name: room_name}).then(function (room) {
videoRoom = room;
Twilio.Video.createLocalVideoTrack({audio: true}).then(function (localTrack) {
localTrack.attach("#localVideo");
room.localParticipant.addTrack(localTrack);
local_participant = room.localParticipant;
});
room.on('participantConnected', function (participant) {
console.log('Participant connected: ' + participant.identity);
});
room.on('participantDisconnected', function (participant) {
console.log('Participant disconnected: ' + participant.identity);
});
room.on('trackAdded', function (track, participant) {
console.log(participant.identity + " added track: " + track.kind);
track.attach("#patientVideo");
});
room.on('trackRemoved', function (track, participant) {
console.log(participant.identity + " removed track: " + track.kind);
track.detach("#patientVideo");
});
});
答案 0 :(得分:2)
Twilio开发者传道者在这里。
在您的代码中,您可以通过以下方式获取本地用户的视频跟踪:
Twilio.Video.createLocalVideoTrack({audio: true})
但是createLocalVideoTrack
不会创建音轨。相反,您应该致电createLocalTracks
:
Twilio.Video.createLocalTracks()
default options for createLocalTracks
为{ video: true, audio: true }
,因此应该是您所需要的一切。承诺使用LocalTracks
数组解析,因此您还需要更新回调代码。
Twilio.Video.createLocalTracks().then(function (localTracks) {
localTracks.forEach(function(localTrack) {
localTrack.attach("#localVideo");
room.localParticipant.addTrack(localTrack);
})
local_participant = room.localParticipant;
});
如果有帮助,请告诉我!