@besovideo/webrtc-player 0.7.1 → 0.7.2

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,268 +1,268 @@
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
-
78
- // setVideoFit 更改videoFit
79
- instance.setVideoFit("contain");
80
- // setToken 更改请求时的token
81
- instance.setToken("newTTTTToken");
82
- // setPuOption 更改请求的设备信息
83
- instance.setPuOption({
84
- id: "PU_12345test",
85
- index: 123,
86
- });
87
- // setApiPrefix 更改请求时的url前缀
88
- instance.setApiPrefix("/测试改前缀");
89
- // open 异步 先关闭再开始建立连接 (可选参数: muted:boolean = false 是否静音打开)
90
- instance.open();
91
- // close 异步 释放dialog 并关闭 当前的 peer connection
92
- instance.close();
93
- // destroy 执行close 并从dom移除PuPlayer节点
94
- instance.destroy();
95
- // moveTo 将节点移动至新的容器
96
- instance.moveTo(document.getElementById("new_player_container"));
97
- // getCurrentContainer 获得当前所在的容器
98
- instance.getCurrentContainer();
99
- // hidden 隐藏 异步 (可选参数: muted?:boolean 是否静音 可不传)
100
- instance.hidden(true);
101
- // display 显示 (可选参数: muted?:boolean 是否静音 可不传)
102
- instance.display();
103
- // play 播放 异步
104
- instance.play();
105
- // mute 切换静音 (可选参数: muted:boolean = false 是否静音)
106
- instance.mute(true);
107
- // 获取puPlayer的div
108
- instance.getPlayerElement();
109
- // 获取内部引用的video元素
110
- instance.getVideoElement();
111
-
112
- // clearAllDialog 异步 释放全部打开的dialog 不管是音视频还是对讲
113
- clearAllDialog();
114
- ```
115
-
116
- **对讲**
117
-
118
- ```typescript
119
- import {
120
- Intercom,
121
- IIntercomProps,
122
- IIntercomInstance,
123
- } from "@besovideo/webrtc-player";
124
- import "@besovideo/webrtc-player/dist/main.es.css";
125
-
126
- const { instance } = Intercom({
127
- // 必填 设备选项
128
- puOption: {
129
- // 设备id
130
- id: "PU_123456",
131
- // 设备通道号
132
- index: 0,
133
- },
134
- // 必填 用户授权令牌
135
- token: "Y3UrQ1VfYWRtestYDHYUAStest",
136
- // (可选) 连接建立后回调
137
- onConnected: () => {},
138
- // (可选) 连接建立失败时的回调
139
- onConnectedFailed: () => {},
140
- // (可选) 连接断开后回调
141
- onDisConnected: () => {},
142
- //(可选) 无法获取用户麦克风时
143
- onGetUserMediaFailed: () => {},
144
- // (可选) 指定请求url的前缀 方便代理请求
145
- // apiPrefix: "/test_api/prefix",
146
- });
147
- ```
148
-
149
- **会议**
150
-
151
- ```typescript
152
- import {
153
- Conference,
154
- IConferenceProps,
155
- IConferenceInstance,
156
- } from "@besovideo/webrtc-player";
157
- import "@besovideo/webrtc-player/dist/main.es.css";
158
-
159
- const { instance } = Conference({
160
- // 必填 设备选项
161
- confOption: {
162
- // 会议id
163
- id: "test89312",
164
- // 会议成员ID
165
- index: 0,
166
- },
167
- // 必填 用户授权令牌
168
- token: "Y3UrQ1VfYWRtestYDHYUAStest",
169
- // (可选) 连接建立后回调
170
- onConnected: () => {},
171
- // (可选) 连接建立失败时的回调
172
- onConnectedFailed: () => {},
173
- // (可选) 连接断开后回调
174
- onDisConnected: () => {},
175
- //(可选) 无法获取用户麦克风时
176
- onGetUserMediaFailed: () => {},
177
- // (可选) 指定请求url的前缀 方便代理请求
178
- // apiPrefix: "/test_api/prefix",
179
- });
180
- ```
181
-
182
- **Vue 示例**
183
-
184
- ```vue
185
- <template>
186
- <div ref="testRef" class="container"></div>
187
- <div ref="test2Ref" class="container2"></div>
188
- <button @click="close">关闭</button>
189
- </template>
190
-
191
- <script lang="ts">
192
- import { defineComponent, onMounted, ref } from "vue";
193
- import { PuPlayer, IPuPlayerInstance } from "@besovideo/webrtc-player";
194
- import "@besovideo/webrtc-player/dist/main.es.css";
195
-
196
- export default defineComponent({
197
- name: "Test",
198
- props: {
199
- // 设备id号
200
- puId: {
201
- type: String,
202
- required: true,
203
- },
204
- // 设备通道号
205
- index: {
206
- type: Number,
207
- required: true,
208
- },
209
- },
210
- setup(props) {
211
- const testRef = ref(null);
212
- const test2Ref = ref(null);
213
- const instanceRef = ref<IPuPlayerInstance | null>(null);
214
-
215
- const init = async () => {
216
- const { instance } = PuPlayer({
217
- container: testRef.value,
218
- puOption: { id: props.puId, index: props.index },
219
- token:
220
- "Y3UrQ1VfYWRtaW4rYWRtaW4rMTQzOSsxOTMwMTUrMTYyNTIwMjU3OCthN2I0Y2JiZDliMzkwZWUy",
221
- });
222
- console.log("初始化播放器完成:", instance);
223
- instanceRef.value = instance;
224
-
225
- try {
226
- await instance.open();
227
- } catch (e) {}
228
-
229
- setTimeout(() => {
230
- // 测试移动到另一个容器内
231
- console.log("移动节点");
232
- instance.moveTo(test2Ref.value);
233
- }, 5000);
234
- };
235
-
236
- onMounted(() => {
237
- init();
238
- });
239
-
240
- return {
241
- testRef,
242
- test2Ref,
243
- close: () => instanceRef.value?.close(),
244
- };
245
- },
246
- });
247
- </script>
248
-
249
- <style lang="scss" scoped>
250
- .container {
251
- height: 300px;
252
- }
253
- </style>
254
- ```
255
-
256
- ## 开发 Dev
257
-
258
- ```shell
259
- # 开发运行
260
- yarn
261
- yarn start
262
-
263
- # 打包和发布
264
- make publish
265
-
266
- ```
267
-
268
- [环境变量切换方式](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
+
78
+ // setVideoFit 更改videoFit
79
+ instance.setVideoFit("contain");
80
+ // setToken 更改请求时的token
81
+ instance.setToken("newTTTTToken");
82
+ // setPuOption 更改请求的设备信息
83
+ instance.setPuOption({
84
+ id: "PU_12345test",
85
+ index: 123,
86
+ });
87
+ // setApiPrefix 更改请求时的url前缀
88
+ instance.setApiPrefix("/测试改前缀");
89
+ // open 异步 先关闭再开始建立连接 (可选参数: muted:boolean = false 是否静音打开)
90
+ instance.open();
91
+ // close 异步 释放dialog 并关闭 当前的 peer connection
92
+ instance.close();
93
+ // destroy 执行close 并从dom移除PuPlayer节点
94
+ instance.destroy();
95
+ // moveTo 将节点移动至新的容器
96
+ instance.moveTo(document.getElementById("new_player_container"));
97
+ // getCurrentContainer 获得当前所在的容器
98
+ instance.getCurrentContainer();
99
+ // hidden 隐藏 异步 (可选参数: muted?:boolean 是否静音 可不传)
100
+ instance.hidden(true);
101
+ // display 显示 (可选参数: muted?:boolean 是否静音 可不传)
102
+ instance.display();
103
+ // play 播放 异步
104
+ instance.play();
105
+ // mute 切换静音 (可选参数: muted:boolean = false 是否静音)
106
+ instance.mute(true);
107
+ // 获取puPlayer的div
108
+ instance.getPlayerElement();
109
+ // 获取内部引用的video元素
110
+ instance.getVideoElement();
111
+
112
+ // clearAllDialog 异步 释放全部打开的dialog 不管是音视频还是对讲
113
+ clearAllDialog();
114
+ ```
115
+
116
+ **对讲**
117
+
118
+ ```typescript
119
+ import {
120
+ Intercom,
121
+ IIntercomProps,
122
+ IIntercomInstance,
123
+ } from "@besovideo/webrtc-player";
124
+ import "@besovideo/webrtc-player/dist/main.es.css";
125
+
126
+ const { instance } = Intercom({
127
+ // 必填 设备选项
128
+ puOption: {
129
+ // 设备id
130
+ id: "PU_123456",
131
+ // 设备通道号
132
+ index: 0,
133
+ },
134
+ // 必填 用户授权令牌
135
+ token: "Y3UrQ1VfYWRtestYDHYUAStest",
136
+ // (可选) 连接建立后回调
137
+ onConnected: () => {},
138
+ // (可选) 连接建立失败时的回调
139
+ onConnectedFailed: () => {},
140
+ // (可选) 连接断开后回调
141
+ onDisConnected: () => {},
142
+ //(可选) 无法获取用户麦克风时
143
+ onGetUserMediaFailed: () => {},
144
+ // (可选) 指定请求url的前缀 方便代理请求
145
+ // apiPrefix: "/test_api/prefix",
146
+ });
147
+ ```
148
+
149
+ **会议**
150
+
151
+ ```typescript
152
+ import {
153
+ Conference,
154
+ IConferenceProps,
155
+ IConferenceInstance,
156
+ } from "@besovideo/webrtc-player";
157
+ import "@besovideo/webrtc-player/dist/main.es.css";
158
+
159
+ const { instance } = Conference({
160
+ // 必填 设备选项
161
+ confOption: {
162
+ // 会议id
163
+ id: "test89312",
164
+ // 会议成员ID
165
+ index: 0,
166
+ },
167
+ // 必填 用户授权令牌
168
+ token: "Y3UrQ1VfYWRtestYDHYUAStest",
169
+ // (可选) 连接建立后回调
170
+ onConnected: () => {},
171
+ // (可选) 连接建立失败时的回调
172
+ onConnectedFailed: () => {},
173
+ // (可选) 连接断开后回调
174
+ onDisConnected: () => {},
175
+ //(可选) 无法获取用户麦克风时
176
+ onGetUserMediaFailed: () => {},
177
+ // (可选) 指定请求url的前缀 方便代理请求
178
+ // apiPrefix: "/test_api/prefix",
179
+ });
180
+ ```
181
+
182
+ **Vue 示例**
183
+
184
+ ```vue
185
+ <template>
186
+ <div ref="testRef" class="container"></div>
187
+ <div ref="test2Ref" class="container2"></div>
188
+ <button @click="close">关闭</button>
189
+ </template>
190
+
191
+ <script lang="ts">
192
+ import { defineComponent, onMounted, ref } from "vue";
193
+ import { PuPlayer, IPuPlayerInstance } from "@besovideo/webrtc-player";
194
+ import "@besovideo/webrtc-player/dist/main.es.css";
195
+
196
+ export default defineComponent({
197
+ name: "Test",
198
+ props: {
199
+ // 设备id号
200
+ puId: {
201
+ type: String,
202
+ required: true,
203
+ },
204
+ // 设备通道号
205
+ index: {
206
+ type: Number,
207
+ required: true,
208
+ },
209
+ },
210
+ setup(props) {
211
+ const testRef = ref(null);
212
+ const test2Ref = ref(null);
213
+ const instanceRef = ref<IPuPlayerInstance | null>(null);
214
+
215
+ const init = async () => {
216
+ const { instance } = PuPlayer({
217
+ container: testRef.value,
218
+ puOption: { id: props.puId, index: props.index },
219
+ token:
220
+ "Y3UrQ1VfYWRtaW4rYWRtaW4rMTQzOSsxOTMwMTUrMTYyNTIwMjU3OCthN2I0Y2JiZDliMzkwZWUy",
221
+ });
222
+ console.log("初始化播放器完成:", instance);
223
+ instanceRef.value = instance;
224
+
225
+ try {
226
+ await instance.open();
227
+ } catch (e) {}
228
+
229
+ setTimeout(() => {
230
+ // 测试移动到另一个容器内
231
+ console.log("移动节点");
232
+ instance.moveTo(test2Ref.value);
233
+ }, 5000);
234
+ };
235
+
236
+ onMounted(() => {
237
+ init();
238
+ });
239
+
240
+ return {
241
+ testRef,
242
+ test2Ref,
243
+ close: () => instanceRef.value?.close(),
244
+ };
245
+ },
246
+ });
247
+ </script>
248
+
249
+ <style lang="scss" scoped>
250
+ .container {
251
+ height: 300px;
252
+ }
253
+ </style>
254
+ ```
255
+
256
+ ## 开发 Dev
257
+
258
+ ```shell
259
+ # 开发运行
260
+ yarn
261
+ yarn start
262
+
263
+ # 打包和发布
264
+ make publish
265
+
266
+ ```
267
+
268
+ [环境变量切换方式](https://github.com/entropitor/dotenv-cli/pull/44)