Giter Site home page Giter Site logo

jordicenzano / videojs-cdn-prefetch Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 75 KB

Prefecth media segments to the CDN POP used by the player

License: GNU General Public License v3.0

HTML 13.97% JavaScript 86.03%
video videojs-plugin cdn video-streaming hls live edge prefetching

videojs-cdn-prefetch's Introduction

Note: This plugin is useless without the CDN prefetching code, that has to run on the CDN.

videojs-cdn-prefetch

Prefecth media segments to the CDN point of presence (POP) used by the player, this improves the viewer experience (basically reduces the chances of buffering). This feature is specially interesting when your origin is very far from that viewer and the stream is not very popular on that CDN POP.

This plugin also needs CDN code to interpret the prefechting requests. That code could be implemented in VCL Fastly or inside Lambda edge CloudFront

This code detects the parameters pr_url inside the querystring of the HLS media chunks requests and sends a GET request to those URL adding few params that allows the CDN POP to prefect that data. Example:

Chunk URL: 
Test_00028.ts?pr_url=Test_00029.ts,Test_00030.ts&foo=bar

In the previous example, before fetching the segment Test_00028.ts this plugin will send 2 GET requests (to: Test_00029.ts, and Test_00030.ts) with the following QS parameter ?pf=1, in the CDN side we need to interpret this code and execute the prefecthing.

Installation

npm install --save videojs-cdn-prefetch

Usage

To include videojs-cdn-prefetch on your website or web application, use any of the following methods.

<script> Tag

This is the simplest case. Get the script in whatever way you prefer and include the plugin after you include video.js, so that the videojs global is available.

<script src="//path/to/video.min.js"></script>
<script src="//path/to/videojs-cdn-prefetch.min.js"></script>
<script>
  var player = videojs('my-video');

  player.cdnPrefetch();
</script>

Browserify/CommonJS

When using with Browserify, install videojs-cdn-prefetch via npm and require the plugin as you would any other module.

var videojs = require('video.js');

// The actual plugin function is exported by this module, but it is also
// attached to the `Player.prototype`; so, there is no need to assign it
// to a variable.
require('videojs-cdn-prefetch');

var player = videojs('my-video');

player.cdnPrefetch();

RequireJS/AMD

When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require the plugin as you normally would:

require(['video.js', 'videojs-cdn-prefetch'], function(videojs) {
  var player = videojs('my-video');

  player.cdnPrefetch();
});

License

GPL-3.0. Copyright (c) Jordi Cenzano <[email protected]>

videojs-cdn-prefetch's People

Contributors

jordicenzano avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

benjaminymlee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.