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,6 +102,7 @@ type Props = {
102 102
   clientRole: Number,
103 103
   onCancel: Function,
104 104
   uid: Number,
105
+  showVideo: boolean,
105 106
 }
106 107
 
107 108
 export default class AgoraComponent extends Component<Props> {
@@ -111,7 +112,7 @@ export default class AgoraComponent extends Component<Props> {
111 112
     isSpeak: true,
112 113
     isMute: false,
113 114
     isCameraTorch: false,
114
-    disableVideo: false,
115
+    showVideo: true,
115 116
     hideButton: false,
116 117
     visible: false,
117 118
     selectedUid: undefined,
@@ -234,11 +235,17 @@ export default class AgoraComponent extends Component<Props> {
234 235
   }
235 236
 
236 237
   toggleVideo = () => {
238
+    const showVideo = !this.state.showVideo
237 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 251
   toggleHideButtons = () => {
@@ -257,7 +264,7 @@ export default class AgoraComponent extends Component<Props> {
257 264
     })
258 265
   }
259 266
 
260
-  buttonsView = ({hideButton, isCameraTorch, disableVideo, isMute, isSpeaker}) => {
267
+  buttonsView = ({hideButton, isCameraTorch, showVideo, isMute, isSpeaker}) => {
261 268
     if (!hideButton) {
262 269
     return (
263 270
       <View>
@@ -275,7 +282,7 @@ export default class AgoraComponent extends Component<Props> {
275 282
         />
276 283
         <OperateButton
277 284
           onPress={this.toggleVideo}
278
-          source={disableVideo ? EnableCamera() : DisableCamera()}
285
+          source={showVideo ? EnableCamera() : DisableCamera()}
279 286
         />
280 287
       </View>
281 288
       <View style={styles.bottomView}>
@@ -353,7 +360,7 @@ export default class AgoraComponent extends Component<Props> {
353 360
         onPress={this.toggleHideButtons}
354 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 364
           <View style={styles.absView}>
358 365
             <Text>channelName: {this.props.channelName}, peers: {this.state.peerIds.length}</Text>
359 366
             {this.agoraPeerViews(this.state)}