npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

videojs-hls-live-sync

v0.9.5

Published

Allows sync of multiple VideoJS players accross multiple browsers to syncronize playback with an offset of < 0.1 sec

Downloads

7

Readme

video-hls-live-sync

This package attempts to synchronize playback of hls (others not tested) based live video streams across browsers running on different computers.

The primary use case is when you want to play a synchronized stream in a different language in the same room on different speakers.

Requirements:

You will need a HTTPsTime Server that provides the X-HTTPSTIME header, in order to get sufficient accuracy.

Here is a naive Go handler for such a server:

func timeHandler(w http.ResponseWriter, req *http.Request) {
	w.Header().Add("X-HTTPSTIME", fmt.Sprintf("%d", time.Now().UnixNano()/int64(time.Millisecond)))
	w.Header().Add("Access-Control-Allow-Origin", "*")
	w.Header().Add("Access-Control-Expose-Headers", "X-HTTPSTIME")
	w.Write([]byte{})
}

The system also performs the sync 6 times. The first result is ignored as there are often delays that are not present in later requests (cold functions, routing etc), and then computes the average of the next 5 results.

In addition you will need a Firebase project with enabled RealTime Database.

Usage

An example page playing a dummy live stream is available at ./src/index.html. You should modify that file to include your firebase config. Then you can easily run it using npm install && make demo and visiting http://localhost:8000/ It requires you to have python3 installed as it is used as a dummy web server.

When you open the page, the URL will be updated with a session code in the hash, like for example http://localhost:8000/#90jv47. This url can be copied into another browser, where the player will then act as a slave and attempt to sync to the master that was automatically created in the first window.

It is possible to force a certain ID on a master by using #master-<ID> but remember that 2 masters in the same session are not a good idea.

After the system has finished syncing as best it can1, you can perform fine adjustments using the .nudge(<time>) method.

In the example this is implemented in the form of two buttons:

document.getElementById("add").addEventListener("click", () => liveSync.nudge(0.2));
document.getElementById("sub").addEventListener("click", () => liveSync.nudge(-0.2));

This usually allows for a diff of < 80ms within a few clicks. Note that due to the components involved (Browser, Js engine, Garbage collection, network, etc.) it is pretty much not possible to synchronize the playback with an accuracy that audible no phase shift occurs on headphones. It is not meant to be used on one output!

In the cases where the system does not converge, you should just do a full reload of the page.

It is also possible to request a .resync() for example like this:

document.getElementById("resync").addEventListener("click", () => liveSync.resync());

FAQ:

The stream sometimes doesn't converge or errors out in the start: Just reload the whole page.

.nudge() function is not accurate: Yeah, I know.

Can I use this with players other than Video.js: Unlikely in this form, but if you get it working send a patch.

Can I use this for VOD: No, not as is, but it could likely be adjusted to work.

I'm getting odd results: We rely on AWS using consecutive segment numbers, and a segment length of 6 seconds.

Do the two computers need to have tightly synchronized clocks: No, the time is synced for that reason.

References:

  • HTTPsTime specs: https://web.archive.org/web/20210103104032/http://phk.freebsd.dk/time/20151129/
  • Inspiration: https://github.com/webtiming/timingsrc
  • NTP code, inspiration: https://stackoverflow.com/questions/1638337/the-best-way-to-synchronize-client-side-javascript-clock-with-server-date

Footnotes

1: Sometimes +- 0.5 sec but usually a lot closer.