No Description

App.js 3.2KB

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