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

              
                <script src="//cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/swarmcloud-hls@latest/dist/p2p-engine.min.js"></script>
<video id="video" controls></video>
<p id="version"></p>
<h3>download info:</h3>
<p id="info"></p>
<table id="table-body">
    <tbody ></tbody>
</table>
<script>
    document.querySelector('#version').innerText = `hls.js version: ${Hls.version}  p2p version: ${P2PEngineHls.version}`;
    var p2pConfig = {
        logLevel: 'debug',
        live: false,        // set to true in live mode
        swFile: './sw.js',
        // trackerZone: 'hk',        // if using Hongkong tracker
        // trackerZone: 'us',        // if using USA tracker
        // token: YOUR_TOKEN
        // Other p2pConfig options provided by CDNBye
    }
    var source = 'https://test-streams.mux.dev/x36xhzz/url_2/193039199_mp4_h264_aac_ld_7.m3u8';
    var video = document.getElementById('video');
    if(Hls.isSupported()) {
        var hls = new Hls({
            maxBufferSize: 0,       // Highly recommended setting in live mode
            maxBufferLength: 15,     // Highly recommended setting in live mode
            liveSyncDurationCount: 10,   // Highly recommended setting in live mode
        });
        p2pConfig.hlsjsInstance = hls;
        hls.loadSource(source);
        hls.attachMedia(video);
        hls.on(Hls.Events.MANIFEST_PARSED,function(event, data) {
            video.play();
        });
    }
    // This is using the built-in support of the plain video element, without using hls.js.
    else if (video.canPlayType('application/vnd.apple.mpegurl')) {
        P2PEngineHls.tryRegisterServiceWorker(p2pConfig).then(() => {
            video.src = source;
        })
        video.addEventListener('loadedmetadata',function() {
            video.play();
        });
    }
    var engine = new P2pEngineHls(p2pConfig);

    engine.on('stats', function ({totalHTTPDownloaded=0, totalP2PDownloaded=0, totalP2PUploaded=0}) {
        var total = totalHTTPDownloaded + totalP2PDownloaded;
        document.querySelector('#info').innerText = `p2p ratio: ${Math.round(totalP2PDownloaded/total*100)}%, saved traffic: ${totalP2PDownloaded}KB`;
    })

    engine.on('FRAG_LOADED', ({url, sn, segId, loaded, duration, byP2p, fromPeerId}) => {
        // console.warn(`FRAG_LOADED ${url}`)
        var source = 'HTTP';
        if (byP2p) {
            source = 'P2P';
        }
        addToTable(url, loaded, source);
    });

    function addToTable(url, downloaded, source) {
        var infoStr = `download ${url}(size:${downloaded}B) by ${source}`;
        document.querySelector('#table-body tbody').innerHTML +=
            `<tr style="text-align: center">
                    <td>${infoStr}</td>
                </tr>`
    };
</script>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console