Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

janus.js - renegotiate with external stream #2604

Merged
merged 10 commits into from
May 6, 2021
18 changes: 10 additions & 8 deletions html/janus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -2196,6 +2196,10 @@ function Janus(gatewayCallbacks) {
if(media.addData) {
media.data = true;
}
// Reset external stream flag when replacing MediaStream with user media
if(config.streamExternal) {
config.streamExternal = false;
}
kmeyerhofer marked this conversation as resolved.
Show resolved Hide resolved
}
// If we're updating and keeping all tracks, let's skip the getUserMedia part
if((isAudioSendEnabled(media) && media.keepAudio) &&
Expand All @@ -2206,7 +2210,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))) {
kmeyerhofer marked this conversation as resolved.
Show resolved Hide resolved
if(media.removeAudio || media.replaceAudio) {
if(config.myStream && config.myStream.getAudioTracks() && config.myStream.getAudioTracks().length) {
var at = config.myStream.getAudioTracks()[0];
Expand Down Expand Up @@ -2264,12 +2268,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;
Expand Down