Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@skylineos/clsp-player

skylineos4.8kMIT0.23.13TypeScript support: included

Skyline Technology Solutions' CLSP Video Player. Stream video in near-real-time in modern browsers.

html5, clsp, video, player, skyline

readme

Skyline CLSP Player

An html5 CLSP video player. CLSP is a proprietary near-real-time video streaming protocol only available via Skyline's SFS solutions.

Table of Contents

Supported Browsers

Desktop

  • Google Chrome 53+
  • Mozilla Firefox 70+
  • Microsoft Edge 80+ (Chromium-based)

All other desktop browsers are currently not supported.

Mobile

@todo

CLSP Streams

The highest h.264 keyframe/iframe segment frequency this player currently supports is 2 per second (this is different from frames per second).

URL Structure

The network protocol is handled by specifying the following URI format:

[clsp protocol] :// [sfs-host] : [port-number-of-web-socket] / [stream-name]

  • clsp protocol: clsp or clsps
  • sfs-host: the host (or ip address) of the Skyline SFS
  • port-number-of-web-socket: optional, @see Default Port
  • stream-name: the stream name as defined on the Skyline SFS

Example stream url:

clsp://sfs.somecity.com/CityFeedVideo0652

Note that many Skyline SFS production LTS deployments use a default port of 9001. To accomodate for this, you do not necessarilly need to append the port 9001 to every clsp url. You can use the utility method utils.setDefaultStreamPort, which is documented below.

Tokenization

Control stream access via jwt tokens.

JWT

The JWT authorization method provides authorization as well as stream access time.

clsps://[sfs-host]:[port-number-of-web-socket]/[stream-name]
  ?token=[jwt-token]
  • sfs-host: the host (or ip address) of the Skyline SFS
  • port-number-of-web-socket: required, @see Default Port
  • stream-name: the stream name as defined on the Skyline SFS
  • token: contains a jwt token with the expiration claim, signed by the shared secret

The token is created by the stream manager. A shared secret exists between the stream manager and Skyline SFS(s) You will need to work with Skyline to configure and use jwt token support.

Default Port

protocol / SFS version >= v5.2.0 < v5.2.0
clsp 80 9001
clsps 443 443

Note that many Skyline SFS production LTS deployments use a default port of 9001. To accomodate for this, you do not necessarilly need to append the port 9001 to every clsp url. You can use the utility method utils.setDefaultStreamPort, which is documented below.

Installation

Via Yarn

yarn add @skylineos/clsp-player

Via NPM

Note that installation /use via yarn is recommended as it is what we use for development, testing, and dependency management.

npm i @skylineos/clsp-player

Use

via <script> tag

NOTE: See demos/single-player/ and demos/advanced-dist/ for full examples.

A CLSP object is attached to window, which contains the classes and utils you need to create players.

<head> Tag

<head>
  <!-- load CLSP Player styles -->
  <link
    rel="stylesheet"
    href="/path/to/dist/clsp-player.css"
  >
<head>

<script> Tag

<!-- load CLSP Player in `head` or `body` -->
<script src="/path/to/dist/clsp-player.min.js"></script>

<!-- use CLSP Player at end of `body` -->
<script>
  let videoElementId = 'my-video';
  let urls = [
    'clsps://bd-demo-sfs1.skyvdn.com/testpattern',
    'clsps://bd-demo-sfs1.skyvdn.com/testpattern',
  ];

  // If you are using a Skyline SFS that uses a default CLSP stream port that
  // isn't `80` (e.g. SFS < v5.2.0), you may set the window-level default port
  // for `clsp` streams:
  window.CLSP.utils.setDefaultStreamPort('clsp', 9001);

  // Construct the player collection
  let iovCollection = window.CLSP.IovCollection.asSingleton();

  // Instantiate the iov instance for the target video element
  let iov = iovCollection.create({
    videoElementId: videoElementId,
  })

  // play a CLSP stream with the iov instance
  iov.changeSrc(urls[0])
    .then(/*..*/)
    .catch(/*..*/);
</script>

<video> tag

We recommend wrapping the video tag in a container element (e.g. div) that the CLSP Player can mutate as needed. The CLSP Player needs to perform some actions on the video element as well as its container.

Note that for clsp streams, the src tag must have a type attribute with a value of video/mp4; codecs='avc1.42E01E'.

