我有以下代码:
$.getJSON('/video/getToken', function (data, status) {
identity = data.identity;
navigator.mediaDevices.getUserMedia({
audio: true,
video: {width: 320, height: 240}
})
.then(function (mediaStream) {
console.log("Obtained " + mediaStream.getTracks() +" from local and joining room" + roomName);
var connectOptions = {
name: roomName,
logLevel: 'off',
tracks: mediaStream.getTracks(),
preferredVideoCodecs: ['VP9', 'VP8']
};
return Video.connect(data.token, connectOptions);
})
.then(roomJoined)
.catch(function (error) {
log('Could not connect to Twilio: ' + error.message);
});
});
function roomJoined(room) {
const localParticipant = room.localParticipant;
localParticipant.on('trackPublicationFailed', function(error, localTrack){
console.log('Failed to publish track %s to room "%s": %s', localTrack,roomName, error.message);
});
localParticipant.on('trackPublished', function(localTrackPublication){
console.log('Succesfully published track %s with name %s to room "%s"', localTrackPublication.trackSid, localTrackPublication.trackName, roomName);
});
}
根据文档,“trackPublished”事件是在参与者将媒体发布到房间并且“trackPublished失败”时触发的
发布失败时激发事件。然而,在我的情况下,似乎没有发生任何事件。
我可以确认这些曲目实际上已发布到房间中,但“trackPublished”事件仍未触发。
twilio视频1.6.1
铬:63
Ubuntu:16.04