屏幕共享:接收端的流不更新

问题描述 投票:0回答:1

我已经实现了屏幕共享选项。 当我退出屏幕共享并更改曲目时,流仅在发送者站点上更新。我如何更新接收者站点上的流

这是我的 addStream 函数

this.videoHeight = 200
        if(this.$store.rtcmConnection.streamEvents[this.screenId]){
            const test = await navigator.mediaDevices.getDisplayMedia();
            const track = this.$store.rtcmConnection.streamEvents[this.screenId].stream.getTracks()[0]
            this.userIds.forEach(e => {
                Object.keys(this.$store.rtcmConnection.streamEvents).forEach((streamid) => {
                    const event = this.$store.rtcmConnection.streamEvents[streamid];
                    if(typeof event !== 'function'){
                    if (event.userid == e){
                        if(event.stream.isVideo)
                        {
                           
                            event.stream.removeTrack(track)
                            event.stream.addTrack(test.getTracks()[0])
                        }
                        }
                    }
                });
            })
        }else{
        this.$store.rtcmConnection.addStream({
            screen: true,
            oneway: true,
            }) 
        }

当我使用replaceTrack时,它似乎可以工作,但他抛出了一个类型错误,表明轨道偏离了不同类型

if (this.$store.rtcmConnection.streamEvents[this.screenId]) {
            const test = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: false });
            const streamTrack = test.getVideoTracks()[0]
            const track = this.$store.rtcmConnection.streamEvents[this.screenId].stream.getVideoTracks()[0]
            const event = this.$store.rtcmConnection.streamEvents[this.screenId];
            if (event.stream.isVideo) {
                this.userIds.forEach(async e => {
                    const peerContainer = this.$store.rtcmConnection.peers[e]
                    if (typeof peerContainer != 'undefined') {
                        const connection = peerContainer.peer
                        connection.getSenders().forEach(sender => {
                            sender.replaceTrack(streamTrack, event.stream)
                        })

                    }

                })

                event.stream.removeTrack(track)
                event.stream.addTrack(streamTrack)
            }

        } else {
            this.$store.rtcmConnection.addStream({
                screen: true,
                oneway: true,
            })
        }
javascript webrtc rtcmulticonnection
1个回答
0
投票

我忘了检查发件人

if(sender.track.kind == 'video')
© www.soinside.com 2019 - 2024. All rights reserved.