-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
48 lines (40 loc) · 1.01 KB
/
App.js
File metadata and controls
48 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
const Tag = 'WS';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = { connected: false };
window.navigator.userAgent = 'react-native';
}
_connectSocket = () => {
this.ws = new WebSocket('ws://104.236.168.186:3000');
this.ws.onerror = (e) => {
console.log(Tag, 'Error', e.message);
};
this.ws.onopen = (ws, event) => {
console.log(Tag, "Socket open");
};
this.ws.onclose = () => {
console.log(Tag, "Socket closed");
};
}
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Button
title = 'Connect'
onPress = { this._connectSocket } />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});