Browse Source

fix. disableVideo

matrixbirds 5 years ago
parent
commit
1448fc04a8
1 changed files with 15 additions and 8 deletions
  1. 15
    8
      samples/simpleDemo/components/agora.js

+ 15
- 8
samples/simpleDemo/components/agora.js View File

102
   clientRole: Number,
102
   clientRole: Number,
103
   onCancel: Function,
103
   onCancel: Function,
104
   uid: Number,
104
   uid: Number,
105
+  showVideo: boolean,
105
 }
106
 }
106
 
107
 
107
 export default class AgoraComponent extends Component<Props> {
108
 export default class AgoraComponent extends Component<Props> {
111
     isSpeak: true,
112
     isSpeak: true,
112
     isMute: false,
113
     isMute: false,
113
     isCameraTorch: false,
114
     isCameraTorch: false,
114
-    disableVideo: false,
115
+    showVideo: true,
115
     hideButton: false,
116
     hideButton: false,
116
     visible: false,
117
     visible: false,
117
     selectedUid: undefined,
118
     selectedUid: undefined,
234
   }
235
   }
235
 
236
 
236
   toggleVideo = () => {
237
   toggleVideo = () => {
238
+    const showVideo = !this.state.showVideo
237
     this.setState({
239
     this.setState({
238
-      disableVideo: !this.state.videodisableVideo
239
-    }, () => {
240
-      this.state.disableVideo ? RtcEngine.enableVideo() : RtcEngine.disableVideo()
241
-    });
240
+      showVideo
241
+    })
242
+    if (showVideo) {
243
+      RtcEngine.enableVideo()
244
+      RtcEngine.startPreview()
245
+    } else {
246
+      RtcEngine.disableVideo()
247
+      RtcEngine.stopPreview()
248
+    }
242
   }
249
   }
243
 
250
 
244
   toggleHideButtons = () => {
251
   toggleHideButtons = () => {
257
     })
264
     })
258
   }
265
   }
259
 
266
 
260
-  buttonsView = ({hideButton, isCameraTorch, disableVideo, isMute, isSpeaker}) => {
267
+  buttonsView = ({hideButton, isCameraTorch, showVideo, isMute, isSpeaker}) => {
261
     if (!hideButton) {
268
     if (!hideButton) {
262
     return (
269
     return (
263
       <View>
270
       <View>
275
         />
282
         />
276
         <OperateButton
283
         <OperateButton
277
           onPress={this.toggleVideo}
284
           onPress={this.toggleVideo}
278
-          source={disableVideo ? EnableCamera() : DisableCamera()}
285
+          source={showVideo ? EnableCamera() : DisableCamera()}
279
         />
286
         />
280
       </View>
287
       </View>
281
       <View style={styles.bottomView}>
288
       <View style={styles.bottomView}>
353
         onPress={this.toggleHideButtons}
360
         onPress={this.toggleHideButtons}
354
         style={styles.container}
361
         style={styles.container}
355
       >
362
       >
356
-        <AgoraView style={styles.localView} showLocalVideo={true} />
363
+        { this.state.showVideo ? <AgoraView style={styles.localView} showLocalVideo={this.state.showVideo} /> : null}
357
           <View style={styles.absView}>
364
           <View style={styles.absView}>
358
             <Text>channelName: {this.props.channelName}, peers: {this.state.peerIds.length}</Text>
365
             <Text>channelName: {this.props.channelName}, peers: {this.state.peerIds.length}</Text>
359
             {this.agoraPeerViews(this.state)}
366
             {this.agoraPeerViews(this.state)}