Hi guys,
I’ve just made a start on the Graceful asynchronous programming article and wanted to clarify something.
In the first example given, a video chat app is discussed and an async code block is detailed which uses the method ‘getUserMedia()’. This method, as I understand, asks for video and audio and once both values are ‘true’ continues with the code. I’m assuming that if one or both are ‘false’ then the promise will fail and the catch() method will run.
I’m wondering since initially, the video and audio properties will have a value of ‘false’, why doesn’t the promise return as fail and the code jump straight to catch()? How long does the browser wait for the values of video and audio to change to ‘true’ and how does it know to do this? I skimmed through the reference page for the getUserMedia() method but couldn’t find an answer.
The code from the example I’m referencing is below. More specifically, I’m asking about line 3.
I’m not very familiar with Promises and the terminology so if what I’m asking isn’t clear, please let me know and I’ll try to rephrase the question.
Also, I read this paragraph a few times but it doesn’t make any sense to me.
The important thing here is that the
getUserMedia()
call returns almost immediately, even if the camera stream hasn’t been obtained yet. Even if thehandleCallButton()
function has already returned to the code that called it, whengetUserMedia()
has finished working, it calls the handler you provide. As long as the app doesn’t assume that streaming has begun, it can just keep on running.
Any help would be appreciated.
Thanks!
Regards,
Jared