Requesting User-Media Permissions
Before we get into the heavy-duty WebRTC code, let’s start off by handling an essential task that’s also pretty awesome and fun: requesting permission for your app to access a user’s camera and then displaying the camera’s live video in the HTML’s self video element.
Start by declaring a new variable called $self near the top of the main.js file. Note the variable name is prefixed with a dollar sign. While self would be a more convenient name, browsers have a built-in self property on the global window object.[23] So we will go with $self and assign it an object literal with a mediaConstraints property:
| const $self = { |
| mediaConstraints: { audio: false, video: true }, |
|
Get Programming WebRTC now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.