Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class Chatting extends Component {
- constructor(props) {
- super(props);
- this.socket = new WebSocket('ws://192.168.1.2:4000/message.php');
- this.socket.onopen = function() {
- alert("Соединение установлено.");
- };
- this.socket.onclose = function(event) {
- if (event.wasClean) {
- alert('Соединение закрыто чисто');
- } else {
- alert('Обрыв соединения'); // например, "убит" процесс сервера
- }
- alert('Код: ' + event.code + ' причина: ' + event.reason);
- alert(event);
- };
- this.socket.onmessage = function(event) {
- alert("Получены данные " + event.data);
- };
- this.socket.onerror = function(error) {
- alert("Ошибка " + error.message);
- };
- this.inputValue = null;
- this.state = {data: []};
- }
- render() {
- return(
- <View style={styles.general}>
- <FlatList
- data={this.state.data}
- style={styles.list}
- keyExtractor={(item, index) => index.toString()}
- renderItem={({item}) => {
- return(
- <View>
- </View>
- );
- }}
- />
- <View>
- <TextInput onChangeText={(data) => this.inputValue = data} placeholder={'Введите сообщение'} placeholderTextColor={'gray'} style={styles.input}></TextInput>
- <TouchableNativeFeedback onPress={() => {this.socket.send(this.inputValue)}}>
- <View style={styles.button}>
- <Text style={{textAlign: 'center', fontWeight: 'bold', fontSize: 16}}>Отправить</Text>
- </View>
- </TouchableNativeFeedback>
- </View>
- </View>)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement