JSFiddle - React, Tailwind, and code Playground

by sanat gupta

HTML

<button id="start">share</button>

JavaScript

async function getScreenshareWithMicrophone() {
  const stream = await navigator.mediaDevices.getDisplayMedia({video: true});
  const audio = await navigator.mediaDevices.getUserMedia({audio: true});
  return new MediaStream([audio.getTracks()[0], stream.getTracks()[0] ]);  
}

document.getElementById('start').onclick = async () => {
  const stream = await getScreenshareWithMicrophone();
  console.log('got', stream.getTracks());
};