Skip to content

Commit

Permalink
Merge pull request #356 from ant-media/fix-noise-suppression
Browse files Browse the repository at this point in the history
Fix calling the applyConstraints(noiseSuppresion) for audio mutes the audio in player
  • Loading branch information
mustafaboleken committed Apr 28, 2023
2 parents 53985fa + 07ff0fd commit 6c658d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 9 additions & 3 deletions src/main/webapp/js/media_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -915,16 +915,19 @@ export class MediaManager {
}

if (typeof deviceId != "undefined") {
//Update the media constraints
if (this.mediaConstraints.audio !== true)
this.mediaConstraints.audio.deviceId = deviceId;
else
this.mediaConstraints.audio = {"deviceId": deviceId};

//to change only audio track set video false otherwise issue #3826 occurs on Android
let tempMediaConstraints = {"video": false, "audio": {"deviceId": deviceId}};
this.setAudioInputSource(streamId, tempMediaConstraints, null, true, deviceId);
return this.setAudioInputSource(streamId, tempMediaConstraints, null, deviceId);
} else {
this.setAudioInputSource(streamId, this.mediaConstraints, null, true, deviceId);
return new Promise((resolve, reject) => {
reject("There is no device id for audio input source");
});
}
}

Expand Down Expand Up @@ -1337,7 +1340,10 @@ export class MediaManager {

if (constraints.audio !== undefined) {
//just give the audio constraints not to get video stream
promise = this.setAudioInputSource(streamId, {audio: this.mediaConstraints.audio}, null);
//we dont call applyContrains for audio because it does not work. I think this is due to gainStream things. This is why we call getUserMedia again

//use the publishStreamId because we don't have streamId in the parameter anymore
promise = this.setAudioInputSource(this.publishStreamId, {audio: this.mediaConstraints.audio}, null);
}
return promise;
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/webapp/js/webrtc_adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ export class WebRTCAdaptor {
}

switchAudioInputSource(streamId, deviceId) {
this.mediaManager.switchAudioInputSource(streamId, deviceId);
return this.mediaManager.switchAudioInputSource(streamId, deviceId);
}

setVolumeLevel(volumeLevel) {
Expand All @@ -1638,7 +1638,7 @@ export class WebRTCAdaptor {
}

applyConstraints(constraints) {
this.mediaManager.applyConstraints(constraints)
return this.mediaManager.applyConstraints(constraints)
};

changeBandwidth(bandwidth, streamId) {
Expand All @@ -1664,11 +1664,6 @@ export class WebRTCAdaptor {
closeStream() {
return this.mediaManager.closeStream();
};


applyConstraints(newConstaints) {
this.mediaManager.applyConstraints(newConstaints);
}
}


Expand Down
8 changes: 7 additions & 1 deletion src/main/webapp/samples/publish_webrtc.html
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,13 @@
break;
}
}
webRTCAdaptor.applyConstraints(constraint);
webRTCAdaptor.applyConstraints(constraint).then((value) => {
console.log("Applied audio constraints: " + JSON.stringify(constraint));
})
.catch((error) => {
console.error("Audio Constraints could not be applied" + JSON.stringify(constraint));
console.error(error);
});
}

var websocketURL = getWebSocketURL(location, rtmpForward);
Expand Down

0 comments on commit 6c658d4

Please sign in to comment.