Cleanup connection logic
This commit is contained in:
@@ -36,6 +36,9 @@ export const HTTP = ({ connecting }: HTTPProps): JSX.Element => {
|
||||
});
|
||||
|
||||
const onSubmit = handleSubmit(async (data) => {
|
||||
if (data.ip) {
|
||||
localStorage.setItem('connectionUrl', data.ip);
|
||||
}
|
||||
dispatch(
|
||||
setConnectionParams({
|
||||
type: connType.HTTP,
|
||||
|
||||
@@ -30,12 +30,9 @@ type connectionType = IBLEConnection | IHTTPConnection | ISerialConnection;
|
||||
|
||||
export let connection: connectionType = new IHTTPConnection();
|
||||
|
||||
const state = store.getState().meshtastic;
|
||||
export const connectionUrl = state.hostOverrideEnabled
|
||||
? state.hostOverride
|
||||
: import.meta.env.PROD
|
||||
? window.location.hostname
|
||||
: (import.meta.env.VITE_PUBLIC_DEVICE_IP as string) ?? 'meshtastic.local';
|
||||
const appState = store.getState().app;
|
||||
|
||||
export const connectionUrl = appState.connectionParams.HTTP.address;
|
||||
|
||||
export const setConnection = async (conn: connType): Promise<void> => {
|
||||
await connection.disconnect();
|
||||
@@ -53,6 +50,8 @@ export const setConnection = async (conn: connType): Promise<void> => {
|
||||
}
|
||||
registerListeners();
|
||||
const connectionParams = store.getState().app.connectionParams;
|
||||
console.log(connectionParams);
|
||||
|
||||
switch (conn) {
|
||||
case connType.HTTP:
|
||||
await connection.connect(connectionParams.HTTP);
|
||||
|
||||
@@ -35,7 +35,11 @@ const initialState: AppState = {
|
||||
connectionParams: {
|
||||
BLE: {},
|
||||
HTTP: {
|
||||
address: 'http://meshtastic.local/',
|
||||
address:
|
||||
localStorage.getItem('connectionUrl') ?? import.meta.env.PROD
|
||||
? window.location.hostname
|
||||
: (import.meta.env.VITE_PUBLIC_DEVICE_IP as string) ??
|
||||
'meshtastic.local',
|
||||
tls: false,
|
||||
receiveBatchRequests: false,
|
||||
fetchInterval: 2000,
|
||||
|
||||
@@ -55,8 +55,6 @@ interface MeshtasticState {
|
||||
ready: boolean;
|
||||
nodes: Node[];
|
||||
radio: Radio;
|
||||
hostOverrideEnabled: boolean;
|
||||
hostOverride: string;
|
||||
chats: ChatEntries;
|
||||
logs: Types.LogEventPacket[];
|
||||
}
|
||||
@@ -71,11 +69,6 @@ const initialState: MeshtasticState = {
|
||||
preferences: Protobuf.RadioConfig_UserPreferences.create(),
|
||||
hardware: Protobuf.MyNodeInfo.create(),
|
||||
},
|
||||
//todo implement
|
||||
// connectionMethod: localStorage.getItem('connectionMethod'),
|
||||
hostOverrideEnabled:
|
||||
localStorage.getItem('hostOverrideEnabled') === 'true' ?? false,
|
||||
hostOverride: localStorage.getItem('hostOverride') ?? '',
|
||||
chats: {},
|
||||
logs: [],
|
||||
};
|
||||
@@ -257,20 +250,6 @@ export const meshtasticSlice = createSlice({
|
||||
node.lastHeard = action.payload.time;
|
||||
}
|
||||
},
|
||||
setHostOverrideEnabled: (state, action: PayloadAction<boolean>) => {
|
||||
state.hostOverrideEnabled = action.payload;
|
||||
localStorage.setItem('hostOverrideEnabled', String(action.payload));
|
||||
if (state.hostOverrideEnabled !== action.payload) {
|
||||
// connection.disconnect();
|
||||
}
|
||||
},
|
||||
setHostOverride: (state, action: PayloadAction<string>) => {
|
||||
state.hostOverride = action.payload;
|
||||
localStorage.setItem('hostOverride', action.payload);
|
||||
if (state.hostOverride !== action.payload) {
|
||||
// connection.disconnect();
|
||||
}
|
||||
},
|
||||
addChat: (state, action: PayloadAction<number>) => {
|
||||
state.chats[action.payload] = {
|
||||
messages: [],
|
||||
@@ -303,8 +282,6 @@ export const {
|
||||
addMessage,
|
||||
ackMessage,
|
||||
updateLastInteraction,
|
||||
setHostOverrideEnabled,
|
||||
setHostOverride,
|
||||
addChat,
|
||||
resetState,
|
||||
} = meshtasticSlice.actions;
|
||||
|
||||
Reference in New Issue
Block a user