Theta P2P Javascript SDK

Here are instructions for integrating Theta P2P with any HLS.js compatible video player. Below examples are using video.js and hls.js as a video player solution, and can serve as a guide for integrating into custom players.

To integrate Theta into your video.js powered player, simply include the theta scripts and setup the options for your video.js player as shown below. You can also check here for a full integration example.

1. Include scripts

Enter the following script tags in your head tag. Ensure HLS.js is included before the theta-hls-plugin.

<script src=''></script>
<script src="[email protected]"></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<link rel=“stylesheet” href=“”>

2. Setup video.js options

   play video boii {{.}}
   <video id="my-player" controls></video>

  const optionalHlsOpts = null;
  const optionalThetaOpts = {
    allowRangeRequests: true, // false if cdn does not support range headers  
  const player = window.player = videojs('my-player', {
          techOrder: ["theta_hlsjs", "html5"],
          sources: [{
            src: "YOUR_VIDEO_URL",
            type: "application/",
            label: "1080p"
          theta_hlsjs: {
              videoId: "YOUR_INTERNAL_VIDEO_ID",
              userId: "YOUR_AUTHED_USER_ID (optional)", 
              onThetaReady: null, // optional listener
              onStreamReady: null, // optional listener
              hlsOpts: optionalHlsOpts,
              thetaOpts: optionalThetaOpts,

All set! Now your web clients should start to peer with each other and share video streams to offload the CDN bandwidth. For more controls for the Theta lib, e.g. turning off the p2p feature, please refer to the 3. Additional Controls section.

3. Additional Controls (Optional)

Toggle CDN Only

Sometimes you want to only allow CDN (user pref, etc). This code will enable or disable CDN only mode.