网站在线客服系统实时语音视频聊天实战开发,判断MediaStream对象是视频流还是音频流

当我们接收到音视频流MediaStream对象以后,我们需要知道这是视频还是音频

才能去以正确的标签展示,可以看下面的判断

                    console.log("call stream",remoteStream);
                    var videoTracks = remoteStream.getVideoTracks();
                    var audioTracks = remoteStream.getAudioTracks();
                    //视频流
                    if (videoTracks.length > 0) {
                        console.log("客服视频接待");
                        var remoteVideo = document.getElementById("remoteVideo");
                        remoteVideo.srcObject = remoteStream;
                        remoteVideo.play();
                        _this.peerjs.remoteVideoStream=remoteStream;
                    }else if (audioTracks.length > 0) {
                        //音频流
                        console.log("客服音频接待");
                        var remoteAudio = document.getElementById("remoteAudio");
                        remoteAudio.srcObject = remoteStream;
                        remoteAudio.play();
                        _this.peerjs.remoteAudioStream=remoteStream;
                    }

 

posted @ 2023-02-12 23:37  唯一客服系统开发笔记  阅读(45)  评论(0编辑  收藏  举报