Giter Club home page Giter Club logo

clappr-stats's Introduction

npm version license

Usage

You can use it from JSDelivr https://cdn.jsdelivr.net/npm/@clappr/stats-plugin@latest/dist/clappr-stats.min.js or as a npm package.

<script>
    var player = new Clappr.Player({
      parentId: '#player',
      plugins: [ClapprStats],
      source: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4',
      height: 360,
      width: 640,
      clapprStats: {
        // optional: time in miliseconds for each report.
        // default: 5000
        runEach: 5000,
        // optional: callback function.
        // default: console.log
        onReport: (metrics) => {console.log(metrics)},
        // Fire PERCENTAGE_EVENT when video complete some percentage.
        // default: []
        onCompletion: [10, 20, 55, 100],
        // optional: provide an img uri hosted at the same place as your farm
        // or near of it prefferable 1x1px, without caching.
        // default: none
        uriToMeasureLatency: 'http://www.example.com/images/tv/pixel-1x1-red.gif',
        // optional: provide some assets uris hosted at the same place as your farm
        // or near of it prefferable in an uncompressible file format, without caching.
        // default: none
        urisToMeasureBandwidth: [
          {url: 'http://www.example.com/images/tv/500kb.jpg', timeout: 3000},
          {url: 'http://www.example.com/images/tv/1mb.jpg', timeout: 6000},
          {url: 'http://www.example.com/images/tv/5mb.jpg', timeout: 12000}
        ],
        // optional: number of reports between two consecutive bandwidth tests.
        // default: 10
        runBandwidthTestEvery: 10
      }
    })
</script>

Metrics

{
  counters: {
    play: 0, // number of plays
    pause: 0, // number of pauses
    error: 0, // number of errors
    buffering: 0, // number of bufferings
    decodedFrames: 0, // number of decoded frames (when available)
    droppedFrames: 0, // number of dropped frames (when available)
    fps: 0, // frames per second (when available)
    changeLevel: 0, // number of adaptative bitrate changes
    seek: 0, // number of seeks
    fullscreen: 0, // number of times that user went to fullscreen
    dvrUsage: 0 // number of time that user used dvr seek (at live stream)
  },
  timers: {
    startup: 0, // time (ms) since user click/touch play (intent to play) to the play
    watch: 0, // time (ms) of watched content (does not include pause and buffering)
    pause: 0, // time (ms) of paused content
    buffering: 0, // time (ms) of buffering
    session: 0, // time (ms) of session (sum of watch+pause+buffering)
    latency: 0, // time (ms) of latency between user and the provided uri
  },
  extra: {
    playbackName: '', // playback name (hls, html5_video, flashls)
    playbackType: '', // vod or live
    buffersize: 0, // buffersize in ms
    duration: 0, // duration time in ms
    currentTime: 0, // current time in ms
    bitratesHistory: [], // the bitrates changes history
    bitrateWeightedMean: 0, // bitrate weighted mean (bps)
    bitrateMostUsed: 0, // most used (based on time) bitrate (bps)
    watchHistory: [], // an array of an array of watched range time ex: [0, 2200]
    watchedPercentage: 0, // % of watched time
    bufferingPercentage: 0, // % of buffering time
    bandwidth: 0, // user bandwidth (bps)
  }
}

clappr-stats's People

Contributors

dependabot[bot] avatar jhonatangcavalcanti avatar joaopaulovieira avatar kafeltz avatar leandromoreira avatar lucasrodcosta avatar lukasdrgon avatar otmjka avatar towerz avatar vagnervjs avatar ya7ya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clappr-stats's Issues

Create a nerd-stats UI plugin

hi
is there any possibility to add in stats "live latency" like on youtube ?
capture

I like the way they display stats and what they show.. maybe an idea to improve this plugin ;-) ?

thanks

nico

Won't work :-(

I initialize player this:

new Clappr.Player(
            {
                source: this.canal.streaming_url,
                poster: this.epgPoster,
                plugins: [LevelSelector, ChromecastPlugin, ClapprStats],
                levelSelectorConfig: {
                    title: 'Qualitat',
                    labels: {
                        2: 'Alta', // 500kbps
                        1: 'Mitja', // 240kbps
                        0: 'Baixa', // 120kbps
                    }
                },
                parentId: "#player",
                chromecast: {
                    appId: undefined,
                    contentType: 'video/mp4',
                    media: {
                        type: ChromecastPlugin.Movie,
                        title: this.canal.description,
                        subtitle: this.currentEpgDescription,
                    }
                },
                autoPlay: true,
                width: '100%',
                clapprStats: {
                    runEach: 1000,
                    onReport: (metrics) => {console.log(metrics)},
                    //uriToMeasureLatency: 'https://upload.wikimedia.org/wikipedia/commons/c/ce/Transparent.gif'
                }
            });

