Skip to content

Remote stream 오디오 사이즈 확인

Heedong Kim edited this page Feb 13, 2022 · 1 revision
function getAudioLevel() {
    Object.keys(participants).forEach(userId => {
        if (userId !== '<본인 user Id') {
            let participant = participants[userId];
            participant.rtcPeer.peerConnection.getStats(null).then(stats => {
                stats.forEach(report => {
                    if (report.type === "inbound-rtp" && report.kind === "audio") {
                        console.log("userId " + userId + " audio level : " + report.audioLevel);
                        if (report.audioLevel > 0.1) {
                            // 수치는 알아서 조절
                            // add business logic
                            alert("소음 발생");
                        }
                            
                    }
                });
            });
        }
    });
}

window.setInterval(getAudioLevel, 1000); // interval 값 알아서 조절
Clone this wiki locally