No Description

App.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, {Component} from 'react';
  9. import {
  10. Platform, StyleSheet, Text, View, TouchableOpacity, TextInput
  11. } from 'react-native';
  12. import AgoraRTCView from './components/agora';
  13. const instructions = Platform.select({
  14. ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  15. android:
  16. 'Double tap R on your keyboard to reload,\n' +
  17. 'Shake or press menu button for dev menu',
  18. });
  19. const styles = StyleSheet.create({
  20. container: {
  21. flex: 1,
  22. justifyContent: 'center',
  23. alignItems: 'center',
  24. backgroundColor: '#F5FCFF',
  25. },
  26. welcome: {
  27. fontSize: 20,
  28. textAlign: 'center',
  29. margin: 10,
  30. },
  31. instructions: {
  32. textAlign: 'center',
  33. color: '#333333',
  34. marginBottom: 5,
  35. },
  36. button: {
  37. height: 44,
  38. paddingHorizontal:20,
  39. backgroundColor:'#6A71DD',
  40. borderRadius:10,
  41. justifyContent:'center',
  42. alignItems:'center',
  43. marginTop: 10
  44. }
  45. });
  46. type Props = {};
  47. export default class App extends Component<Props> {
  48. constructor(props) {
  49. super(props);
  50. this.state = {
  51. showLive: false,
  52. error: undefined,
  53. channelProfile: 1,
  54. videoProfile: 40,
  55. clientRole: 1,
  56. swapWidthAndHeight: true
  57. };
  58. }
  59. joinChannel = () => {
  60. this.setState({
  61. showLive: true
  62. })
  63. }
  64. onCancel = (error) => {
  65. console.log("[error]", error);
  66. this.setState({
  67. showLive: false,
  68. error
  69. })
  70. }
  71. render() {
  72. if (this.state.showLive) {
  73. return (<AgoraRTCView
  74. onCancel={this.onCancel}
  75. channelProfile={this.state.channelProfile}
  76. videoProfile={this.state.videoProfile}
  77. clientRole={this.state.clientRole}
  78. swapWidthAndHeight={this.state.swapWidthAndHeight}
  79. ></AgoraRTCView>);
  80. }
  81. return (
  82. <View style={styles.container}>
  83. {this.state.error && <Text>Error Message: {error}</Text>}
  84. <TextInput
  85. style={{height: 40}}
  86. keyboardType='numeric'
  87. placeholder="Enter channelProfile (numeric)"
  88. onChangeText={(text) => {
  89. let matched = text.match(/\d+/g) && text.match(/\d+/g)[0]
  90. if (matched) {
  91. this.setState({channelProfile: +matched})
  92. }
  93. }
  94. } />
  95. <TextInput
  96. style={{height: 40}}
  97. keyboardType='numeric'
  98. placeholder="Enter videoProfile (numeric)"
  99. onChangeText={(text) => {
  100. let matched = text.match(/\d+/g) && text.match(/\d+/g)[0]
  101. if (matched) {
  102. this.setState({videoProfile: +matched})
  103. } }
  104. } />
  105. <TextInput
  106. style={{height: 40}}
  107. keyboardType='numeric'
  108. placeholder="Enter clientRole (numeric)"
  109. onChangeText={(text) => {
  110. let matched = text.match(/\d+/g) && text.match(/\d+/g)[0]
  111. if (matched) {
  112. this.setState({clientRole: +matched})
  113. } }
  114. } />
  115. <TouchableOpacity
  116. style={styles.button}
  117. onPress={this.joinChannel}
  118. >
  119. <Text style={{color: "#fff"}}>join room</Text>
  120. </TouchableOpacity>
  121. </View>
  122. );
  123. }
  124. }