1

我在这个 repo 的主分支上使用 v 计数twiliohttps://github.com/twilio/video-quickstart-jstwilio-video必须 显示选择的媒体并将设备推入其中但是当我尝试更新VideoDevice时我得到了一个错误beta-2

updateVideoDevice error TypeError: track must be a LocalAudioTrack, LocalVideoTrack, LocalDataTrack, or MediaStreamTrack
at Object.INVALID_TYPE (index.js:30952)
at Object.validateLocalTrack (index.js:31469)
at LocalParticipant.unpublishTrack (index.js:17047)
at index.js:17096
at Array.reduce (<anonymous>)
at LocalParticipant.unpublishTracks (index.js:17095)
at index.js:36056

我的updateVideoDevice功能如下

function updateVideoDevice(event) {
const select = event.target;
const localParticipant = room.localParticipant;
if (select.value !== '') {
    Video.createLocalVideoTrack({
        deviceId: { exact: select.value }
    }).then(function(localVideoTrack) {
        const tracks = Array.from(localParticipant.videoTracks.values());
        localParticipant.unpublishTracks(tracks);
        log(localParticipant.identity + " removed track: " + tracks[0].kind);
        detachTracks(tracks);

        localParticipant.publishTrack(localVideoTrack);
        log(localParticipant.identity + " added track: " + localVideoTrack.kind);
        const previewContainer = document.getElementById('local-media');
        attachTracks([localVideoTrack], previewContainer);
    })
    .catch(error => {
        console.error('updateVideoDevice error' ,error);
    });
}
}

谁能解释我做错了什么?

4

1 回答 1

5

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

这看起来是 Twilio Video JS v1 和 v2 之间的重大变化。在 v2 文档中,调用localParticipant.videoTracks返回 a Mapof <Track.SID, LocalVideoTrackPublication>. 调用.values()该映射会返回 s 的迭代器,LocalVideoTrackPublication然后使用 s 将其转换为数组Array.from

问题是您随后将导致错误的LocalVideoTrackPublications数组传递给该数组,因为需要一个 s 数组而不是s 数组。localParticipant.unpublishTracks(tracks);unpublishTracksLocalTrackLocalVideoTrackPublication

您可以通过映射出版物并返回track属性来解决此问题:

const tracks = Array.from(localParticipant.videoTracks.values())
                 .map(publication => publication.track);

让我知道这是否有帮助。

于 2018-10-04T06:25:54.257 回答