0.8.70 • Published 25 days ago

@besovideo/webrtc-player v0.8.70

Weekly downloads
-
License
MIT
Repository
-
Last release
25 days ago

@besovideo/webrtc-player

npm NPM npm

NPM

简介 Introduction

设备视频播放、对讲封装

安装 Installation

use npm

npm i @besovideo/webrtc-player

use yarn

yarn add @besovideo/webrtc-player

示例 Example

视频

import {
  PuPlayer,
  IPuPlayerProps,
  IPuPlayerInstance,
  clearAllDialog,
} from "@besovideo/webrtc-player";
import "@besovideo/webrtc-player/dist/main.es.css";

const { instance } = PuPlayer({
  // (可选) 容器节点 注意一个容器内只能存在一个实例  当container为假值(包括false、null、undefined)时 将返回实例引用的dom节点 容器必须指定高度 参考高德地图
  container: document.getElementById("player_container"),
  // 必填 设备选项
  puOption: {
    // 设备id
    id: "PU_123456",
    // 设备通道号
    index: 0,
  },
  // 必填 用户授权令牌
  token: "Y3UrQ1VfYWRtestYDHYUAStest",
  // (可选) peer connection 连接媒体配置
  defaultMediaOption: {
    // 启用音频
    audio: true,
    // 启用视频
    video: true,
  },
  // (可选) 传输协议
  type: "webrtc" | "ws-bvrtc" | "auto";
  // (可选) 是否静音
  muted: false,
  // (可选) 指定video如何适应容器 (fill: 填充容器 ; contain :保持视频比例适应容器)
  videoFit: "fill",
  // (可选) 指定请求url路径前缀 可使用protocol+host 如:http://192.168.88.11:9780
  // apiPrefix: "/test_api/prefix",

  // (可选) 用于测试播放视频 (存在时优先使用url播放,为浏览器直接播放)
  // testUrl: "https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4",
  // (可选) 连接建立后回调
  onConnected: () => {},
  // (可选) 连接建立失败时的回调
  onConnectedFailed: () => {},
  // (可选) 连接断开后回调
  onDisConnected: () => {},
  // (可选) 双击是否全屏
  fullScreenOnDblclick: true,
  // (可选) 启用控制器
  enableController: false,
  // (可选) 禁用控制器的控制项 下面示例中禁用了云台控制
  disabledControls: ["ptzControl"],
  // (可选) 设置最大重连间隔(s),默认不自动重连,setDefaultProps设置的maxReconnectInterval高于props
  maxReconnectInterval: 30,
  // (可选) 设置webrtc下视频预览,当没有视频时有音频情况下,是否展示音频波形
  noVideoRendeAudioWaveform: false,
  // (可选) 设置语言支持中文zh、英文en,默认中文
  locale: "zh",
  // (可选) bvrtc配置
  bvrtcConfig: {
    // (可选) 是否启用webcodecs解码,默认启用
    enableWebcodes: boolean,
    // (可选) 设置解码实时性 范围 0-10, 0 -- 流畅性最大, 10 -- 实时性最大
    realTimeLevel: number
  }
});

// setVideoFit 更改videoFit
instance.setVideoFit("contain");
// setToken 更改请求时的token
instance.setToken("newTTTTToken");
// setPuOption 更改请求的设备信息
instance.setPuOption({
  id: "PU_12345test",
  index: 123,
});
// setApiPrefix 更改请求时的url前缀
instance.setApiPrefix("/测试改前缀");
// open 的可选参数muted如果为undefined, 是否静音将使用之前的状态
// open 异步 先关闭再开始建立连接 (可选参数: muted:boolean = false 是否静音打开,可选参数: protocol = type 选择协议(type = "auto" | "webrtc" | "ws-bvrtc") 不填默认为auto)
instance.open();
// close 异步 释放dialog 并关闭 当前的 peer connection
instance.close();
// destroy 执行close 并从dom移除PuPlayer节点
instance.destroy();
// moveTo 将节点移动至新的容器
instance.moveTo(document.getElementById("new_player_container"));
// getCurrentContainer 获得当前所在的容器
instance.getCurrentContainer();
// hidden 隐藏 异步 (可选参数: muted?:boolean 是否静音 可不传)
instance.hidden(true);
// display 显示 (可选参数: muted?:boolean 是否静音 可不传)
instance.display();
// play 播放 异步
instance.play();
// mute 切换静音 (可选参数: muted:boolean = false 是否静音)
instance.mute(true);
// 获取puPlayer的div
instance.getPlayerElement();
// 获取内部引用的video元素
instance.getVideoElement();

