Fixes
This commit is contained in:
@@ -4,6 +4,10 @@ import {
|
||||
ISerialConnection,
|
||||
} from '@meshtastic/meshtasticjs';
|
||||
|
||||
export const connection = new IHTTPConnection();
|
||||
export const bleConnection = new IBLEConnection();
|
||||
export const serialConnection = new ISerialConnection();
|
||||
type connectionType = IBLEConnection | IHTTPConnection | ISerialConnection;
|
||||
|
||||
export let connection: connectionType = new IHTTPConnection();
|
||||
|
||||
export const setConnection = (conn: connectionType): void => {
|
||||
connection = conn;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,11 @@ export interface MessageWithAck {
|
||||
isSender: boolean;
|
||||
received: Date;
|
||||
}
|
||||
enum connType {
|
||||
HTTP,
|
||||
BLE,
|
||||
SERIAL,
|
||||
}
|
||||
|
||||
interface MeshtasticState {
|
||||
deviceStatus: Types.DeviceStatusEnum;
|
||||
@@ -24,6 +29,7 @@ interface MeshtasticState {
|
||||
messages: MessageWithAck[];
|
||||
hostOverrideEnabled: boolean;
|
||||
hostOverride: string;
|
||||
connectionType: connType;
|
||||
}
|
||||
|
||||
const initialState: MeshtasticState = {
|
||||
@@ -40,6 +46,7 @@ const initialState: MeshtasticState = {
|
||||
hostOverrideEnabled:
|
||||
localStorage.getItem('hostOverrideEnabled') === 'true' ?? false,
|
||||
hostOverride: localStorage.getItem('hostOverride') ?? '',
|
||||
connectionType: parseInt(localStorage.getItem('connectionType') ?? '0'),
|
||||
};
|
||||
|
||||
export const meshtasticSlice = createSlice({
|
||||
@@ -58,8 +65,21 @@ export const meshtasticSlice = createSlice({
|
||||
setMyNodeInfo: (state, action: PayloadAction<Protobuf.MyNodeInfo>) => {
|
||||
state.myNodeInfo = action.payload;
|
||||
},
|
||||
setUser: (state, action: PayloadAction<Protobuf.User>) => {
|
||||
state.user = action.payload;
|
||||
setUser: (
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
nodeNum: number;
|
||||
user: Protobuf.User;
|
||||
}>,
|
||||
) => {
|
||||
if (action.payload.nodeNum === state.myNodeInfo.myNodeNum) {
|
||||
state.user = action.payload.user;
|
||||
} else {
|
||||
const num = state.nodes.findIndex(
|
||||
(node) => node.num === action.payload.nodeNum,
|
||||
);
|
||||
state.nodes[num].user = action.payload.user;
|
||||
}
|
||||
},
|
||||
addPositionPacket: (state, action: PayloadAction<Types.PositionPacket>) => {
|
||||
state.positionPackets.push(action.payload);
|
||||
@@ -75,7 +95,6 @@ export const meshtasticSlice = createSlice({
|
||||
state.nodes.push(action.payload);
|
||||
}
|
||||
},
|
||||
|
||||
addChannel: (state, action: PayloadAction<Protobuf.Channel>) => {
|
||||
if (
|
||||
state.channels.findIndex(
|
||||
@@ -121,6 +140,13 @@ export const meshtasticSlice = createSlice({
|
||||
connection.disconnect();
|
||||
}
|
||||
},
|
||||
setConnectionType: (state, action: PayloadAction<connType>) => {
|
||||
state.connectionType = action.payload;
|
||||
localStorage.setItem('connectionType', String(action.payload));
|
||||
if (state.connectionType !== action.payload) {
|
||||
connection.disconnect();
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user