This tells the browser exactly what codec to use to decode and play the video. H.264 baseline 3.0 is a least common denominator codec supported on all browsers (according to the MSE development page).

<div class="video-container">
  <div class="clsp-player-container clsp-container-fit">
    <video id="my-video"></video>
  </div>
</div>

via import or require

NOTE: See demos/single-player/ and demos/advanced-src/ for full examples.

JS

import {
  IovCollection,
  utils,
} from '@skylineos/clsp-player';

const videoElementId = 'my-video';
const urls = [
  'clsps://bd-demo-sfs1.skyvdn.com/testpattern',
  'clsps://bd-demo-sfs1.skyvdn.com/testpattern',
];

try {
  // If you are using a Skyline SFS that uses a default CLSP stream port that
  // isn't `80` (e.g. SFS < v5.2.0), you may set the window-level default port
  // for `clsp` streams:
  utils.setDefaultStreamPort('clsp', 9001);

  // Construct the player collection
  const iovCollection = IovCollection.asSingleton();

  // Instantiate the iov instance for the target video element
  const iov = iovCollection.create({ videoElementId });

  // play a CLSP stream with the iov instance
  await iov.changeSrc(urls[0]);
}
catch (error) {
  // do something with the error
  console.error(error);
}

Styles

@import '/path/to/node_modules/@skylineos/clsp-player/dist/clsp-player.css';
// or import it from src
@import '/path/to/node_modules/@skylineos/clsp-player/src/styles/clsp-player.css';

<video> tag

We recommend wrapping the video tag in a container element (e.g. div) that the CLSP Player can mutate as needed. The CLSP Player needs to perform some actions on the video element as well as its container.

<!-- The outer container used for your styling -->
<div class="video-container">
  <!-- The inner container used by CLSP for styling and other operations -->
  <div class="clsp-player-container clsp-container-fit">
    <video id="my-video"></video>
  </div>
</div>

Known Issues

Videos appear to have a low framerate

During testing, we have encountered an issue where a large number of CLSP streams ( > 30 ) played on a single page in Chrome can appear choppy or to have a low framerate. This same test / demo works without issue on other machines, or in Firefox.

The underlying symptom appears to be a large number ( > 50 ) of Style recalcs / sec as reported by the Chrome Performance Monitor. This high number has only been observed in Chrome with specific video cards and with hardware acceleration enabled (which is the default setting).

This appears to be a bug in the Chrome browser, and there are anecdotal reports of this behavior online starting from early 2019, but no official bug report that we are aware of.

At the moment, the only known workarounds are to disable hardware acceleration in Chrome's settings, try using the Firefox browser, or try using a different video card.

changelog

CLSP Player Changelog

Table of Contents

CLSP Player

  • add jwt authorization

v0.23.0 - 2022-01-17 - Optional

  • add loading spinner
  • fix to work with Angular optimized builds

v0.22.0 - 2020-09-30 - Critical

  • fix all destroy logic, including when iframe is destroyed
  • increase and improve event-based logic
  • implement option to pass in a <video> tag that is not destroyed
  • make logging to the console globally configurable for all players
  • fix error preventing port 80 from being accepted on stream urls
  • add tests
  • reduce visible logging
  • temporarily remove tour support
  • improve memory usage
  • improve memory management
  • improve performance
  • improve restart logic
  • improve logging
  • improve error handling
  • improve code documentation
  • added timeouts to some async actions
  • create single-player demo, retire simple demos
  • implement iframe destroy testing in single-player demo
  • split Conduit up into multiple Router Manager classes to reduce coupling
  • update all dependencies
  • CLSP Player is now packaged and published as a UMD module
  • Updated the default exports (@see src/js/index.js)
  • README no longer uses src and dist terms - now references import/require and <script>
  • @babel/polyfill is no longer required! - instead, @babel/runtime is used and already included
  • All exports when using CLSP Player via <script> are namespaced in window.CLSP
  • All examples and demos now use dist assets rather than src assets to be more in line with 3rd party use
  • Babel configuration is now in its own file
  • All demos have their own README files
  • Metrics have been temporarily removed from all demos
  • Created typescript module definition file
  • All utils exports are now documented
  • Webpack configurations were refactored to support the demos relying on the CLSP Player dist assets
  • Webpack configurations were refactored to be explicitly named after the CLSP Player and demos
  • The build and serve scripts were refactored to use the new webpack config files
  • The build and serve webpack utilities were consolidated and moved to their own folder
  • Removed unused pre-build script

