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

              
                <!DOCTYPE html>
<html>

<head>
  <title>Quickstart JS</title>
  <meta charset="UTF-8" />
</head>

<body>
  <header>
    <img class="logo" src="https://www.100ms.live/assets/logo.svg" />
    <button id="leave-btn" class="btn-danger hide">Leave Room</button>
  </header>
  <form id="join">
    <h2>Join Room</h2>
    <div class="input-container">
      <input id="name" type="text" name="username" placeholder="Your name" />
    </div>
    <div class="input-container">
      <input id="token" type="text" name="token" placeholder="Auth token" />
    </div>
    <button type="button" class="btn-primary" id="join-btn">
      Join
    </button>
  </form>

  <div id="conference" class="conference-section hide">
    <h2>Conference</h2>

    <div id="peers-container"></div>
  </div>

  <div id="controls" class="control-bar hide">
    <button id="mute-aud" class="btn-control">Mute</button>
    <button id="mute-vid" class="btn-control">Hide</button>
  </div>
</body>

</html>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  background-color: #263238;
  color: white;
}

h1,
h2,
h3,
h4,
h5 {
  font-weight: normal;
}

header {
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

form {
  max-width: 450px;
  margin: 30px auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 20px;
}

input {
  display: block;
  width: 100%;
  border-radius: 8px;
  border: 2px solid transparent;
  height: 34px;
  padding: 5px;
  background: #37474f;
  color: inherit;
  font-family: inherit;
}

input::placeholder {
  color: #aaa;
}

.input-container {
  margin-bottom: 20px;
}

.btn-primary {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 14px;
  background-color: #1565c0;
  color: white;
  font-family: inherit;
  font-size: 14px;
}

form h2,
.conference-section h2 {
  margin-bottom: 20px;
}

.btn-danger {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 14px;
  background-color: #f44336;
  color: white;
  font-family: inherit;
  font-size: 14px;
}

.conference-section {
  padding: 20px 30px;
  max-width: 960px;
  margin: 0 auto;
}

.conference-section h2 {
  text-align: center;
  font-size: 32px;
  padding-bottom: 10px;
  border-bottom: 1px solid #546e7a;
}

#peers-container {
  display: grid;
  grid-template-columns: repeat(3, minmax(min-content, 1fr));
  place-items: center;
  grid-gap: 10px;
}

.peer-video {
  height: 250px;
  width: 250px;
  border-radius: 40%;
  object-fit: cover;
  margin-bottom: 10px;
}

.local.peer-video {
  transform: scaleX(-1);
}

.peer-name {
  font-size: 14px;
  text-align: center;
}

.peer-container {
  padding: 10px;
}

.control-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  width: 100%;
  padding: 15px;
  justify-content: center;
  z-index: 10;
}

.control-bar > *:not(:first-child) {
  margin-left: 8px;
}

.btn-control {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border: 2px solid #37474f;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  text-align: center;
  background-color: #607d8b;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
  color: white;
}

.hide {
  display: none;
}

              
            
!

JS

              
                import {
  HMSReactiveStore,
  selectIsConnectedToRoom,
  selectIsLocalAudioEnabled,
  selectIsLocalVideoEnabled,
  selectPeers
} from "https://cdn.skypack.dev/@100mslive/hms-video-store";

// Initialize HMS Store
const hmsManager = new HMSReactiveStore();
hmsManager.triggerOnSubscribe();
const hmsStore = hmsManager.getStore();
const hmsActions = hmsManager.getHMSActions();

// HTML elements
const form = document.getElementById("join");
const joinBtn = document.getElementById("join-btn");
const conference = document.getElementById("conference");
const peersContainer = document.getElementById("peers-container");
const leaveBtn = document.getElementById("leave-btn");
const muteAud = document.getElementById("mute-aud");
const muteVid = document.getElementById("mute-vid");
const controls = document.getElementById("controls");

// Joining the room
joinBtn.addEventListener("click", () => {
  hmsActions.join({
    userName: document.getElementById("name").value,
    authToken: document.getElementById("token").value
  });
});

// Leaving the room
function leaveRoom() {
  hmsActions.leave();
}

// Cleanup if user refreshes the tab or navigates away
window.onunload = window.onbeforeunload = leaveRoom;
leaveBtn.addEventListener("click", leaveRoom);

// helper function to create html elements
function h(tag, attrs = {}, ...children) {
  const newElement = document.createElement(tag);

  Object.keys(attrs).forEach((key) => {
    newElement.setAttribute(key, attrs[key]);
  });

  children.forEach((child) => {
    newElement.append(child);
  });

  return newElement;
}

// display a tile for each peer in the peer list
function renderPeers(peers) {
  peersContainer.innerHTML = "";

  if (!peers) {
    // this allows us to make peer list an optional argument
    peers = hmsStore.getState(selectPeers);
  }

  peers.forEach((peer) => {
    if (peer.videoTrack) {
      const video = h("video", {
        class: "peer-video" + (peer.isLocal ? " local" : ""),
        autoplay: true, // if video doesn't play we'll see a blank tile
        muted: true,
        playsinline: true
      });

      // this method takes a track ID and attaches that video track to a given
      // <video> element
      hmsActions.attachVideo(peer.videoTrack, video);

      const peerContainer = h(
        "div",
        {
          class: "peer-container"
        },
        video,
        h(
          "div",
          {
            class: "peer-name"
          },
          peer.name + (peer.isLocal ? " (You)" : "")
        )
      );

      peersContainer.append(peerContainer);
    }
  });
}

function onConnection(isConnected) {
  if (isConnected) {
    form.classList.add("hide");
    conference.classList.remove("hide");
    leaveBtn.classList.remove("hide");
    controls.classList.remove("hide");
  } else {
    form.classList.remove("hide");
    conference.classList.add("hide");
    leaveBtn.classList.add("hide");
    controls.classList.add("hide");
  }
}

// reactive state - renderPeers is called whenever there is a change in the peer-list
hmsStore.subscribe(renderPeers, selectPeers);

// listen to the connection state
hmsStore.subscribe(onConnection, selectIsConnectedToRoom);

muteAud.addEventListener("click", () => {
  const audioEnabled = !hmsStore.getState(selectIsLocalAudioEnabled);

  hmsActions.setLocalAudioEnabled(audioEnabled);

  muteAud.textContent = audioEnabled ? "Mute" : "Unmute";
});

muteVid.addEventListener("click", () => {
  const videoEnabled = !hmsStore.getState(selectIsLocalVideoEnabled);

  hmsActions.setLocalVideoEnabled(videoEnabled);

  muteVid.textContent = videoEnabled ? "Hide" : "Unhide";

  // Re-render video tile
  renderPeers();
});

              
            
!
999px

Console