Skip to content

绑定域名

在使用P2P服务之前,需要先绑定域名

TIP

Localhost 已加入白名单,无需绑定,用于本地调试。

Demo

参考播放器示例

引入插件

Script标签引入

html
<script src="https://cdn.jsdelivr.net/npm/@swarmcloud/vhs"></script>

文件引入

点击

Browserify / Webpack

shell
npm install --save @swarmcloud/vhs

在播放器模块中通过 require 引入cdnbye:

javascript
var P2pEngineVHS = require('@swarmcloud/vhs');

或者使用ES6的 import 语法:

javascript
import P2pEngineVHS from '@swarmcloud/vhs';

使用插件

javascript
var engine;
var player = videojs('my_video', {
  html5: {
      vhs: {
          overrideNative: true          // Enable p2p if the platform supports Media Source Extensions
      },
  }
});
player.on('xhr-hooks-ready', () => {
    if (engine) {
      engine.destroy();
    }
    engine = new P2PEngineVHS(player, {
      // trackerZone: 'hk',        // if using Hongkong tracker
      // trackerZone: 'us',        // if using USA tracker
      // token: YOUR_TOKEN
    })
});
player.src(YOUR_PLAYLIST_URL)

或者

javascript
var player = videojs('my_video', {
   html5: {
       vhs: {
           overrideNative: true        // Enable p2p if the platform supports Media Source Extensions
       },
   }
});
var engine = new P2PEngineVHS(player, {
      globalVhs: videojs.Vhs,
      // trackerZone: 'hk',        // if using Hongkong tracker
      // trackerZone: 'us',        // if using USA tracker
      // token: YOUR_TOKEN
    }, videojs)
player.src(YOUR_PLAYLIST_URL)

文件解释

@swarmcloud/vhs/
├── vhs-p2p-engine.min.d.ts         # Typescript type information
├── vhs-p2p-engine.min.js           # P2pEngine that supports both Dash and Hls
└── vhs-p2p-engine.hls.min.js       # P2pEngine that supports Hls only
└── vhs-p2p-engine.dash.min.js      # P2pEngine that supports Dash only

粤ICP备18075581号