1

I have the following code:

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

According to the documentation, the "trackPublished" event is fired when a participant publishes media to a room and the "trackPublicationFailed" event is fired when the publication fails. However none of the events seem to fire in my case.

I can verify that the tracks were in fact published to the room and still the "trackPublished" event was not fired.

twilio-video at 1.6.1 Chrome: 63 Ubuntu: 16.04

4

1 回答 1

1

Twilio 开发人员布道者在这里。

我看到你也在 GitHub 上问过这个问题。只是想在这里为后代添加答案:

对不起,你遇到了这个。我相信这种行为是设计使然。在连接解析之前,SDK 可能会了解一些在连接时成功发布的 Track(例如,您在示例中发布的 LocalAudioTrack 和 LocalVideoTrack)。这些将在 LocalParticipant 的 trackPublications 集合上同步可用,因此我们不会为这些引发“trackPublished”事件。我们只为在连接期间未完成发布或在连接后通过 publishTrack 发布的 LocalTrack 引发“trackPublished”事件。不过,我看到我们没有在CHANGELOG.md中提及这一点。对于那个很抱歉!

GitHub 上也有更新的代码示例。

于 2018-01-12T00:57:10.333 回答