@@ -76,19 +76,48 @@ function onWebSocketClose() {
76
76
RTC . quit ( ) ;
77
77
}
78
78
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
+
79
98
function initRTC ( opts ) {
80
99
window . RTC = new WebRTCAPI ( {
81
100
userId : opts . userId ,
82
101
userSig : opts . userSig ,
83
102
sdkAppId : opts . sdkappid ,
84
103
accountType : opts . accountType
85
104
} , function ( ) {
86
- RTC . createRoom ( {
105
+ // RTC.createRoom({
106
+ RTC . enterRoom ( {
87
107
roomid : opts . roomid * 1 ,
88
108
privateMapKey : opts . privateMapKey ,
89
109
role : "user" ,
90
110
} , function ( info ) {
91
111
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
+ } )
92
121
} , function ( error ) {
93
122
console . error ( "init error" , error )
94
123
} ) ;
@@ -114,7 +143,7 @@ function initRTC(opts) {
114
143
}
115
144
} ) ;
116
145
RTC . on ( "onStreamNotify" , function ( info ) {
117
- // console.warn('onStreamNotify', info)
146
+ console . warn ( 'onStreamNotify' , info )
118
147
} ) ;
119
148
RTC . on ( "onWebSocketNotify" , function ( info ) {
120
149
// console.warn('onWebSocketNotify', info)
@@ -141,6 +170,7 @@ function push() {
141
170
"userSig" : userSig ,
142
171
"sdkappid" : sdkappid ,
143
172
"accountType" : 1 , // 随便传一个值,现在没有啥用处
173
+ "closeLocalMedia" : false ,
144
174
"roomid" : roomid
145
175
} ) ;
146
176
}
@@ -163,9 +193,9 @@ function stopWs() {
163
193
164
194
function startRTC ( ) {
165
195
RTC . startRTC ( 0 , function ( info ) {
166
- // console.debug(info)
196
+ console . debug ( 'success' , info )
167
197
} , function ( info ) {
168
- // console.debug(info)
198
+ console . debug ( 'failed' , info )
169
199
} ) ;
170
200
}
171
201
0 commit comments