v0.20.1 - 2020-04-30 - Critical

  • change default CLSP port from 9001 to 80 to comply with newest SFS versions
  • make default clsp and clsps ports configurable via utils

v0.19.0 - 2020-04-21 - Critical

  • move demo to demos
  • create advanced and simple demos that use dist assets
  • create advanced and simple demos that use src assets
  • move demo dist assets to dist/demos folder
  • include README examples for both dist and src approaches
  • refactor build and serve scripts
  • only generate prod dist assets for CLSP VideoJS Plugin
  • only generate dev dist assets for demos

v0.18.0-1 - 2020-04-04 - Critical

  • Update minimum supported Chrome version to 53
  • publish to NPM registry!
  • dist files are no longer part of source control
  • dist files get generated during publish
  • remove all videojs assets, logic, dependencies, etc.
  • update all dependencies
  • update all demos to not explicitly say "standalone"
  • advanced demo now uses src assets, not dist assets
  • remove all vagrant assets
  • simplify webpack config
  • replace extract-text-webpack-plugin with mini-css-extract-plugin

Pre CLSP Player

v0.17.0-1 - 2020-02-11 - Critical

Note that version 0.17 was never released.

  • change the videojs element class from vjs-mse-over-mqtt to vjs-clsp
  • update vulnerable dependencies
  • update all outdated dependencies
  • numerous memory leak fixes
  • the video tags SHOULD now have a dedicated container for use by the CLSP plugin
  • add functionality to switch stream source on internal player
  • add externally available tour controller
  • add stream play timeout handling in Conduit
  • add CLSP publishing events
  • handle streams that don't return data (with timeouts)
  • handle invalid urls (with timeouts)
  • rename IOV classes
  • implement ConduitCollection
  • implement StreamConfiguration
  • implement TourController
  • most constants (like timeout durations) are now configurable on instances
  • improve async logic and error handling
  • add timeouts to catch and respond to errors, which improves memory utilization
  • IovPlayer no longer calls methods on its parent Iov
  • IovPlayer now instantiates and controls its own Conduit
  • split styles into multiple files
  • add demo for tours
  • each demo now has its own folder
  • create constants for Conduit and Router events
  • document Conduit and Router classes and files
  • Add debug logs
  • emit "firstFrameShown" event
  • fix streams flickering in certain situations
  • remove jupyter notebook, which makes this project show as primarily javascript in github
  • update destroy logic
  • Remove debug statements appearing as console errors
  • Update all outdated npm dependencies
  • Rearchitected interfaces between most classes, and among the videojs plugin components
  • Added IOV Collection class to manage IOV instances
  • De-coupled the CLSP-playing logic from videojs
  • IOV is now the only class that communicates with the Conduit and the IOV Player
  • Removed the requirement of videojs for playing CLSP streams
  • Added explicit play, stop, fullscreen, and destroy methods to the CLSP player (IOV)
  • Added explicit stop and destroy methods to the CLSP plugin
  • Improved destroy logic
  • Identify additional browsers
  • Implement successful failover to HLS, if available
  • Added support for ononline and onoffline window events
  • Added new logging system
  • Improved logging
  • Improve jsdocs
  • Created demo wall for CLSP player
  • Created demo player for CLSP player
  • Created demo player for CLSP plugin
  • Created demo landing page
  • Include code examples for common use cases in README
  • Moved internal-developer-specific stuff from the README into DEVELOPERS.md

v0.15.0 - 2018-12-07 - Critical

  • update to node 10.15
  • move to yarn from npm
  • add Vagrantfile and steps
  • update standard skyline development assets
  • remove gulp, rely solely on bash scripts and webpack
  • make iframe javascript reference parent window paho library to reduce code duplication
  • minimize the iframe srcdoc javascript
  • fix window minimize memory leak

v0.13.11 - 2018-12-07 - Critical

  • lock down paho version to ensure it doesn't update to 1.1.0, which is incompatible

v0.13.10 - 2018-10-13 - Critical

  • fix chrome detection for chrome v71

