From 768d5eaa8726eaab615675ccb0ea40ddb3897df4 Mon Sep 17 00:00:00 2001 From: maran Date: Sat, 23 Mar 2019 18:41:34 +0530 Subject: [PATCH] added url to state --- Home.js | 53 ++++++++++++++++++++++++++++------------------------- app.json | 3 +++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Home.js b/Home.js index 37aeb01..f0e3503 100644 --- a/Home.js +++ b/Home.js @@ -9,7 +9,7 @@ const dataArray = [ ]; const SendActions = ['whistleCount', ]; -const RecvActions = ['whistleInc',]; +const RecvActions = ['whistleInc', 'tempHigh', 'gasLeak']; var cooker = require('./assets/whistle4.png') @@ -21,25 +21,25 @@ import { getStatusBarHeight } from 'react-native-status-bar-height'; export default class Home extends React.Component { // For white titlebar - // static navigationOptions = { - // title: 'Whistle Counter', - // height: 60, - // headerStyle: { - // shadowOpacity: 0, - // shadowOffset: { - // height: 0 - // }, - // shadowRadius: 0, - // borderBottomWidth: 0, - // elevation: 0 - // } - - // } - static navigationOptions = { - header : null + title: 'Whistle Counter', + height: 60, + headerStyle: { + shadowOpacity: 0, + shadowOffset: { + height: 0 + }, + shadowRadius: 0, + borderBottomWidth: 0, + elevation: 0 + } + } + // static navigationOptions = { + // header : null + // } + constructor(props) { super(props); this.state = { splash_sc : false , @@ -47,6 +47,7 @@ export default class Home extends React.Component { DialogState: false, loading : true, connected : false, + ws_url : "echo.websocket.org", currWhistleCount : 0, totalWhistleCount : 0, count : 0, @@ -61,13 +62,14 @@ export default class Home extends React.Component { } initSocket(){ - this.client = new WebSocket('ws://echo.websocket.org'); + this.client = new WebSocket('ws://' + this.state.ws_url); this.client.onopen = connection => { console.log( new Date().toISOString() + ' Connected'); this.setState({connected : true}) }; + this.client.onclose = () => this.setState({connected : false}); // Recieve and handle messages this.client.onmessage = msg => { console.log(msg.data + " recieved"); @@ -81,6 +83,8 @@ export default class Home extends React.Component { case 'whistleInc': this.setState(prevState => ({ currWhistleCount : prevState.currWhistleCount + 1})); break; + case 'tempHigh': + break; } } @@ -137,8 +141,8 @@ export default class Home extends React.Component { return ( {/* For white titlebar */} - {/* */} -
+ + {/*
Whistle Counter @@ -147,7 +151,7 @@ export default class Home extends React.Component { -
+
*/} @@ -157,7 +161,7 @@ export default class Home extends React.Component { - Status: {this.state.connected ? 'Connected' : 'Disconnected'} + Status: {this.state.connected ? 'Connected to ' + this.state.ws_url : 'Disconnected'} No of whistles: {this.state.currWhistleCount}/{this.state.totalWhistleCount} @@ -194,9 +198,8 @@ export default class Home extends React.Component { footer={ - {this.setState({ DialogState: false });}} /> @@ -274,7 +277,7 @@ const styles = StyleSheet.create({ paddingRight: 5, paddingTop: 10, paddingBottom: 20, - borderRadius: 10 + borderRadius: 10, }, }); diff --git a/app.json b/app.json index 5db5c82..79a784c 100644 --- a/app.json +++ b/app.json @@ -28,6 +28,9 @@ "description": "", "androidStatusBar":{ "backgroundColor":"#000000" + }, + "android": { + "package": "com.whistlecorp.whistlecount" } } } \ No newline at end of file