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

@lofter-common-features/ad

v0.1.5

Published

## 调用例子 ```ts import { AdPlayTask } from '@lofter-common-features/ad/play-ad';

Downloads

112

Readme

广告相关 Ad

调用例子

import {
  AdPlayTask
} from '@lofter-common-features/ad/play-ad';

const adPlayTask = new AdPlayTask(options);
adPlayTask.play().then(
  () => {
    // 播放广告成功
    // 通过 adPlayTask.status 查询即可
    业务代码xxx
    // 建议销毁
    adPlayTask.destroy();
  },
  () => {
    // 播放广告失败
    // 通过 adPlayTask.status 查询原因即可
    业务代码xxx
    // 建议销毁
    adPlayTask.destroy();
  }
)

参数说明

options.orderId

类型:string

必填,广告订单ID

options.userId

类型:number

必填,登陆用户id,需要传给客户端

options.location 和 options.category

广告参数

options.playAgainCount

类型:number

非必填,连续的第几次播放,默认为1

options.pollingConfig

非必填,如果不传则不会进行轮询,并在客户端回调后标记为resolve

{
  /**
   * 第一次收到回调后立刻查询,
   * 后续每2秒轮询一次,
   */
  pollingDelay: 2000,
  /**
   * 总共的轮询次数
   */
  pollingMaxCount: 10,
  pollingFunction: ({
    /**
     * 当前是第几次轮询,从1开始
     */
    times
  }) => Promise<void | {
    success: true | false,
    /**
     *
     */
    orderResults: OrdersResult
  }>
}


/**
 * 给客户端打点用的,透传后端数据
 */
type OrdersResult = {
  id: number;
  /**
   * 0-未成功;1-已成功
   */
  status: 0 | 1;
  rewardType: number;
  rewardCount: number;
}[]

options.tracking

非必填,埋点函数的回调

(
  eventId: string,
  eventData: any
) => void;

播放状态

export const PLAY_AD_STATUS = {
  /**
   * 广告任初始化后,默认是prepare
   */
  PREPARE: -1,
  /**
   * 调用 njb_playAd 但是还没收到反馈
   */
  START: 0,
  /**
   * 客户端通过 njb_playAdCallback 回调成功
   */
  COMPLETED: 1,
  /**
   * 规定时间内,未收到客户端的njb_playAdCallback回调
   */
  TIME_OUT: 2,
  /**
   * 播放中的状态,一半可以葫芦
   */
  PLAYING: 3,
  /**
   * 用户主动取消
   */
  CANCEL: 4,
  /**
   * 客户端回调状态为 0 或者未识别的状态吗
   */
  ERROR: 5,
  /**
   * 订单轮询成功
   */
  ORDER_SUCCESS: 6,
  /**
   * 订单轮询失败
   */
  ORDER_FAILURE: 7,
}

广告播放 bridge 返回 code用于debug

/**
 * 广告播放 bridge 返回 code
 */
export const PLAY_AD_CODE = {
  COMPLETED: 200,
  ORDER_COMPLETED: 202,
  ERROR: 0,
  PLAYING: 201,
  CANCEL: 100
}

播放事件

export interface PlayAdEvents {
  completed: AdPlayTask;
  playing: AdPlayTask;
  cancel: AdPlayTask;
  error: AdPlayTask;
  play: AdPlayTask;
  orderSuccess: AdPlayTask;
  orderFailure: AdPlayTask;
  timeout: AdPlayTask;
}

const removeListener = adPlayTask.addListener('eventName', () => {})