Various fixes

This commit is contained in:
Martin Bauer
2021-07-22 18:39:02 +02:00
parent 0bb0e2f121
commit a307e2a4ea
10 changed files with 19971 additions and 53 deletions

View File

@@ -83,6 +83,11 @@ export class DeviceReduxCoupling {
const state = this.reduxStore.getState();
if (this.conn === null || (state.settings.swimTrackerHost != this.conn.swimTrackerHost)) {
console.log(" ---- starting websocket connection to ", state.settings.swimTrackerHost);
if( this.conn !== null) {
this.conn.close();
}
this.conn = new SwimTrackerWebsocketConnection(state.settings.swimTrackerHost,
this._onNewData,
(sessionId) => this.reduxStore.dispatch(reportSessionStarted(sessionId)),
@@ -137,27 +142,27 @@ export const deviceStateReducer = (state = INITIAL_DEVICE_STATE, action) => {
};
return res;
case DEVICE_CONNECT:
return { ...INITIAL_DEVICE_STATE, connState: ConnState.CONNECTED_STOPPED };
return { ...INITIAL_DEVICE_STATE, wifiState: state.wifiState, connState: ConnState.CONNECTED_STOPPED };
case DEVICE_DISCONNECT:
return { ...INITIAL_DEVICE_STATE, connState: ConnState.DISCONNECTED };
return { ...INITIAL_DEVICE_STATE, wifiState: state.wifiState, connState: ConnState.DISCONNECTED };
case SESSION_STARTED:
return { ...INITIAL_DEVICE_STATE, connState: ConnState.CONNECTED_RUNNING, sessionId: action.sessionId };
return { ...INITIAL_DEVICE_STATE, wifiState: state.wifiState, connState: ConnState.CONNECTED_RUNNING, sessionId: action.sessionId };
case SESSION_STOPPED:
return { ...INITIAL_DEVICE_STATE, connState: ConnState.CONNECTED_STOPPED };
return { ...INITIAL_DEVICE_STATE, wifiState: state.wifiState, connState: ConnState.CONNECTED_STOPPED };
case START_SESSION:
if (state.connState === ConnState.SESSION_STARTED)
return state;
return { ...INITIAL_DEVICE_STATE, connState: ConnState.CONNECTED_STARTING };
return { ...INITIAL_DEVICE_STATE, wifiState: state.wifiState, connState: ConnState.CONNECTED_STARTING };
case STOP_SESSION:
if (state.connState === ConnState.SESSION_STOPPED)
return state;
return { ...INITIAL_DEVICE_STATE, connState: ConnState.CONNECTED_STOPPING };
return { ...INITIAL_DEVICE_STATE, wifiState: state.wifiState, connState: ConnState.CONNECTED_STOPPING };
case WIFI_SET_STATE:
let wifState = WifiState.UNKNOWN;
if (action.newStateStr === "STATION_MODE") { wifState = WifiState.STA; }
else if (action.newStateStr === "AP_PROVISIONING") { wifState = WifiState.AP_PROVISIONING; }
else if (action.newStateStr === "AP_SECURE") { wifState = WifiState.AP_SECURE; }
return { ...state, wifiState: wifState };
let wifiState = WifiState.UNKNOWN;
if (action.newStateStr === "STATION_MODE") { wifiState = WifiState.STA; }
else if (action.newStateStr === "AP_PROVISIONING") { wifiState = WifiState.AP_PROVISIONING; }
else if (action.newStateStr === "AP_SECURE") { wifiState = WifiState.AP_SECURE; }
return { ...state, wifiState: wifiState };
default:
//console.log("Unhandled state in deviceStateReducer", action, action.type, "state", state);
return state;

View File

@@ -3,13 +3,18 @@ import { deviceStateReducer } from "./DeviceReduxCoupling";
export const CHANGE_USER_NAME = "SET_USERNAME";
export const RESET_DEVICE_DATA = "RESET_DEVICE_DATA";
export const CHANGE_SWIMTRACKER_HOSTNAME = "CHANGE_SWIMTRACKER_HOSTNAME";
export const changeUsername = newUsername => ({
type: CHANGE_USER_NAME,
newUserName: newUsername,
});
export const changeSwimTrackerHostname = newSwimTrackerHost => ( {
type: CHANGE_SWIMTRACKER_HOSTNAME,
newSwimTrackerHost: newSwimTrackerHost,
});
export const startSession = () => ({
type: START_SESSION
});
@@ -48,8 +53,10 @@ const settingsReducer = (state = INITIAL_SETTINGS, action) => {
switch (action.type) {
case CHANGE_USER_NAME:
return { ...state, username: action.newUsername };
case CHANGE_SWIMTRACKER_HOSTNAME:
return {... state, swimTrackerHost: action.newSwimTrackerHost};
default:
return state
return state;
}
};