// clearAllDialog 异步 释放全部打开的dialog 不管是音视频还是对讲
clearAllDialog();
  • Controls 控制项列表
// 全部控制项
[
  "fullscreen",
  "ptzControl",
  "rotate",
  "record",
  "screenshot",
  "volumeSlider",
  "volume",
  "mike",
  "information"
];
// 在创建实例时 传入参数disabledControls数组 可关闭相关功能
// 如不使用全屏按钮、云台控制器
disabledControls: ["fullscreen", "ptzControl"];

对讲

import {
  Intercom,
  IIntercomProps,
  IIntercomInstance,
} from "@besovideo/webrtc-player";
import "@besovideo/webrtc-player/dist/main.es.css";

const { instance } = Intercom({
  // 必填 设备选项
  puOption: {
    // 设备id
    id: "PU_123456",
    // 设备通道号
    index: 0,
  },
  // 必填 用户授权令牌
  token: "Y3UrQ1VfYWRtestYDHYUAStest",
  // (可选) 连接建立后回调
  onConnected: () => {},
  // (可选) 连接建立失败时的回调
  onConnectedFailed: () => {},
  // (可选) 连接断开后回调
  onDisConnected: () => {},
  //(可选) 无法获取用户麦克风时
  onGetUserMediaFailed: () => {},
  // (可选) 指定请求url的前缀 方便代理请求
  // apiPrefix: "/test_api/prefix",
});

// open 异步 先关闭再开始建立连接 (可选参数: protocol = type 选择协议(type = "auto" | "webrtc" | "ws-bvrtc") 不填默认为auto)
install.open(type);

会议

import {
  Conference,
  IConferenceProps,
  IConferenceInstance,
} from "@besovideo/webrtc-player";
import "@besovideo/webrtc-player/dist/main.es.css";

const { instance } = Conference({
  // 必填 设备选项
  confOption: {
    // 会议id
    id: "test89312",
    // 会议成员ID
    index: 0,
  },
  // 必填 用户授权令牌
  token: "Y3UrQ1VfYWRtestYDHYUAStest",
  // (可选) 连接建立后回调
  onConnected: () => {},
  // (可选) 连接建立失败时的回调
  onConnectedFailed: () => {},
  // (可选) 连接断开后回调
  onDisConnected: () => {},
  //(可选) 无法获取用户麦克风时
  onGetUserMediaFailed: () => {},
  // (可选) 指定请求url的前缀 方便代理请求
  // apiPrefix: "/test_api/prefix",
});

// open 异步 先关闭再开始建立连接 (可选参数: protocol = type 选择协议(type = "auto" | "webrtc" | "ws-bvrtc") 不填默认为auto)
install.open(type);

Vue 示例

<template>
  <div ref="testRef" class="container"></div>
  <div ref="test2Ref" class="container2"></div>
  <button @click="close">关闭</button>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";
import { PuPlayer, IPuPlayerInstance } from "@besovideo/webrtc-player";
import "@besovideo/webrtc-player/dist/main.es.css";

export default defineComponent({
  name: "Test",
  props: {
    // 设备id号
    puId: {
      type: String,
      required: true,
    },
    // 设备通道号
    index: {
      type: Number,
      required: true,
    },
  },
  setup(props) {
    const testRef = ref(null);
    const test2Ref = ref(null);
    const instanceRef = ref<IPuPlayerInstance | null>(null);

    const init = async () => {
      const { instance } = PuPlayer({
        container: testRef.value,
        puOption: { id: props.puId, index: props.index },
        token:
          "Y3UrQ1VfYWRtaW4rYWRtaW4rMTQzOSsxOTMwMTUrMTYyNTIwMjU3OCthN2I0Y2JiZDliMzkwZWUy",
      });
      console.log("初始化播放器完成:", instance);
      instanceRef.value = instance;

      try {
        await instance.open();
      } catch (e) {}

      setTimeout(() => {
        // 测试移动到另一个容器内
        console.log("移动节点");
        instance.moveTo(test2Ref.value);
      }, 5000);
    };

    onMounted(() => {
      init();
    });

    return {
      testRef,
      test2Ref,
      close: () => instanceRef.value?.close(),
    };
  },
});
</script>

