@besovideo/webrtc-player 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,290 +1,290 @@
1
- # @besovideo/webrtc-player
2
-
3
- ![npm](https://img.shields.io/npm/v/@besovideo/webrtc-player) ![NPM](https://img.shields.io/npm/l/@besovideo/webrtc-player) ![npm](https://img.shields.io/npm/dt/@besovideo/webrtc-player)
4
-
5
- [![NPM](https://nodei.co/npm/@besovideo/webrtc-player.png)](https://nodei.co/npm/@besovideo/webrtc-player/)
6
-
7
- ## 简介 Introduction
8
-
9
- > 设备视频播放、对讲封装
10
-
11
- ## 安装 Installation
12
-
13
- **use npm**
14
-
15
- ```shell
16
- npm i @besovideo/webrtc-player
17
- ```
18
-
19
- **use yarn**
20
-
21
- ```
22
- yarn add @besovideo/webrtc-player
23
- ```
24
-
25
- ## 示例 Example
26
-
27
- **视频**
28
-
29
- ```typescript
30
- import {
31
- PuPlayer,
32
- IPuPlayerProps,
33
- IPuPlayerInstance,
34
- clearAllDialog,
35
- } from "@besovideo/webrtc-player";
36
- import "@besovideo/webrtc-player/dist/main.es.css";
37
-
38
- const { instance } = PuPlayer({
39
- // (可选) 容器节点 注意一个容器内只能存在一个实例 当container为假值(包括false、null、undefined)时 将返回实例引用的dom节点 容器必须指定高度 参考高德地图
40
- container: document.getElementById("player_container"),
41
- // 必填 设备选项
42
- puOption: {
43
- // 设备id
44
- id: "PU_123456",
45
- // 设备通道号
46
- index: 0,
47
- },
48
- // 必填 用户授权令牌
49
- token: "Y3UrQ1VfYWRtestYDHYUAStest",
50
- // (可选) peer connection 连接媒体配置
51
- defaultMediaOption: {
52
- // 启用音频
53
- audio: true,
54
- // 启用视频
55
- video: true,
56
- },
57
- // (可选) 是否静音
58
- muted: false,
59
- // (可选) 指定video如何适应容器 (fill: 填充容器 ; contain :保持视频比例适应容器)
60
- videoFit: "fill",
61
- // (可选) 指定请求url路径前缀 可使用protocol+host 如:http://192.168.6.111:9780
62
- // apiPrefix: "/test_api/prefix",
63
-
64
- // (可选) 用于测试播放视频 (存在时优先使用url播放,为浏览器直接播放)
65
- // testUrl: "https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4",
66
- // (可选) 连接建立后回调
67
- onConnected: () => {},
68
- // (可选) 连接建立失败时的回调
69
- onConnectedFailed: () => {},
70
- // (可选) 连接断开后回调
71
- onDisConnected: () => {},
72
- // (可选) 双击是否全屏
73
- fullScreenOnDblclick: true,
74
- // (可选) 启用控制器
75
- enableController: false,
76
- // (可选) 禁用控制器的控制项 下面示例中禁用了云台控制
77
- disabledControls: ["ptzControl"],
78
- });
79
-
80
- // setVideoFit 更改videoFit
81
- instance.setVideoFit("contain");
82
- // setToken 更改请求时的token
83
- instance.setToken("newTTTTToken");
84
- // setPuOption 更改请求的设备信息
85
- instance.setPuOption({
86
- id: "PU_12345test",
87
- index: 123,
88
- });
89
- // setApiPrefix 更改请求时的url前缀
90
- instance.setApiPrefix("/测试改前缀");
91
- // open 异步 先关闭再开始建立连接 (可选参数: muted:boolean = false 是否静音打开)
92
- instance.open();
93
- // close 异步 释放dialog 并关闭 当前的 peer connection
94
- instance.close();
95
- // destroy 执行close 并从dom移除PuPlayer节点
96
- instance.destroy();
97
- // moveTo 将节点移动至新的容器
98
- instance.moveTo(document.getElementById("new_player_container"));
99
- // getCurrentContainer 获得当前所在的容器
100
- instance.getCurrentContainer();
101
- // hidden 隐藏 异步 (可选参数: muted?:boolean 是否静音 可不传)
102
- instance.hidden(true);
103
- // display 显示 (可选参数: muted?:boolean 是否静音 可不传)
104
- instance.display();
105
- // play 播放 异步
106
- instance.play();
107
- // mute 切换静音 (可选参数: muted:boolean = false 是否静音)
108
- instance.mute(true);
109
- // 获取puPlayer的div
110
- instance.getPlayerElement();
111
- // 获取内部引用的video元素
112
- instance.getVideoElement();
113
-
114
- // clearAllDialog 异步 释放全部打开的dialog 不管是音视频还是对讲
115
- clearAllDialog();
116
- ```
117
-
118
- - Controls 控制项列表
119
-
120
- ```typescript
121
- // 全部控制项
122
- [
123
- "volume",
124
- "volumeSlider",
125
- "information",
126
- "screenshot",
127
- "record",
128
- "fullscreen",
129
- "rotate",
130
- "ptzControl",
131
- ]
132
- // 在创建实例时 传入参数disabledControls数组 可关闭相关功能
133
- // 如不使用全屏按钮、云台控制器
134
- disabledControls: ["fullscreen", "ptzControl"]
135
-
136
- ```
137
-
138
- **对讲**
139
-
140
- ```typescript
141
- import {
142
- Intercom,
143
- IIntercomProps,
144
- IIntercomInstance,
145
- } from "@besovideo/webrtc-player";
146
- import "@besovideo/webrtc-player/dist/main.es.css";
147
-
148
- const { instance } = Intercom({
149
- // 必填 设备选项
150
- puOption: {
151
- // 设备id
152
- id: "PU_123456",
153
- // 设备通道号
154
- index: 0,
155
- },
156
- // 必填 用户授权令牌
157
- token: "Y3UrQ1VfYWRtestYDHYUAStest",
158
- // (可选) 连接建立后回调
159
- onConnected: () => {},
160
- // (可选) 连接建立失败时的回调
161
- onConnectedFailed: () => {},
162
- // (可选) 连接断开后回调
163
- onDisConnected: () => {},
164
- //(可选) 无法获取用户麦克风时
165
- onGetUserMediaFailed: () => {},
166
- // (可选) 指定请求url的前缀 方便代理请求
167
- // apiPrefix: "/test_api/prefix",
168
- });
169
- ```
170
-
171
- **会议**
172
-
173
- ```typescript
174
- import {
175
- Conference,
176
- IConferenceProps,
177
- IConferenceInstance,
178
- } from "@besovideo/webrtc-player";
179
- import "@besovideo/webrtc-player/dist/main.es.css";
180
-
181
- const { instance } = Conference({
182
- // 必填 设备选项
183
- confOption: {
184
- // 会议id
185
- id: "test89312",
186
- // 会议成员ID
187
- index: 0,
188
- },
189
- // 必填 用户授权令牌
190
- token: "Y3UrQ1VfYWRtestYDHYUAStest",
191
- // (可选) 连接建立后回调
192
- onConnected: () => {},
193
- // (可选) 连接建立失败时的回调
194
- onConnectedFailed: () => {},
195
- // (可选) 连接断开后回调
196
- onDisConnected: () => {},
197
- //(可选) 无法获取用户麦克风时
198
- onGetUserMediaFailed: () => {},
199
- // (可选) 指定请求url的前缀 方便代理请求
200
- // apiPrefix: "/test_api/prefix",
201
- });
202
- ```
203
-
204
- **Vue 示例**
205
-
206
- ```vue
207
- <template>
208
- <div ref="testRef" class="container"></div>
209
- <div ref="test2Ref" class="container2"></div>
210
- <button @click="close">关闭</button>
211
- </template>
212
-
213
- <script lang="ts">
214
- import { defineComponent, onMounted, ref } from "vue";
215
- import { PuPlayer, IPuPlayerInstance } from "@besovideo/webrtc-player";
216
- import "@besovideo/webrtc-player/dist/main.es.css";
217
-
218
- export default defineComponent({
219
- name: "Test",
220
- props: {
221
- // 设备id号
222
- puId: {
223
- type: String,
224
- required: true,
225
- },
226
- // 设备通道号
227
- index: {
228
- type: Number,
229
- required: true,
230
- },
231
- },
232
- setup(props) {
233
- const testRef = ref(null);
234
- const test2Ref = ref(null);
235
- const instanceRef = ref<IPuPlayerInstance | null>(null);
236
-
237
- const init = async () => {
238
- const { instance } = PuPlayer({
239
- container: testRef.value,
240
- puOption: { id: props.puId, index: props.index },
241
- token:
242
- "Y3UrQ1VfYWRtaW4rYWRtaW4rMTQzOSsxOTMwMTUrMTYyNTIwMjU3OCthN2I0Y2JiZDliMzkwZWUy",
243
- });
244
- console.log("初始化播放器完成:", instance);
245
- instanceRef.value = instance;
246
-
247
- try {
248
- await instance.open();
249
- } catch (e) {}
250
-
251
- setTimeout(() => {
252
- // 测试移动到另一个容器内
253
- console.log("移动节点");
254
- instance.moveTo(test2Ref.value);
255
- }, 5000);
256
- };
257
-
258
- onMounted(() => {
259
- init();
260
- });
261
-
262
- return {
263
- testRef,
264
- test2Ref,
265
- close: () => instanceRef.value?.close(),
266
- };
267
- },
268
- });
269
- </script>
270
-
271
- <style lang="scss" scoped>
272
- .container {
273
- height: 300px;
274
- }
275
- </style>
276
- ```
277
-
278
- ## 开发 Dev
279
-
280
- ```shell
281
- # 开发运行
282
- yarn
283
- yarn start
284
-
285
- # 打包和发布
286
- make publish
287
-
288
- ```
289
-
290
- [环境变量切换方式](https://github.com/entropitor/dotenv-cli/pull/44)
1
+ # @besovideo/webrtc-player
2
+
3
+ ![npm](https://img.shields.io/npm/v/@besovideo/webrtc-player) ![NPM](https://img.shields.io/npm/l/@besovideo/webrtc-player) ![npm](https://img.shields.io/npm/dt/@besovideo/webrtc-player)
4
+
5
+ [![NPM](https://nodei.co/npm/@besovideo/webrtc-player.png)](https://nodei.co/npm/@besovideo/webrtc-player/)
6
+
7
+ ## 简介 Introduction
8
+
9
+ > 设备视频播放、对讲封装
10
+
11
+ ## 安装 Installation
12
+
13
+ **use npm**
14
+
15
+ ```shell
16
+ npm i @besovideo/webrtc-player
17
+ ```
18
+
19
+ **use yarn**
20
+
21
+ ```
22
+ yarn add @besovideo/webrtc-player
23
+ ```
24
+
25
+ ## 示例 Example
26
+
27
+ **视频**
28
+
29
+ ```typescript
30
+ import {
31
+ PuPlayer,
32
+ IPuPlayerProps,
33
+ IPuPlayerInstance,
34
+ clearAllDialog,
35
+ } from "@besovideo/webrtc-player";
36
+ import "@besovideo/webrtc-player/dist/main.es.css";
37
+
38
+ const { instance } = PuPlayer({
39
+ // (可选) 容器节点 注意一个容器内只能存在一个实例 当container为假值(包括false、null、undefined)时 将返回实例引用的dom节点 容器必须指定高度 参考高德地图
40
+ container: document.getElementById("player_container"),
41
+ // 必填 设备选项
42
+ puOption: {
43
+ // 设备id
44
+ id: "PU_123456",
45
+ // 设备通道号
46
+ index: 0,
47
+ },
48
+ // 必填 用户授权令牌
49
+ token: "Y3UrQ1VfYWRtestYDHYUAStest",
50
+ // (可选) peer connection 连接媒体配置
51
+ defaultMediaOption: {
52
+ // 启用音频
53
+ audio: true,
54
+ // 启用视频
55
+ video: true,
56
+ },
57
+ // (可选) 是否静音
58
+ muted: false,
59
+ // (可选) 指定video如何适应容器 (fill: 填充容器 ; contain :保持视频比例适应容器)
60
+ videoFit: "fill",
61
+ // (可选) 指定请求url路径前缀 可使用protocol+host 如:http://192.168.6.111:9780
62
+ // apiPrefix: "/test_api/prefix",
63
+
64
+ // (可选) 用于测试播放视频 (存在时优先使用url播放,为浏览器直接播放)
65
+ // testUrl: "https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4",
66
+ // (可选) 连接建立后回调
67
+ onConnected: () => {},
68
+ // (可选) 连接建立失败时的回调
69
+ onConnectedFailed: () => {},
70
+ // (可选) 连接断开后回调
71
+ onDisConnected: () => {},
72
+ // (可选) 双击是否全屏
73
+ fullScreenOnDblclick: true,
74
+ // (可选) 启用控制器
75
+ enableController: false,
76
+ // (可选) 禁用控制器的控制项 下面示例中禁用了云台控制
77
+ disabledControls: ["ptzControl"],
78
+ });
79
+
80
+ // setVideoFit 更改videoFit
81
+ instance.setVideoFit("contain");
82
+ // setToken 更改请求时的token
83
+ instance.setToken("newTTTTToken");
84
+ // setPuOption 更改请求的设备信息
85
+ instance.setPuOption({
86
+ id: "PU_12345test",
87
+ index: 123,
88
+ });
89
+ // setApiPrefix 更改请求时的url前缀
90
+ instance.setApiPrefix("/测试改前缀");
91
+ // open 异步 先关闭再开始建立连接 (可选参数: muted:boolean = false 是否静音打开)
92
+ instance.open();
93
+ // close 异步 释放dialog 并关闭 当前的 peer connection
94
+ instance.close();
95
+ // destroy 执行close 并从dom移除PuPlayer节点
96
+ instance.destroy();
97
+ // moveTo 将节点移动至新的容器
98
+ instance.moveTo(document.getElementById("new_player_container"));
99
+ // getCurrentContainer 获得当前所在的容器
100
+ instance.getCurrentContainer();
101
+ // hidden 隐藏 异步 (可选参数: muted?:boolean 是否静音 可不传)
102
+ instance.hidden(true);
103
+ // display 显示 (可选参数: muted?:boolean 是否静音 可不传)
104
+ instance.display();
105
+ // play 播放 异步
106
+ instance.play();
107
+ // mute 切换静音 (可选参数: muted:boolean = false 是否静音)
108
+ instance.mute(true);
109
+ // 获取puPlayer的div
110
+ instance.getPlayerElement();
111
+ // 获取内部引用的video元素
112
+ instance.getVideoElement();
113
+
114
+ // clearAllDialog 异步 释放全部打开的dialog 不管是音视频还是对讲
115
+ clearAllDialog();
116
+ ```
117
+
118
+ - Controls 控制项列表
119
+
120
+ ```typescript
121
+ // 全部控制项
122
+ [
123
+ "volume",
124
+ "volumeSlider",
125
+ "information",
126
+ "screenshot",
127
+ "record",
128
+ "fullscreen",
129
+ "rotate",
130
+ "ptzControl",
131
+ ]
132
+ // 在创建实例时 传入参数disabledControls数组 可关闭相关功能
133
+ // 如不使用全屏按钮、云台控制器
134
+ disabledControls: ["fullscreen", "ptzControl"]
135
+
136
+ ```
137
+
138
+ **对讲**
139
+
140
+ ```typescript
141
+ import {
142
+ Intercom,
143
+ IIntercomProps,
144
+ IIntercomInstance,
145
+ } from "@besovideo/webrtc-player";
146
+ import "@besovideo/webrtc-player/dist/main.es.css";
147
+
148
+ const { instance } = Intercom({
149
+ // 必填 设备选项
150
+ puOption: {
151
+ // 设备id
152
+ id: "PU_123456",
153
+ // 设备通道号
154
+ index: 0,
155
+ },
156
+ // 必填 用户授权令牌
157
+ token: "Y3UrQ1VfYWRtestYDHYUAStest",
158
+ // (可选) 连接建立后回调
159
+ onConnected: () => {},
160
+ // (可选) 连接建立失败时的回调
161
+ onConnectedFailed: () => {},
162
+ // (可选) 连接断开后回调
163
+ onDisConnected: () => {},
164
+ //(可选) 无法获取用户麦克风时
165
+ onGetUserMediaFailed: () => {},
166
+ // (可选) 指定请求url的前缀 方便代理请求
167
+ // apiPrefix: "/test_api/prefix",
168
+ });
169
+ ```
170
+
171
+ **会议**
172
+
173
+ ```typescript
174
+ import {
175
+ Conference,
176
+ IConferenceProps,
177
+ IConferenceInstance,
178
+ } from "@besovideo/webrtc-player";
179
+ import "@besovideo/webrtc-player/dist/main.es.css";
180
+
181
+ const { instance } = Conference({
182
+ // 必填 设备选项
183
+ confOption: {
184
+ // 会议id
185
+ id: "test89312",
186
+ // 会议成员ID
187
+ index: 0,
188
+ },
189
+ // 必填 用户授权令牌
190
+ token: "Y3UrQ1VfYWRtestYDHYUAStest",
191
+ // (可选) 连接建立后回调
192
+ onConnected: () => {},
193
+ // (可选) 连接建立失败时的回调
194
+ onConnectedFailed: () => {},
195
+ // (可选) 连接断开后回调
196
+ onDisConnected: () => {},
197
+ //(可选) 无法获取用户麦克风时
198
+ onGetUserMediaFailed: () => {},
199
+ // (可选) 指定请求url的前缀 方便代理请求
200
+ // apiPrefix: "/test_api/prefix",
201
+ });
202
+ ```
203
+
204
+ **Vue 示例**
205
+
206
+ ```vue
207
+ <template>
208
+ <div ref="testRef" class="container"></div>
209
+ <div ref="test2Ref" class="container2"></div>
210
+ <button @click="close">关闭</button>
211
+ </template>
212
+
213
+ <script lang="ts">
214
+ import { defineComponent, onMounted, ref } from "vue";
215
+ import { PuPlayer, IPuPlayerInstance } from "@besovideo/webrtc-player";
216
+ import "@besovideo/webrtc-player/dist/main.es.css";
217
+
218
+ export default defineComponent({
219
+ name: "Test",
220
+ props: {
221
+ // 设备id号
222
+ puId: {
223
+ type: String,
224
+ required: true,
225
+ },
226
+ // 设备通道号
227
+ index: {
228
+ type: Number,
229
+ required: true,
230
+ },
231
+ },
232
+ setup(props) {
233
+ const testRef = ref(null);
234
+ const test2Ref = ref(null);
235
+ const instanceRef = ref<IPuPlayerInstance | null>(null);
236
+
237
+ const init = async () => {
238
+ const { instance } = PuPlayer({
239
+ container: testRef.value,
240
+ puOption: { id: props.puId, index: props.index },
241
+ token:
242
+ "Y3UrQ1VfYWRtaW4rYWRtaW4rMTQzOSsxOTMwMTUrMTYyNTIwMjU3OCthN2I0Y2JiZDliMzkwZWUy",
243
+ });
244
+ console.log("初始化播放器完成:", instance);
245
+ instanceRef.value = instance;
246
+
247
+ try {
248
+ await instance.open();
249
+ } catch (e) {}
250
+
251
+ setTimeout(() => {
252
+ // 测试移动到另一个容器内
253
+ console.log("移动节点");
254
+ instance.moveTo(test2Ref.value);
255
+ }, 5000);
256
+ };
257
+
258
+ onMounted(() => {
259
+ init();
260
+ });
261
+
262
+ return {
263
+ testRef,
264
+ test2Ref,
265
+ close: () => instanceRef.value?.close(),
266
+ };
267
+ },
268
+ });
269
+ </script>
270
+
271
+ <style lang="scss" scoped>
272
+ .container {
273
+ height: 300px;
274
+ }
275
+ </style>
276
+ ```
277
+
278
+ ## 开发 Dev
279
+
280
+ ```shell
281
+ # 开发运行
282
+ yarn
283
+ yarn start
284
+
285
+ # 打包和发布
286
+ make publish
287
+
288
+ ```
289
+
290
+ [环境变量切换方式](https://github.com/entropitor/dotenv-cli/pull/44)