Console don't show nothing. Any way to find more?
The streaming URL is a m3u8 playlist.

Regards

watch metrics & PlaybackSpeedPlugin

Is there any way of updating 'watch' metrics in line with the playback speed plugin.

When a video is played at x2 speed for 10 seconds, clappr-stats still reports it as 10 seconds, but I expect it to report 20 seconds. Or when the video is played at 0.5 speed for 10 seconds, it should be logged as 5 seconds. Is this possible?
Thanks.

improvements

  • test load (it needs to reset)
  • session time (first buffering is happening first than "PLAY", waiting PLAY_REQUESTED)
  • always pass a copy of metrics
  • test autoPlay
  • write better doc (readme)
  • dropped / fps for Flash ???
  • test hls and dash
  • Use skip/pick events instead of relying on states
  • Implements the latency meter
  • Adds buffersize (latency + buffersize + encoding_segmenting === "real" latency between generated video and user)
  • adds tests
  • write better documentation (clearly defining what is each metric)
  • discuss startup metric
  • check why there is a timeupdate before play (html5, check all the other)
  • double-check buffering
  • discuss the reactive event programing approach
  • discuss if lastbitrate couldn't be an array [].push (with history)
  • avg bitrate
  • hurdle about other metrics, timers and extras.
  • provide the minimum about extensibility (maybe let the user define what is startup)
  • pauses and play are double counting??? (hls+html5?)
  • double check buffering time | startup =/ (using network throttle)

onReport - how to pass metrics to a callback function

Perhaps I'm dense or need more caffeine - but alas, I have yet to be able to understand how to override the default console.log(metrics) that gets called with onReport.

I honestly have never seen this form of syntax prior today:

onReport: (metrics) => { console.log(metrics) }

So perhaps I'm not well enough versed, but can I get some guidance on how I can pass the metrics that are being sent to console log to an external function?

I have tried:

clapperStats: { runEach: 5000, onReport: function(metrics) { myFunction(metrics); } },

clapperStats: { runEach: 5000, onReport: (metrics) => { myFunction(metrics) } },

with something like this outside the player,

function myFunction(metrics = null) { console.log('You rang?'); console.log(metrics); }

And nothing I have tried has worked. I see the default console.logs happening like clockwork, but "myFunction" is never touched.

Barring forking the code and replacing the default, you have successfully triggered my impostor syndrome and I beg for a light in this darkness.

All that said, great work here - I'm just a bit confused on this one aspect.

Handle stop event

Currently, if a user stop a live stream and play it again, this plugin won't report anymore metrics. Should we restart this plugin's state (and collects new metrics) or include counters and timers of stop?

PR new stats

After talking with @lucasrodcosta he asked me to post a PR here.
I worked a bit to ouput "latency" and "current buffer"
I'm not a dev so I do my best but I'm sure there are better ways to do it

current buffer
hls.on(Hls.Events.LEVEL_LOADED,function(event,data) {
var pos = video.currentTime;
var bufferLen = video.buffered.end(0) - pos;
console.log('CURRENT BUFFER : ' + bufferLen.toFixed(2) + ' seconds');
});

=> I detected an issue about current buffer in my code but I don't know yet how to fix it : when encoder is started if I stop it then restart it, value begins to be negative because of video.buffered.end(0) which is frozen to a very small value (0.0x)

latency (it needs EXT-X-PROGRAM-DATE-TIME header)
hls.on(Hls.Events.LEVEL_LOADED,function(event,data) {
var current = video.currentTime;
var frag = data.details.fragments[0].start;
var tps = current - frag;
var now = new Date();
var unixnow = Date.parse(now)/1000;
var tunix = Date.parse(data.details.fragments[0].rawProgramDateTime)/1000;
var latence = unixnow - tunix - tps;
console.log('LATENCY : ' + latence.toFixed(2) + ' seconds');
});

I made some tests and It works rather well.

Nico

Does not work with autoPlay true

var playerElement = document.getElementById("player-wrapper");

var player = new Clappr.Player({
  source: 'http://clappr.io/highline.mp4',
  baseUrl: '/latest',
  poster: 'http://clappr.io/poster.png',
  mute: true,
  autoPlay: true,
  plugins: [ClapprStats],
  height: 360,
  width: 640
});

player.attachTo(playerElement);

stats on RTMP stream

Hi, would this plugin work with RTMP streams as well?
cannot get it to work with clappr RTMP plugin...

Add current time / duration

It's important if the user wants to keep track of in what happened in a given time, mostly for VOD. Therefore we might deduce X %.

extra: {
   duration: 50004, // in ms
   currentTime: 4504, // in ms
   watchedPercentage: (watch / duration) * 100,// in ms
   bufferingPercentage: (buffering  / watch) * 100,// in ms
}

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.