清理 getDisplayMedia 演示

作者: jabcreations创建于 2023年6月30日更新于 2023年10月23日

Save the following as index.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>getDisplayMedia demo</title>
<style>
* {border: 0; margin: 0; padding: 0;}
a {color: #fff; text-decoration: none;}
a:focus, a:hover {text-decoration: underline;}
body, html {background-color: #000; color: #ccc; font-size: 1em; text-align: center;}
button, input, select, textarea {background-color: #000; border: 1px solid #777; color: #ccc; padding: 0 2px;}
button:focus, button:hover, input:focus, input:hover, select:focus, select:hover, textarea:focus, textarea:hover {border-color: #fff;}
label {border: 1px dotted #777; padding: 0 2px; margin-left: 4px;}
label:hover {border-style: solid;}
p {margin: 16px;}
video {border: 1px solid #777; border-radius: 4px; width: 40%;}
.flex {align-content: center; display: flex; justify-content: center;}
</style>
<script type="application/ZZTERM4ZZ">
//<![CDATA[
function id_(id) {return ((document.getElementById(id)) ? document.getElementById(id) : false);}

function get_display_media_init()
{
 var button = id_('btn-test-getDisplayMedia'),
 video = document.querySelector('video');


 button.setAttribute('disabled', 'true');
 
 get_display_media_invoke(function(screen)
 {
  add_stream_stop_listener(screen, function() {location.reload();});
  
  video.srcObject = screen;

  if (typeof screen.getTracks == 'function' && screen.getTracks.length > 0 && typeof screen.getTracks()[0].getCapabilities == 'function')
  {
   var _capabilities = screen.getTracks()[0].getCapabilities();
   id_('capabilities').value = 'capabilities:\n\n' + JSON.stringify(_capabilities, null, '\t');
   id_('capabilities').style.display = '';

   var _settings = screen.getTracks()[0].getSettings();
   id_('settings').value = 'settings:\n\n' + JSON.stringify(_settings, null, '\t');
   id_('settings').style.display = '';
  }
 },


 function(e)
 {
  button.disabled = false;

  var error = {
   name: e.name || 'UnKnown',
   message:
…

内容来源: muaz-khan/WebRTC-Experiment