omnirtc-web 0.0.1 → 0.0.6-beta
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 +90 -0
- package/dist/es-omnirtc-web.js +4 -4
- package/dist/omnirtc-web.js +2 -2
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
直播中台WebRTC SDK。如需接入,联系兰龙刚(lanlonggang@tal.com)张文博(zhangwenbo1@tal.com)
|
|
2
|
+
# Omni_WebRTC
|
|
3
|
+
|
|
4
|
+
## 引入SDK
|
|
5
|
+
- ES Module引入
|
|
6
|
+
```javascript
|
|
7
|
+
import getRTCEngine from 'omnirtc-web';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## 加入RTC房间
|
|
11
|
+
```javascript
|
|
12
|
+
/**
|
|
13
|
+
* 获取token,
|
|
14
|
+
* 获取方式参考 https://wiki.zhiyinlou.com/pages/viewpage.action?pageId=30835986
|
|
15
|
+
* 有问题联系周伟伟(zhouweiwei3@tal.com)老师
|
|
16
|
+
**/
|
|
17
|
+
const token = 'token';
|
|
18
|
+
// 获取引擎实例
|
|
19
|
+
// engine API详细 https://dev-webrtc.weclassroom.com/doc/classes/CoreRTC.CoreRTC-1.html
|
|
20
|
+
const engine = getRTCEngine(token);
|
|
21
|
+
|
|
22
|
+
// 加入RTC房间
|
|
23
|
+
// client API详细 https://dev-webrtc.weclassroom.com/doc/classes/Client.Client-1.html
|
|
24
|
+
const client = engine.createClient({
|
|
25
|
+
mode: 'live',
|
|
26
|
+
codec: 'h264'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 监听会议相关事件
|
|
30
|
+
client.on('user-joined', (user) => {
|
|
31
|
+
console.log('有用户加入房间。', user.uid)
|
|
32
|
+
})
|
|
33
|
+
client.on('user-left', (user, reason) => {
|
|
34
|
+
console.log('用户离开房间了。', user.uid)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// 有其他用户开始推流了
|
|
38
|
+
client.on('user-published', async (user, mediaKind) => {
|
|
39
|
+
console.log('用户开始推流了。', user.uid, mediaKind)
|
|
40
|
+
|
|
41
|
+
// 在这里就可以拉取该用户的流了,也可以先保存user,延后再拉。
|
|
42
|
+
const track = await client.subscribe(user, mediaKind);
|
|
43
|
+
|
|
44
|
+
console.log('媒体流已就绪,可以播放。', user.uid, mediaKind);
|
|
45
|
+
if (mediaKind === 'audio') {
|
|
46
|
+
track.play();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (mediaKind === 'video') {
|
|
50
|
+
track.play('video-dom');
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
client.on('user-unpublished', (user, mediaKind) => {
|
|
54
|
+
console.log('用户停止推流了。', user.uid, mediaKind)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
client.join().then((uid) => {
|
|
58
|
+
console.log('您已经加入房间了。您的用户ID:', uid)
|
|
59
|
+
});
|
|
60
|
+
...
|
|
61
|
+
```
|
|
62
|
+
## 推送媒体流
|
|
63
|
+
- 推送媒体流必须在调用`client.join`之后
|
|
64
|
+
```javascript
|
|
65
|
+
// 打开摄像头和麦克风
|
|
66
|
+
const tracks = await engine.createMicrophoneAndCameraTracks();
|
|
67
|
+
// 推送音视频流
|
|
68
|
+
await client.publish(tracks);
|
|
69
|
+
```
|
|
70
|
+
## 拉取远端流
|
|
71
|
+
- 必须在收到远端用户`user-published`之后再调用`client.subsribe`
|
|
72
|
+
```javascript
|
|
73
|
+
// 拉取远端用户音频流
|
|
74
|
+
const audioTrack = await client.subscribe(user, 'audio');
|
|
75
|
+
audioTrack.play();
|
|
76
|
+
|
|
77
|
+
// 拉取远端用户视频流
|
|
78
|
+
const videoTrack = await client.subscribe(user, 'video');
|
|
79
|
+
videoTrack.play('video-dom');
|
|
80
|
+
```
|
|
81
|
+
## 注意事项
|
|
82
|
+
- 建议开发者捕获播放失败的事件
|
|
83
|
+
```javascript
|
|
84
|
+
engine.onAudioAutoplayFailed = () => {
|
|
85
|
+
console.log('音频播放失败。')
|
|
86
|
+
// 建议用户和页面交互后再调用track.play()
|
|
87
|
+
// 参考https://www.jianshu.com/p/c3c6944eed5a
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|