Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrapper">
  <div class="sidebar">
    <div id="notification"></div>
    <table class="controls">
      <tr class="pan">
        <td for="rangeZoom">Pan: </td>
        <td><input type="number" id="rangePan" /></td>
      </tr>
      <tr class="tilt">
        <td for="rangeZoom">Tilt: </td>
        <td> <input type="number" id="rangeTilt" /></td>
      </tr>
      <tr class="zoom">
        <td for="rangeZoom">Zoom: </td>
        <td><input type="number" id="rangeZoom" /></td>
      </tr>
    </table>
  </div>

  <div class="content">
    <video id="video" autoplay>
      Your browser does not support the video tag.
    </video>
  </div>
</div>
              
            
!

CSS

              
                body {
  margin: 0;
}

.wrapper {
  position: absolute;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: max-content 1fr;

  .sidebar {
    display: grid;
    grid-template-rows: 20px 1fr;

    #notification {
      background-color: #ff964f;
      height: 30px;
      display: flex;
      justify-content: center;
      line-height: 30px;
      display: none;
    }

    .controls {
      padding: 15px;
    }
  }

  .content {
    position: relative;
    height: 100%;
    width: 100%;

    video {
      right: 0;
      position: absolute;
      height: 100vh;
    }
  }
}

              
            
!

JS

              
                const supports = navigator.mediaDevices.getSupportedConstraints();
if (supports.pan && supports.tilt && supports.zoom) {
  enablePTZ();
} else {
  const message = `You don't have a camera that supports pan, tilt and zoom`;
  const messageBox = document.querySelector("#notification");
  messageBox.innerText = message;
  console.error(message);
}

async function enablePTZ() {
  try {
    const opts = { video: { pan: true, tilt: true, zoom: true } };
    const stream = await navigator.mediaDevices.getUserMedia(opts);

    const [videoTrack] = stream.getVideoTracks();
    const capabilities = videoTrack.getCapabilities();
    const settings = videoTrack.getSettings();

    if ("pan" in settings) {
      enablePan(capabilities, settings, videoTrack);
    }

    if ("zoom" in settings) {
      enableZoom(capabilities, settings, videoTrack);
    }

    if ("tilt" in settings) {
      enableTilt(capabilities, settings, videoTrack);
    }

    document.querySelector("#video").srcObject = stream;
    return stream;
  } catch (error) {
    console.log(error);
    const message = `You've either denied the prompt or matching media isn't available`;
    const messageBox = document.querySelector("#notification");
    messageBox.innerText = message;
    console.error(message);
  }
}

function enablePan(capabilities, settings, videoTrack) {
  const input = document.getElementById("rangePan");
  console.log(capabilities);
  console.log(videoTrack);
  input.min = capabilities.pan.min;
  input.max = capabilities.pan.max;
  input.step = capabilities.pan.step;
  input.value = settings.pan;

  input.addEventListener("input", async () => {
    const opts = { advanced: [{ pan: input.value || input.min }] };
    await videoTrack.applyConstraints(opts);
  });
}

function enableZoom(capabilities, settings, videoTrack) {
  const input = document.getElementById("rangeZoom");
  input.min = capabilities.zoom.min;
  input.max = capabilities.zoom.max;
  input.step = capabilities.zoom.step;
  input.value = settings.zoom;

  input.addEventListener("input", async () => {
    const opts = { advanced: [{ zoom: input.value || input.min }] };
    await videoTrack.applyConstraints(opts);
  });
}

function enableTilt(capabilities, settings, videoTrack) {
  const input = document.getElementById("rangeTilt");
  input.min = capabilities.tilt.min;
  input.max = capabilities.tilt.max;
  input.step = capabilities.tilt.step;
  input.value = settings.tilt;

  input.addEventListener("input", async () => {
    const opts = { advanced: [{ tilt: input.value || input.min }] };
    await videoTrack.applyConstraints(opts);
  });
}

              
            
!
999px

Console