'use strict';

// Define navigator.mediaDevices.getUserMedia() for older devices.

/**
 * Constraints to apply to MediaStream.
 * On this codelab, you will be streaming only video (true).
 */
const mediaStreamConstraints = {
  video: true,
};

/** Video element where stream will be placed. */
const localVideo = document.querySelector('video');

/** Handles success by adding the MediaStream to the video element. */
const localMediaStreamSuccessCallback = (mediaStream) => {
  window.localStream = mediaStream;  // Makes stream available to the console.
  video.srcObject = mediaStream;
};

/** Handles error by logging a message to the console with the error message. */
const localMediaStreamErrorCallback = (error) => {
  console.log('navigator.getUserMedia error: ', error);
};

// Initializes media stream.
navigator.mediaDevices.getUserMedia(mediaStreamConstraints)
  .then(localMediaStreamSuccessCallback)
  .catch(localMediaStreamErrorCallback);

'use strict';

/**
 * On this codelab, you will be streaming only video (true).
 * Constraints to apply to MediaStream.
 */
const mediaStreamConstraints = {
  video: true,
};

/** Video element where stream will be placed. */
const localVideo = document.querySelector('video');

/** Handles success by adding the MediaStream to the video element. */
const gotLocalMediaStream = (mediaStream) => {
  video.srcObject = mediaStream;
};

/** Handles error by logging a message to the console with the error message. */
const localMediaStreamError = (error) => {
  console.log('navigator.getUserMedia error: ', error);
};

// Initializes media stream.
navigator.mediaDevices.getUserMedia(mediaStreamConstraints)
  .then(gotLocalMediaStream).catch(localMediaStreamError);

Simplify function names, some comments and additional text.
Simplify function names, some comments and additional text.
