针对视频多屏播放需求: 轮巡策略,包括单路依次轮巡和多路同时轮巡..
本项目的脚手架来自 pkg
🏠 Homepage
npm install @ifake/easy-polling
# or
yarn add @ifake/easy-polling- 浏览器端
// 我们提供了一个全局变量 `EasyPolling` 以便使用CDN时直接在浏览器端使用. const EasyPolling = window.EasyPolling
- ES6 Module
import { EasyPolling } from "@ifake/easy-polling"
import { EasyPolling } from "@ifake/easy-polling" const instance = new EasyPolling({ source: [param1, param2, param3...], intervalTime: 2000 type: 'single' || 'double' returnCount: 2 }) instance.observe((data) => { }) instance.start() // stop instance.stop() // update intervalTime instance.updateIntervalTime(5000)
git clone https://github.com/ifakejs/easy-polling.git
cd easy-polling
yarn
yarn start
// 新打开命令行
yarn start:demo- 参数
type RunType = "single" | "double" interface EasyPollingOptions { type: RunType // polling type source: any[] // Data source intervalTime: number // ms returnCount: number // 返回的数据(每次展示几屏)个数 replaceCount: number // 仅在single模式生效 每次替换几个视频 }
| 方法 | 类型 | 描述 | 返回值 |
|---|---|---|---|
| start | Function | 开始轮巡 | - |
| stop | Function | 结束轮巡g | - |
| observe | Function | 订阅轮巡数据 | data[] |
| updateIntervalTime | Function | 更新轮巡周期 | - |
请在observe之后调用start方法,因为在调用轮巡策略时内部我们有初始数据的逻辑
否则,将丢失初始回调数据。
e.g
# 正确用法 instance.observe(() => {}) instance.start()
👤 BiYuqi
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This project is MIT licensed.
This README was generated with ❤️ by readme-md-generator