-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
janus.js - renegotiate with external stream #2604
Conversation
Thanks for your contribution, @kmeyerhofer! Please make sure you sign our CLA, as it's a required step before we can merge this. |
CLA signed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! But I feel this needlessly makes things more complicated than they should. My feeling is that this could work just as easily by reusing the existing properties: if media
contains replaceAudio
and/or replaceVideo
and stream
contains a (new) external MediaStream, then replace the tracks (audio and/or video) with the ones from the new stream and renegotiate. Or am I missing something?
Don't worry too much about what the docs say: for the JS part, most was written at the very beginning, and they may not be exactly up-to-date. The fact media
is ignored, for instance, is not true, since media direction is taken into account even when using external streams.
Thanks for your review Lorenzo. I agree with your concern that these changes make things more complicated. Since you've clarified that using |
Based on your feedback @lminiero, I have simplified the previous changes to utilize the With the added changes, a // Assume Janus is correctly initialized
var canvas = document.getElementById('canvas');
var stream = canvas.captureStream();
janusPlugin.createOffer({
stream: stream,
media: {
replaceAudio: true,
replaceVideo: true,
},
simulcast: false,
simulcast2: false,
success: (jsep) => {
janusPlugin.send({ message: { request: "configure", audio: true, video: true}, jsep });
},
error: (error) => { Janus.error('error', error); },
}); |
Thanks! I'll have a look at the new changes and make some tests when I get the chance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few notes inline.
@kmeyerhofer can this be merged? We never use external streams ourselves, so if you tested this and it works for you, it's good enough for me! |
@lminiero Yes this is ready to be merged, thanks! |
Merging then, thanks again 👍 |
This PR adds the ability for an existing PeerConnection to
replaceVideo
with an externalstream
and back again through thecreateOffer
renegotiation.The issue this PR solves is described in this Google Group post https://groups.google.com/g/meetecho-janus/c/Ucz-U3OORHM/m/mo6lXkdjAwAJ
To summarize the issue, a renegotiation
createOffer
sent with a canvasMediaStream
(external stream) does not replace the track of the existing PeerConnection.This PR allows the
stream
property sent in acreateOffer
parameter to be an object which can include thereplaceVideo
andexternalStream
properties, similar to themedia
property. The existing stream property behavior has not been modified.Here is a working example:
Using
createOffer
in this manner replaces a user media (video camera) stream with an externalMediaStream
and an externalMediaStream
with another externalMediaStream
.To renegotiate the same peer connection from an external
MediaStream
back to user media (video camera) utilizes the samemedia
property as before. Here is a working example:In summary this change allows a PeerConnection renegotiation to replace the video in the following three conditions:
Implementation decision making
I was a bit unsure of design implications regarding this note in the
createOffer
/createAnswer
documentation (emphasis added):This is why I chose to modify the
stream
object instead of using the already available{ media: { video: true, replaceVideo: true } }
property.