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

Auto Save

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

              
                <!--
/*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <title>IVS Real-Time: Simple Playback Sample Code</title>

  <script src="https://web-broadcast.live-video.net/1.26.0/amazon-ivs-web-broadcast.js"></script>
</head>

<body>
  <div>
    <!-- Enter the participant token for the subscriber here.
         A publisher must already be connected to the stage 
         for playback to work. -->
    <form>
      <input placeholder="Token" />
      <button type="submit">Load</button>
    </form>

    <!-- Video will play muted to prevent autoplay from being blocked.
         Use the button below to unmute. -->
    <video playsinline muted autoplay></video>
  </div>

  <div>
    <button id="mute-toggle">Unmute</button>
  </div>

  <div>
    Time to Video: <span></span> ms
  </div>
</body>

</html>
              
            
!

CSS

              
                /*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */

video {
  width: 100%;
  max-width: 600px;
}

              
            
!

JS

              
                /*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */

(function () {
  const {
    Stage,
    StageEvents,
    SubscribeType,
    JitterBufferMinDelay
  } = IVSBroadcastClient;

  const formEl = document.querySelector("form");
  const inputEl = document.querySelector("input");
  const videoEl = document.querySelector("video");
  const spanEl = document.querySelector("span");
  const muteButton = document.getElementById("mute-toggle");
  let joinAttemptTimestamp = null;
  let stage = null;

  muteButton.addEventListener("click", () => {
    if (videoEl.muted) {
      videoEl.muted = false;
      muteButton.textContent = "Mute";
    } else {
      videoEl.muted = true;
      muteButton.textContent = "Unmute";
    }
  });

  videoEl.addEventListener("loadeddata", (e) => {
    const ttv = performance.now() - joinAttemptTimestamp;
    spanEl.textContent = ttv.toFixed(2);
  });

  formEl.addEventListener("submit", async (e) => {
    e.preventDefault();

    const strategy = {
      // Increases the jitter buffer to improve playback stability.
      // See "Changing Subscriber Jitter Buffer MinDelay":
      // https://docs.aws.amazon.com/ivs/latest/RealTimeUserGuide/real-time-streaming-optimization.html#real-time-streaming-configurations
      subscribeConfiguration: (participant) => {
        return {
          jitterBuffer: {
            minDelay: JitterBufferMinDelay.MEDIUM
          }
        };
      },

      stageStreamsToPublish() {
        return [];
      },

      shouldPublishParticipant() {
        return false;
      },

      shouldSubscribeToParticipant(participant) {
        return SubscribeType.AUDIO_VIDEO;
      }
    };

    if (stage) {
      await stage.leave();
    }

    const token = inputEl.value;
    stage = new Stage(token, strategy);

    stage.on(
      StageEvents.STAGE_PARTICIPANT_STREAMS_ADDED,
      (participant, streams) => {
        videoEl.srcObject = new MediaStream();
        streams.forEach((stream) => {
          videoEl.srcObject.addTrack(stream.mediaStreamTrack);
        });
      }
    );

    try {
      joinAttemptTimestamp = performance.now();
      await stage.join();
    } catch (error) {
      console.log(error);
    }
  });
})();

              
            
!
999px

Console