css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>
<head>
	<title>WebRTC with SkylinkJS</title>
  
	<script src="//cdn.temasys.io/skylink/skylinkjs/0.6.x/skylink.complete.js"></script>
</head>
<body>

  <header>
    <a href="https://temasys.github.io" target="_blank">SkylinkJS on Github</a>
    You're in a private room. Please click &quot;Start&quot;, allow access to your microphone and camera and <a href="https://codepen.io/temasys/pen/GogabE" target="_blank">click here</a> to open this page in a new tab. You're joining yourself for a fun call ;)
  </header>
  
  <p id="status">Loading room information...</p>
 
  <div id="start">
    <button  onclick="start(event)">Start</button><br/>
    <video id="myvideo" controls="true" playsinline autoplay muted></video>
  </div>
  
</body>
</html>
            
          
!
            
              header {
  background: #eee;
  padding: 20px;
  font-family: Helvetica, Arial, sans-serif;
}

header a:first-child {
  float: right;
  margin: 0 0 20px 30px;
}

button {
  display: inline-block;
  position: relative;
  top: 110px;
  left: 110px;
  z-index: 10;
}

video {
  width: 267px;
  height: 200px;
  border: 1px solid white;
  outline: 1px solid #ccc;
  z-index: 5;
}

#myvideo {
  transform: rotateY(-180deg);
}

#start {
  display: none;
}
            
          
!
            
              var skylink = new Skylink();
skylink.setLogLevel(4);
skylink.on('peerJoined', function(peerId, peerInfo, isSelf) {
  if(isSelf) return; // We already have a video element for our video and don't need to create a new one.
  var vid = document.createElement('video');
  vid.autoplay = true;
  vid.controls = true;
  vid.setAttribute('playsinline', true);
  vid.muted = true; // Added to avoid feedback when testing locally
  vid.id = peerId;
  document.body.appendChild(vid);
});

skylink.on('incomingStream', function(peerId, stream, isSelf) {
  if(isSelf) return;
  var vid = document.getElementById(peerId);
  attachMediaStream(vid, stream);
});

skylink.on('peerLeft', function(peerId) {
  var vid = document.getElementById(peerId);
  document.body.removeChild(vid);
});

skylink.on('mediaAccessSuccess', function(stream) {
  var vid = document.getElementById('myvideo');
  attachMediaStream(vid, stream);
});

skylink.init({
  apiKey: 'f1773757-5f8b-42dc-b1ef-2374066866f6', // Get your own key at https://console.temasys.io
  defaultRoom: 'GogabE'//getRoomId()
}, function (error, success) {
  if (error) {
    document.getElementById('status').innerHTML = 'Failed retrieval for room information.<br>Error: ' + (error.error.message || error.error);
  } else {
       document.getElementById('status').innerHTML = 'Room information has been loaded. Room is ready for user to join.';
    document.getElementById('start').style.display = 'block';
  }
});

function start(event) {
  event.target.style.visibility = 'hidden';
  
  skylink.joinRoom({
    audio: true,
    video: true
  }, function (error, success) {
    if (error) {
      document.getElementById('status').innerHTML = 'Failed joining room.<br>' +
  'Error: ' + (error.error.message || error.error);
    } else {
      document.getElementById('status').innerHTML = 'Joined room.';
    }
  });
}


/* Helper functions */

function getRoomId() {
  var roomId = document.cookie.match(/roomId=([a-z0-9-]{36})/);
  if(roomId) {
    return roomId[1];
  }
  else {
    roomId = skylink.generateUUID();
    var date = new Date();
    date.setTime(date.getTime() + (30*24*60*60*1000));
    document.cookie = 'roomId=' + roomId + '; expires=' + date.toGMTString() + '; path=/';
    return roomId;
  }
};

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console