diff --git a/html/janus.js b/html/janus.js
index 66ca06cd5b..5f2a1b7e88 100644
--- a/html/janus.js
+++ b/html/janus.js
@@ -1741,7 +1741,7 @@ function Janus(gatewayCallbacks) {
}
// We're now capturing the new stream: check if we're updating or if it's a new thing
var addTracks = false;
- if(!config.myStream || !media.update || config.streamExternal) {
+ if(!config.myStream || !media.update || (config.streamExternal && !media.replaceAudio && !media.replaceVideo)) {
config.myStream = stream;
addTracks = true;
} else {
@@ -2206,7 +2206,7 @@ function Janus(gatewayCallbacks) {
}
}
// If we're updating, check if we need to remove/replace one of the tracks
- if(media.update && !config.streamExternal) {
+ if(media.update && (!config.streamExternal || (config.streamExternal && (media.replaceAudio || media.replaceVideo)))) {
if(media.removeAudio || media.replaceAudio) {
if(config.myStream && config.myStream.getAudioTracks() && config.myStream.getAudioTracks().length) {
var at = config.myStream.getAudioTracks()[0];
@@ -2264,12 +2264,10 @@ function Janus(gatewayCallbacks) {
Janus.log("MediaStream provided by the application");
Janus.debug(stream);
// If this is an update, let's check if we need to release the previous stream
- if(media.update) {
- if(config.myStream && config.myStream !== callbacks.stream && !config.streamExternal) {
- // We're replacing a stream we captured ourselves with an external one
- Janus.stopAllTracks(config.myStream);
- config.myStream = null;
- }
+ if(media.update && config.myStream && config.myStream !== callbacks.stream && !config.streamExternal && !media.replaceAudio && !media.replaceVideo) {
+ // We're replacing a stream we captured ourselves with an external one
+ Janus.stopAllTracks(config.myStream);
+ config.myStream = null;
}
// Skip the getUserMedia part
config.streamExternal = true;