@wetspace/wetrtc 1.0.0
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/LICENSE +21 -0
- package/README.md +127 -0
- package/package.json +42 -0
- package/src/index.ts +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 想要飞翔的猪
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# WetRTC
|
|
2
|
+
> 全称 @wetspace/webrtc
|
|
3
|
+
|
|
4
|
+
#### 介绍
|
|
5
|
+
一个基于webRTC的库,简化了使用流程。使得webRTC开发更为友好快捷
|
|
6
|
+
|
|
7
|
+
#### 核心功能
|
|
8
|
+
|
|
9
|
+
1. b2b点对点视频连接功能
|
|
10
|
+
2. b2b文件数据传输功能
|
|
11
|
+
3. 本地视频/语言流捕获上传给中间服务器
|
|
12
|
+
4. 本地视频/语言流录制和截取
|
|
13
|
+
|
|
14
|
+
## 基本使用
|
|
15
|
+
|
|
16
|
+
最开始,先实例化`WetRTC`
|
|
17
|
+
```javascript
|
|
18
|
+
import { WetRTC } from '@wetspace/wetrtc';
|
|
19
|
+
const instance = new WetRTC();
|
|
20
|
+
```
|
|
21
|
+
### 创建点对点连接
|
|
22
|
+
#### 1. 创建一个捕获的流房间
|
|
23
|
+
这是很重要的一步,有捕获了流,才能按业务需求,把流推入到连接
|
|
24
|
+
|
|
25
|
+
在创建捕获流的房间的过程中,会检测可用设备,因为考虑到即便是没有音视频输入,只是捕获不到流,对方无法看到视频而已,因此,该函数接受一个回调函数,接受一个参数,参数就是当前音视频的可用输入设备,业务如何处理就交给使用者
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
/**
|
|
29
|
+
* @param { Object } params 回调参数
|
|
30
|
+
* @param { MediaDeviceInfo[] } params.audioinput
|
|
31
|
+
* @param { MediaDeviceInfo[] } params.videoinput
|
|
32
|
+
**/
|
|
33
|
+
instance.createStreamRoom(callback) // callback可选
|
|
34
|
+
```
|
|
35
|
+
### 发起连接请求
|
|
36
|
+
发起通讯连接,直接使用`instance.connect(options)`即可,内置默认参数
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
/**
|
|
40
|
+
* @param { Object } options 连接配置,属性均可选,默认如下
|
|
41
|
+
* @param { string | number } params.id 连接id
|
|
42
|
+
* @param { RTCConfiguration } params.configuration
|
|
43
|
+
* 建立连接发送offer回调
|
|
44
|
+
* @param { ( params: RTCSessionDescriptionInit)=>void } params.sendOffer
|
|
45
|
+
* 建立连接发送Candidate回调
|
|
46
|
+
* @param { ( params: RTCIceCandidate)=>void } params.sendCandidate
|
|
47
|
+
* @param { HTMLVideoElement } params.remoteVideoPlay 显示远程视频流
|
|
48
|
+
* @param { HTMLAudioElement} params.remoteAudioPlay 显示远程音频流
|
|
49
|
+
**/
|
|
50
|
+
{
|
|
51
|
+
configuration:{
|
|
52
|
+
iceServers:[{
|
|
53
|
+
urls: 'stun:stun.l.google.com:19302'
|
|
54
|
+
}],
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
如果业务上有需要显示本地流视频业务,可以调用`instance.openLocalVideoOrAudio(localVideo)`,localVideo是显示本地流的视频DOM
|
|
59
|
+
|
|
60
|
+
**注意:**
|
|
61
|
+
对于主动发起方的远程连接是需要提供`sendCandidate `,对于应答连接则不需要,应答连接只需要在连接后立即`applyAnswer`即可
|
|
62
|
+
|
|
63
|
+
完整示例代码如下:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
const connect = ( options = {
|
|
67
|
+
sendCandidate:(candidate)=>{sendMsg(candidate)},
|
|
68
|
+
sendOffer:(sdp)=>{sendMsg(sdp)},
|
|
69
|
+
remoteVideoPlay,
|
|
70
|
+
})=>{
|
|
71
|
+
instance.connect(Object.assign(options))
|
|
72
|
+
// 可选,如果业务有把本地视频流展示出来的需求
|
|
73
|
+
if(localVideo){
|
|
74
|
+
instance.openLocalVideoOrAudio(localVideo)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 信令交换必要信息流程
|
|
80
|
+
|
|
81
|
+
发起连接了,这时候就是要响应`answer`,和响应`candidate`,这里本sdk提供了2个方法`applyAnswer`,用于应答,接受一个点对点对象`RTCPeerConnection`,和用于发送`answer(sdp)`的回调函数;另一个就是`addIceCandidate`,是用来添加网络候选的,接受一个点对点对象`RTCPeerConnection`和`RTCIceCandidateInit`类型的参数
|
|
82
|
+
```javascript
|
|
83
|
+
import { applyAnswer, addIceCandidate} from '@wetspace/wetrtc'
|
|
84
|
+
...
|
|
85
|
+
switch (message.action) {
|
|
86
|
+
case "answer":
|
|
87
|
+
applyAnswer(RTCPeerConnection,message.answer);
|
|
88
|
+
break;
|
|
89
|
+
case "candidate":
|
|
90
|
+
addIceCandidate(RTCPeerConnection,message.candidate);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
...
|
|
94
|
+
```
|
|
95
|
+
### 关闭连接
|
|
96
|
+
|
|
97
|
+
#### 1.1 关闭点对点连接
|
|
98
|
+
使用`instance.disconnect()`,如果没有入参,则关闭全部连接,如果有入参id,则关闭以该id建立点对点连接
|
|
99
|
+
```javascript
|
|
100
|
+
instance.disconnect()
|
|
101
|
+
instance.disconnect('uuid')
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 1.2 关闭流房间
|
|
105
|
+
|
|
106
|
+
关闭流房间,是当你不采集音视频流,或者当这个对讲功能完全关闭的时候进行关闭处理,这样就能释放设备对流的捕获。如果不关闭,换一个应用,发起了WebRTC对讲则会导致设备被占用,从而导致捕获流失败
|
|
107
|
+
|
|
108
|
+
值得注意的是,关闭流房间不会导致对讲连接关闭,只是会导致一方无法获取对方的远程音视频
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
instance.closeStreamRoom()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 具体使用文档
|
|
115
|
+
|
|
116
|
+
[文档手册](https://wetspace.gitee.io/wetrtc/)
|
|
117
|
+
|
|
118
|
+
#### 补充
|
|
119
|
+
欢迎大家补充英文文档(虽然我也会补充,但是本人英语是个菜逼)
|
|
120
|
+
#### 特技
|
|
121
|
+
|
|
122
|
+
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
|
123
|
+
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
|
124
|
+
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
|
125
|
+
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
|
126
|
+
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
|
127
|
+
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wetspace/wetrtc",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "一个基于webRTC的库,简化了使用流程。使得webRTC开发更为友好快捷",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"module": "build/wetrtc.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "rollup -c -w",
|
|
9
|
+
"build": "rollup -c",
|
|
10
|
+
"docs:dev": "vuepress dev docs",
|
|
11
|
+
"docs:build": "vuepress build docs",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://gitee.com/wetspace/wetrtc"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"registry": "https://registry.npmjs.org/",
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"files":["README.md",""],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@babel/core": "^7.16.0",
|
|
27
|
+
"@rollup/plugin-babel": "^5.3.0",
|
|
28
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
29
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
30
|
+
"@rollup/plugin-replace": "^3.0.0",
|
|
31
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
32
|
+
"@types/lodash": "^4.14.178",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"rollup-plugin-uglify": "^6.0.4",
|
|
35
|
+
"tslib": "^2.3.1",
|
|
36
|
+
"typescript": "^4.5.2"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"rollup": "^2.60.1",
|
|
40
|
+
"vuepress": "^2.0.0-beta.27"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WetRTC } from './core/index';
|
|
2
|
+
import { getMediaStream, concatStream,filterStream} from './core/stream';
|
|
3
|
+
import { RecordVideoOrAudio } from './lib/record';
|
|
4
|
+
import { getUsAbleDevices } from './core/devices';
|
|
5
|
+
import { getTracks } from './core/tracks';
|
|
6
|
+
import { connectRTC, createLocalPlayer} from './core/create';
|
|
7
|
+
import { applyOffer, applyAnswer, addIceCandidate } from './core/actions';
|
|
8
|
+
|
|
9
|
+
export{
|
|
10
|
+
WetRTC, // rtc连接类,一个主体一个WetRTC连接,其他参与者都是wetChildRTC创建点对点
|
|
11
|
+
getMediaStream,// 获取媒体流
|
|
12
|
+
concatStream,// 合并流
|
|
13
|
+
filterStream,// 按video/audio过滤流
|
|
14
|
+
RecordVideoOrAudio,// 录制
|
|
15
|
+
getUsAbleDevices,// 获取可用设备
|
|
16
|
+
getTracks,// 获取流输入
|
|
17
|
+
connectRTC, // 创建点对点连接
|
|
18
|
+
createLocalPlayer, // 将本地视频流添加到视频
|
|
19
|
+
applyOffer, // 提供offer SDP
|
|
20
|
+
applyAnswer, // 提供answer SDP 或者应答设置
|
|
21
|
+
addIceCandidate // 给RTCPeerConnection实例设置候选者
|
|
22
|
+
}
|