<style lang="scss" scoped>
.container {
  height: 300px;
}
</style>

特别说明

  • 项目是原生 JS、JQuery 写的,项目中没有导入导出功能的,可以使用暴露出来的"bvPlayer"实例对象进行使用

  • 在项目中引入 besovideo/webrtc-player dist 文件夹下面的"main.browser.css"和"main.browser.js"两个文件

<!DOCTYPE html>
<html lang="en">
  <head>
    <link href="./main.browser.css" type="text/css" rel="stylesheet" />
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./main.browser.js"/>
    
    <title>Document</title>
  </head>
  <body>
    
    
  </body>

  <script>
    const playerEle = document.createElement("div")
    playerEle.style.height = "300px"
    playerEle.style.width = "300px"
    playerEle.style.backgroundColor = "black"
    document.body.appendChild(playerEle);
      const {instance} = window.bvPlayer.PuPlayer({
        // (可选) 容器节点 注意一个容器内只能存在一个实例  当container为假值(包括false、null、undefined)时 将返回实例引用的dom节点 容器必须指定高度 参考高德地图
        container: playerEle,
        // 必填 设备选项
        puOption: {
          // 设备id
          id: "PU_123456",
          // 设备通道号
          index: 0,
        },
        // 必填 用户授权令牌
        token: "Y3UrQ1VfYWRtestYDHYUAStest",
      });
      instance.open()
    </script>
</html>

升级 Upgrade

yarn upgrade @besovideo/webrtc-player@latest

开发 Dev

# 开发运行
yarn
yarn start

# 打包和发布(可直接使用 make publish )
# npm login / yarn login
yarn version
yarn build
yarn publish
# 版本号按照 Major.Minor.Patch 规范
# 可参考https://www.jianshu.com/p/c675121a8bfd

环境变量切换方式

0.8.70

25 days ago

0.8.69

1 month ago

0.8.68

1 month ago

0.8.67

2 months ago

0.8.66

2 months ago

0.8.65

2 months ago

0.8.64

2 months ago

0.8.63

3 months ago

0.8.62

4 months ago

0.8.61

4 months ago

0.8.60

4 months ago

0.8.59

4 months ago

0.8.58

5 months ago

0.8.56

5 months ago

0.8.55

5 months ago

0.8.57

5 months ago

0.8.54

5 months ago

0.8.53

5 months ago

0.8.52

7 months ago

0.8.51

7 months ago

0.8.50

8 months ago

0.8.45

9 months ago

0.8.44

9 months ago

0.8.47

9 months ago

0.8.46

9 months ago

0.8.41

10 months ago

0.8.40

10 months ago

0.8.43

9 months ago

0.8.42

10 months ago

0.8.49

9 months ago

0.8.48

9 months ago

0.8.39

1 year ago

0.8.34

1 year ago

0.8.33

1 year ago

0.8.36

1 year ago

0.8.32

1 year ago

0.8.31

1 year ago

0.8.38

1 year ago

0.8.37

1 year ago

0.8.30

1 year ago

0.8.27

1 year ago

0.8.29

1 year ago

0.8.28

1 year ago

0.8.26

1 year ago

0.8.23

2 years ago

0.8.22

2 years ago

0.8.25

1 year ago

0.8.24

2 years ago

0.8.21

2 years ago

0.8.20

2 years ago

0.8.14

2 years ago

0.8.13

2 years ago

0.8.19

2 years ago

0.8.16

2 years ago

0.8.15

2 years ago

0.8.18

2 years ago

0.8.17

2 years ago

0.8.12

2 years ago

0.8.11

2 years ago

0.8.9

2 years ago

0.8.8

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.4.8

2 years ago

0.8.7

2 years ago

0.8.6

2 years ago

0.7.2

2 years ago

0.3.6

2 years ago

0.7.1

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.7.3

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.7.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.8.1

2 years ago

0.4.5

2 years ago

0.8.0

2 years ago

0.4.4

2 years ago

0.8.3

2 years ago

0.4.7

2 years ago

0.8.2

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.3

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.5.3

2 years ago

0.5.5

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.3.9

2 years ago

0.3.10

2 years ago

0.8.10

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago

0.2.7

3 years ago

0.2.9

2 years ago

0.2.8

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.6

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.0.40

3 years ago

0.0.41

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.39

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.1.0

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.25

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.26

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.22

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago