@eyevinn/csai-manager

中文文档
0.1.2发布于 2022/08/10MITTypeScriptCommonJS近 30 天下载 2.5万

CSAI Manager ===

原始使用文档
文档目录5 节
  1. Installation
  2. Basic Usage
  3. Available Options
  4. Events
  5. Methods

CSAI Manager

Simple class to conduct and manage the relation between content playback and an ad experience applied on top - client side.

Installation

npm install @eyevinn/csai-manager

Basic Usage

const videoElement = document.querySelector("video");
new CSAIManager({
  contentVideoElement: videoElement,
  adBreakVASTList: [
    {
      timeOffset: 0,
      vastUrl:
        "https://eyevinn.adtest.eyevinn.technology/api/v1/vast?dur=30",
    },
  ],
});

videoElement.addEventListener("ended", () => {
  csaiManager.destroy();
});

If you do not send in an already created ad video element (through the available option listed below), but let the library create the element, you will need to set the container to position: relative; as the CSAI Manager will try to position the new element absolute edge to edge of the container.

Available Options

export interface ICSAIManagerOptions {
  debug?: boolean;

  contentVideoElement: HTMLVideoElement;
  autoManagePlayback?: boolean; // default true; whether you want the manager to pause/play the content, or if you want to act on the events
  isLive?: boolean; // default false; will adjust the validation to not require vast or vmap url etc
  autoplay?: boolean; // default false

  // Whether you have created a video element for the ads on beforehand, or would want to render it in a div. As fallback it finds the parent of the contentVideoElement
  container?: HTMLElement;
  adVideoElement?: HTMLVideoElement;

  // For fetching ads - either provide a vmap url, or a list of time offsets and vast url's
  vmapUrl?: string;
  adBreakVASTList?: IAdBreakVASTItem[];
}

export interface IAdBreakVASTItem {
  timeOffset: number;
  vastUrl: string;
}

Events

You may listen to events exposed by the ad manager, to for instance handle the pause and play of your content yourself.

const videoElement = document.querySelector("video");
const csaiManager = new CSAIManager({
  contentVideoElement: videoElement,
  adBreakVASTList: [
    {
      timeOffset: 0,
      vastUrl:
        "https://eyevinn.adtest.eyevinn.technology/api/v1/vast?dur=30",
    },
  ],
});

csaiManager.on("*", (event, data) => {

  console.log("DEBUG EVENT", event, data);

  if (event === "breakStart") {
    videoElement.pause();
  }
  if (event === "breakEnd") {
    videoElement.play();
  }
});

The events exposed are matching the VAST tracking - i.e. IAB events

export enum AdTrackingEvent {
  START = "start",
  IMPRESSION = "impression",
  EXPAND = "expand",
  MUTE = "mute",
  UNMUTE = "unmute",
  PAUSE = "pause",
  RESUME = "resume",
  REWIND = "rewind",
  CLOSE = "close",
  COMPLETE = "complete",

  FIRST_QUARTILE = "firstQuartile",
  MIDPOINT = "midpoint",
  THIRD_QUARTILE = "thirdQuartile",

  CLICK_THROUGH = "clickThrough",

  ERROR = "error",
}

export enum AdBreakTrackingEvent {
  BREAK_START = "breakStart",
  BREAK_END = "breakEnd",
}

Methods

  • play() to trigger play when autoplay isn't set to true

These methods are specifically to be used for live (remember to set the initOption autoManagePlayback to false to not pause the live stream)

  • fetchAdBreak(vastUrl: string): Promise<void>
  • triggerAdBreak(): Promise<void>

版本与发布记录

@eyevinn/csai-manager 共发布 3 个版本,首次发布于 2022/05/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.2latest2022/08/104 年前
0.1.12022/05/234 年前
0.1.02022/05/054 年前

关于 @eyevinn/csai-manager 的常见问题

@eyevinn/csai-manager 是什么?

CSAI Manager ===

如何安装 @eyevinn/csai-manager?

在项目目录运行 npm install @eyevinn/csai-manager,或使用 pnpm add / yarn add / bun add。

@eyevinn/csai-manager 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eyevinn/csai-manager 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@eyevinn/csai-manager 可以商用吗?

@eyevinn/csai-manager 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eyevinn/csai-manager 的下载量有多少?

根据 npm 官方下载统计,@eyevinn/csai-manager 在 2026/10/14 – 2026/11/12 这 30 天内被下载 25,380 次,日均约 846 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eyevinn/csai-manager 还在维护吗?

最新版本 0.1.2 发布于 2022/08/10(4 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/05/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。