v0.13.9 - 2018-10-13 - Critical

  • update most outdated libraries
  • update video.js version
  • add memory stats to demo page
  • update to videojs 7 to improve memory management
  • make destroy synchronous
  • performance / lifecycle improvements
  • address errors
  • improve debug statements
  • perform null check on window.performance and memory
  • when the buffer gets full, flush it

v0.13.8 - 2018-11-14 - Critical

  • fix unresolved sourceBuffer destroy
  • ensure the asynchronous destroy logic can finish before videojs dispose runs/finishes
  • document necessary videojs-errors version
  • move videojs-errors into devdependencies

v0.13.7 - 2018-11-13 - Optional

  • set the default timeout back to 2 minutes

v0.13.6 - 2018-11-13 - Critical

  • fix async calls
  • destroy self on player dispose
  • implement disconnect conduit method
  • WIP destroy player without error
  • do not try to reconnect to CLSP after successful disconnection
  • stop trying to send stats to the server on failure
  • reset videojs-errors after responding to recoverable errors

v0.13.5 - 2018-10-31 - Critical

  • fix tab switching memory leak
  • disable metrics by default to improve performance
  • export version in main file
  • implement player retry on error
  • implement workaround for videojs 7 autoplay issue for a future version
  • detect and throw error when too much browser resources are being used
  • retry on iov player error
  • check isSourceBufferReady before performing destroy operations on MSEWrapper
  • additional null checks
  • tracking "stopped" on iov player
  • consolidate iov conduit actions on stop and play
  • demo page allows user to close an individual player
  • demo page only contains wall
  • demo displays index number and stream url
  • demo page remembers last used urls
  • add standard skyline development assets
  • fix webpack config mutations, which fixes dev server
  • trigger a 'firstFrameShown' event on the videojs player instance so that the listener can be registered prior to iovplayer instantiation

v0.13.4 - 2018-08-27 - Critical

  • tours are no longer supported - must be implemented by the caller
  • fix high quality stream playback (streams with large segment intervals)
  • video elements are now properly muted, so user interaction is no longer required for autoplay on page load
  • make drift detection values dynamically calculated based on metrics
  • make freeze detection values dynamically calculated based on metrics
  • improve metrics
  • improve memory management
  • improve error handling
  • tour improvements
  • ensure all moofs have proper and sequential sequence numbers
  • properly display version number on registered plugin
  • add version script to automatically build whenever version is incremented
  • demo page tracks number of videos playing, time started, and time elapsed
  • improve dev server
  • file / class restructure
  • decrease coupling between classes
  • decrease coupling between videojs and iovPlayer
  • update dependencies

v0.12.1 - 2018-08-27 - Optional

  • improve demo page

v0.12.0 - 2018-08-13 - Critical

  • metric collection and calculation
  • implement a queue to reduce unecessarily-dropped video segments
  • implement "burst control" to ensure that video segments are not skipped
  • rudimentary tab visibility handling
  • rudimentary "drift detection" to respond to increases in lag
  • rudimentary "freeze detection" to respond to seemingly frozen streams
  • reduce video stuttering
  • improve error handling
  • require videojs 6.7.1 (the last version to properly support autoplay)
  • document relationship between SFS settings and player performance and guarantees
  • demo page improvements
  • display metrics on demo page
  • abstract the logic for MSE
  • decrease coupling between classes
  • decrease coupling between videojs and iovPlayer
  • update dependencies

v0.10.2 - 2018-08-27 - Optional

  • improve demo page

v0.10.0 - 2018-08-01 - Critical

  • first stable production-ready build
  • support cycling through multiple clsp streams (tours)
  • can respond to CLSP resync messages
  • use default secure and non-secure ports
  • rudimentary error handling
  • updated demo page
  • headless player demo
  • use webpack, babel, es6, etc
  • use npm to manage dependencies
  • decrease coupling between classes
  • decrease coupling between videojs and iovPlayer

v0.1.5 - 2017-08-27 - Critical

  • first stable proof of concept
  • rudimentary demo page
  • point of reference for basic video playing via clsp, no advanced features

Appendices

Status Definitions

  • Critical - this version fixes critical issues that were discovered in the previous version, and it is critical that users update
  • Recommended - this version fixes important issues or adds important functionality, and it is recommended that users update
  • Optional - this version fixes minor issues or adds minor or optional functionality, and users can safely wait to update