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

yakamoz

v1.0.1

Published

HLS framework for complex use cases

Downloads

38

Readme

yakamoz

HLS framework for complex use cases.

Why?

Instead of current HLS implementations, Yakamoz provides a simple API to append buffers by yourself while handles unnecessary buffers and cleans them automaticly.

Usage

import Yakamoz from "yakamoz";
import { Parser } from "m3u8-parser";
import muxjs from "mux.js";

(async () => {
  //You can change these parts or you can connect it to indexedDB if you want!
  const baseURL = `http://localhost:5501/anime_uploads/weathering-with-you/1`;

  const m3u8File = `/1-7054810786387988481-1080p.m3u8`;
  const parser = new Parser();

  //fetching and parsing our m3u8 manifest
  async function fetchAndParseM3U8() {
    const f = await fetch(baseURL + m3u8File);
    const resp = await f.text();
    parser.push(resp);
    parser.end();
    return parser.manifest.segments;
  }

  const parsedSegments = await fetchAndParseM3U8();

  const request = (url) =>
    fetch(url).then((response) => response.arrayBuffer());

  //Transmuxer to convert mp2t buffers to fragmented mp4 buffers
  let transmuxer = new muxjs.mp4.Transmuxer();
  async function transmux(chunk, giveAsSourceBuffer) {
    return new Promise((resolve) => {
      transmuxer.off("data");
      transmuxer.on("data", (segment) => {
        if (giveAsSourceBuffer) {
          let data = new Uint8Array(
            segment.initSegment.byteLength + segment.data.byteLength
          );
          data.set(segment.initSegment, 0);
          data.set(segment.data, segment.initSegment.byteLength);
          resolve(data.buffer);
        } else {
          resolve(segment.data.buffer);
        }
      });

      transmuxer.push(new Uint8Array(chunk));
      transmuxer.flush();
    });
  }

  const yakamoz = new Yakamoz();

  //append the first buffer
  yakamoz.addEventListener("NEED_SOURCEBUFFER", async (e) => {
    const { append } = e.detail;
    const getNewBuffer = await request(`${baseURL}/${parsedSegments[0].uri}`);
    const buffer = await transmux(getNewBuffer, true);
    append(buffer);
  });

  //append proper segments when needed
  yakamoz.addEventListener("NEW_SEGMENT", async (e) => {
    const { append, targetSegment } = e.detail;
    const getNewBuffer = await request(
      `${baseURL}/${parsedSegments[targetSegment].uri}`
    );
    const buffer = await transmux(getNewBuffer);
    append(buffer);
  });

  //Do not forget to create a video element and mime property should match with the playing video.
  yakamoz.init({
    video: document.querySelector("video"),
    segments: parsedSegments,
    mime: 'video/mp4; codecs="avc1.640028,mp4a.40.2"; profiles="isom,iso2,avc1,mp41""',
  });

  //No need to clear unnecessary buffers. Yakamoz will clear them by default 😉
})();