How to fix echo?

Muaz Khan edited this page Aug 25, 2014 · 1 revision

First of all, don't forget to check slides: Echo in WebRTC

Here is how to fix echo with mute/unmute:

function afterEach(setTimeoutInteval, numberOfTimes, callback, startedTimes) {
    startedTimes = (startedTimes || 0) + 1;
    if (startedTimes >= numberOfTimes) return;

    setTimeout(function() {
        callback();
        afterEach(setTimeoutInteval, numberOfTimes, callback, startedTimes);
    }, setTimeoutInteval);
}

connection.onunmute = function(event) {
    // event.isAudio == audio-only-stream
    // event.audio == has audio tracks

    if (event.isAudio || event.session.audio) {
        // set volume=0
        event.mediaElement.volume = 0;

        // steadily increase volume
        afterEach(200, 5, function() {
            event.mediaElement.volume += .20;
        });
    }
};