Skip to content

Commit 8b9016f

Browse files
committed
更新 web demo webrtc api 至 3.0
1 parent ec469b2 commit 8b9016f

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ Android/.idea/libraries/Gradle__com_squareup_okhttp3_logging_interceptor_3_8_1_j
2929
Android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_3_8_1_jar.xml
3030
Android/.idea/libraries/Gradle__com_squareup_okio_okio_1_13_0_jar.xml
3131
Android/.idea/libraries/Gradle__LiteAVSDK_TRTC_release__aar.xml
32+
Android/.settings/*
33+
.project

H5/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<!-- jquery Demo用到,WebRTCAPI不依赖 -->
5353
<script src="./libs/jquery.min.js"></script>
5454
<!-- demo 部分 -->
55-
<script src="https://sqimg.qq.com/expert_qq/webrtc/2.6.2/WebRTCAPI.min.js"></script>
55+
<script src="https://sqimg.qq.com/expert_qq/webrtc/3.0/WebRTCAPI.min.js"></script>
5656
<script>
5757
document.write('<script src="./js/config.js?v='+new Date()+'" type="text/javascript"></scr'+'ipt>')
5858
document.write('<script src="./js/index.js?v='+new Date()+'" type="text/javascript"></scr'+'ipt>')

H5/js/index.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,48 @@ function onWebSocketClose() {
7676
RTC.quit();
7777
}
7878

79+
function gotStream( opt ,succ){
80+
RTC.getLocalStream({
81+
video:true,
82+
audio:true,
83+
videoDevice:opt.videoDevice,
84+
// 如需指定分辨率,可以在attributes中增加对width和height的约束
85+
// 否则将获取摄像头的默认分辨率
86+
// 更多配置项 请参考 接口API
87+
// https://cloud.tencent.com/document/product/647/17251#webrtcapi.getlocalstream
88+
// attributes:{
89+
// width:640,
90+
// height:320
91+
// }
92+
},function(info){
93+
var stream = info.stream;
94+
succ ( stream )
95+
});
96+
}
97+
7998
function initRTC(opts) {
8099
window.RTC = new WebRTCAPI({
81100
userId: opts.userId,
82101
userSig: opts.userSig,
83102
sdkAppId: opts.sdkappid,
84103
accountType: opts.accountType
85104
}, function () {
86-
RTC.createRoom({
105+
// RTC.createRoom({
106+
RTC.enterRoom({
87107
roomid: opts.roomid * 1,
88108
privateMapKey: opts.privateMapKey,
89109
role: "user",
90110
}, function (info) {
91111
console.warn("init succ", info)
112+
gotStream({
113+
audio:true,
114+
video:true
115+
},function(stream){
116+
RTC.startRTC({
117+
stream: stream,
118+
role: 'user'
119+
});
120+
})
92121
}, function (error) {
93122
console.error("init error", error)
94123
});
@@ -114,7 +143,7 @@ function initRTC(opts) {
114143
}
115144
});
116145
RTC.on("onStreamNotify", function (info) {
117-
// console.warn('onStreamNotify', info)
146+
console.warn('onStreamNotify', info)
118147
});
119148
RTC.on("onWebSocketNotify", function (info) {
120149
// console.warn('onWebSocketNotify', info)
@@ -141,6 +170,7 @@ function push() {
141170
"userSig": userSig,
142171
"sdkappid": sdkappid,
143172
"accountType": 1, // 随便传一个值,现在没有啥用处
173+
"closeLocalMedia": false,
144174
"roomid": roomid
145175
});
146176
}
@@ -163,9 +193,9 @@ function stopWs() {
163193

164194
function startRTC() {
165195
RTC.startRTC(0, function (info) {
166-
// console.debug(info)
196+
console.debug('success', info)
167197
}, function (info) {
168-
// console.debug(info)
198+
console.debug('failed', info)
169199
});
170200
}
171201

0 commit comments

Comments
 (0)