| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 | /**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */
import React, {Component} from 'react';
import {
  Platform, StyleSheet, Text, View, TouchableOpacity, TextInput
} from 'react-native';
import AgoraRTCView from './components/agora';
const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  button: {
    height: 44,
    paddingHorizontal:20,
    backgroundColor:'#6A71DD',
    borderRadius:10,
    justifyContent:'center',
    alignItems:'center',
    marginTop: 10
  }
});
type Props = {};
export default class App extends Component<Props> {
  constructor(props) {
    super(props);
    this.state = {
      showLive: false,
      error: undefined,
      channelProfile: 1,
      videoProfile: 40,
      clientRole: 1,
      swapWidthAndHeight: true
    };
  }
  joinChannel = () => {
    this.setState({
      showLive: true
    })
  }
  onCancel = (error) => {
    console.log("[error]", error);
    this.setState({
      showLive: false,
      error
    })
  }
  render() {
    if (this.state.showLive) {
      return (<AgoraRTCView
        onCancel={this.onCancel}
        channelProfile={this.state.channelProfile}
        videoProfile={this.state.videoProfile}
        clientRole={this.state.clientRole}
        swapWidthAndHeight={this.state.swapWidthAndHeight}
      ></AgoraRTCView>);
    }
    return (
      <View style={styles.container}>
        {this.state.error && <Text>Error Message: {error}</Text>}
        <TextInput
          style={{height: 40}}
          keyboardType='numeric'
          placeholder="Enter channelProfile (numeric)"
          onChangeText={(text) => {
            let matched = text.match(/\d+/g) && text.match(/\d+/g)[0]
            if (matched) {
              this.setState({channelProfile: +matched})
            }
          }
        } />
        <TextInput
          style={{height: 40}}
          keyboardType='numeric'
          placeholder="Enter videoProfile (numeric)"
          onChangeText={(text) => {
            let matched = text.match(/\d+/g) && text.match(/\d+/g)[0]
            if (matched) {
              this.setState({videoProfile: +matched})
            }          }
        } />
        <TextInput
          style={{height: 40}}
          keyboardType='numeric'
          placeholder="Enter clientRole (numeric)"
          onChangeText={(text) => {
            let matched = text.match(/\d+/g) && text.match(/\d+/g)[0]
            if (matched) {
              this.setState({clientRole: +matched})
            }          }
        } />
        <TouchableOpacity
          style={styles.button}
          onPress={this.joinChannel}
        >
          <Text style={{color: "#fff"}}>join room</Text>
        </TouchableOpacity>
      </View>
    );
  }
}
 |