"trackPublished" 事件未在 twilio-video 中触发 Javascript SDK

"trackPublished" event not firing in twilio-video Javascript SDk

我有以下代码:

$.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);
    });
}

根据文档,当参与者将媒体发布到房间并且 "trackPublicationFailed" 时会触发 "trackPublished" 事件 发布失败时触发事件。但是 none 的事件似乎在我的案例中触发了。

我可以验证曲目确实已发布到房间,但 "trackPublished" 事件仍未触发。

twilio-video 1.6.1 Chrome: 63 Ubuntu: 16.04

此处为 Twilio 开发人员布道师。

我看到你问了this question on GitHub too。只是想在这里为后代添加答案:

Sorry you've run into this. I believe this behavior is by design. Before connect resolves, the SDK may learn about some set of Tracks that successfully published while connecting (for example, the LocalAudioTrack and LocalVideoTrack you publish in your example). These will be available synchronously on the LocalParticipant's trackPublications collection, and so we don't raise the "trackPublished" events for these. We only raise "trackPublished" events for LocalTracks that have not finished publishing during connect or are published after connect, via publishTrack. I see we failed to mention this in our CHANGELOG.md, though. Sorry about that!

有个updated code sample on GitHub too.