In a Google's WebRTC tutorial, it has the following example code.
I have two questions for it:
- Why do we need to set window.stream to stream? (What does "stream available to console" mean?)
- If we need to create a URL for stream, why can we set video.src to stream which should be a blob?
Thanks.
function successCallback(stream) {
window.stream = stream; // stream available to console
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
} else {
video.src = stream;
}
}
Old and wrong code.
video.src = stream
is wrong. It should bevideo.srcObject = stream
. It just never runs because all browsers today supportURL
.Instead, use
srcObject
whenever available (supported in both Chrome and Firefox) for better life time handling by browsers:Or use adapter.js and don't worry about it:
Oh, and
window.stream
is just some global variable. Likely used for debugging by the sample author.2013 is old for WebRTC code. I recommend looking at the official WebRTC samples instead.