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

@shammas44/interactive-video-player

v4.0.5

Published

- [Summary](#summary) - [Interactive-video-player](#interactive-video-player) - [Description](#description) - [Installation](#installation) - [Usage Exemple](#usage-exemple) - [Documentation](#ducumentation) - [Events](#events) - [Player](

Downloads

6

Readme

Summary

Interactive-video-player

This project is licensed under ISC.

Description

The interactive-video-player package is a custom component using shadowDOM properties embedable in html. This library include a video player allowing the user to switch between multiple video sequence based on textual choicie made by the user presented to him at each ends of a video sequence.

This library allow to quickly create video games like for exemple Super Seducer by providing a scenario object directly to the video player.

Installation

npm i @shammas44/interactive-video-player

Usage Exemple

First import the Player class in your script to make the shammas-player custom element available.

// index.ts

// imports Players types
import {
  Player as PlayerElement,
  Project,
  VideoNode
} from "@shammas44/interactive-video-player";
//imports the web component called shammas-player
import from "@shammas44/interactive-video-player";

Then include it in your html using the shammas-player custom element tag

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script defer type="module" src="index.ts"></script>
</head>
<body>
  <!-- insert your video player -->
  <shammas-player></shammas-player>
</body>
</html>

It is important to use the following meta tag in your html document to make @media query work as expected

<meta name="viewport" content="width=device-width, initial-scale=1" />

To configure your player you need to call the method initProject with a valid project from Project type as argument

// index.ts

// The preceding imports goes here ->

const videos: VideoNode[] = [
  {
    id: "1",
    name: "video1",
    paths: ["video/video1-desktop.mp4", "video/video1-mobile.mp4"],
    animation: {
      title: "Which Video sequence would you watch now ?",
      duration: 10,
      position: InteractionPosition.BOTTOM,
    },
    interactions: [
      { id: "2", content: "video 2" },
      { id: "3", content: "video 3" },
    ],
  },
  {
    id: "2",
    name: "video2",
    paths: ["video/video2-desktop.mp4", "video/video2-mobile.mp4"],
    animation: {
      title: "Which Video sequence would you watch now ?",
      duration: 10,
      position: InteractionPosition.BOTTOM,
    },
  },
  {
    id: "3",
    name: "",
    paths: ["money.mp4", "money.mp4"],
  },
];

const project: Project = {
  id: "1",
  entrypointId: "1",
  videos: videos,
};

const player: PlayerElement | null = document.querySelector("shammas-player");
if (player != null) {
  player.initProject(project);
}

Documentation

Events

shammas-video-end: Fired when the last video sequence just finished playing

shammas-sequence-started: Fired once a new video sequence is played

This events emits The current video of type VideoNode available on property detail

Exemple

const player: PlayerElement | null = document.querySelector("shammas-player");
if (player != null) {
  player.addEventListener('shammas-sequence-started',(e)=>{
    // log out the current video of type VideoNode
    console.log(e.detail) 
  });
  player.initProject(project);
}

⚠️ It is important to set the eventListener before calling player.initProject() otherwise, the first video sequence won't be taken into account.

shammas-lastSequenceReached: Fired when the last video of the sequence start playing.

Player

Selectors: defines CSS selectors that are used in the player.

VideoEvent: defines strings that represent the different types of events that can be triggered when interacting with a video element.

MouseEvents: defines strings that represent the different types of mouse events that can be triggered.

ProgressBarEvents: defines a single event type INPUT that can be triggered when interacting with the progress bar element.

Icons: defines URLs for different icons used in the UI, and they come from an icon library.

Methods

The initProject method takes a Project object, a boolean value indicating whether the player is running on a mobile device (isMobile), and an optional firstVideoId parameter. This method initializes the project property and calls the init method on the videoPlayers object, passing in the project and the Player object. If a firstVideoId is provided, the player will start playing that video; otherwise, it will start playing the entrypoint video specified in the project object.

The playVideo method takes a videoId string and a boolean indicating whether the player is running on a mobile device (isMobile). This method calls the playmethod on thevideoPlayersobject, passing in thevideoId, false, and isMobile parameters.

The togglePlay method toggles the play/pause state of the currently playing video and updates the controller button play icon accordingly.

Project

Interaction: represents an interaction that can be associated with a video node. It has two properties: content, which is a string representing the content of the interaction, and id, which is a unique string identifier for the interaction.

VideoNode: represents a node in a video graph. It has three properties:

  • id, which is a unique string identifier for the node,
  • name, which is a string representing the name of the node
  • paths, which is an array of two strings and the first one is used for stocking the source of the video landscape format, and the seconde one is for the mobile format .
  • Additionally, it can have an optional interactions property, which is an array of Interaction objects associated with the node.

Project: represents a project involving multiple video nodes. It has three properties: id, which is a unique string identifier for the project, entrypointId, which is a string representing the ID of the entrypoint node for the project, and videos, which is an array of VideoNode objects representing the nodes in the video graph.

Video

The Video class has a constructor that sets up some instance variables and event listeners, and it also has several methods that manage video playback and event handling.

The init method initializes the video player with a Project object and a Player object. The play method plays a video with the specified ID, and takes a boolean firstPlay parameter which is true if this is the first video being played, and a boolean isMobile parameter which is true if the player is running on a mobile device.

The getCurrentVideoTag method returns the current HTML video element being played.

Controller

The Controller class represents a custom web component for controlling the video playback.

The class has several properties and methods:

  • currentVideoTagIndex: a number representing the index of the currently selected video tag.
  • videoTags: a list of video elements.
  • toggleButton, volumeButton, and progressBar: references to various elements within the component.
  • hideTimeout: a NodeJS timeout object used to hide the controller after a certain period of inactivity.
  • setCurrentVideoTagIndex(index: number): a method for setting the index of the currently selected video tag.

Finally, the code defines the custom element using the customElements.define() method, which registers the Controller class with the browser so that it can be used as an HTML tag. The COMPONENT_NAME constant (N) is used to specify the name of the custom element.

PopUp

The Popup class is used to create a custom HTML element with the name "popup". It imports several modules and constants from other files, including Interaction and VideoNode from ../../models/project, Selectors and MouseEvents from ../../models/player, and COMPONENT_NAME from ../../utils/helpers. It also imports a default export named template from a file called popup.template and Video from ../video/video.

The buildPopup method takes a VideoNode object as an argument and builds the popup content based on the interactions associated with that video.

The togglePopup method toggles the visibility of the popup and sets up a listener for a click event on the popup button. Finally, the createButtons and createButton methods are used to create and add buttons to the popup based on the interactions associated with the video.

Examples

A quick view of what the player looks like:

1682426760029

It's a player where the user can

  • stop/play the video;
  • mute/unmute the video;
  • move forward and backward in the current video.

A quick view of what the interactions



"interactions": [
	{
		"id": "id-choice-1",
		"content": "choice #1"
	},
	{
		"id": "id-choice-2",
		"content": "choice #2"
	},
	{
		"id": "id-choice-3",
		"content": "choice #3"
	},
	{
		"id": "id-choice-4",
		"content": "choice #4"
	}

look like (they appear in the form of a popup):

1682431711039

When the user cliks in one of the options, it defines wich video plays next.