@adventurelabs/scout-core 1.0.94 → 1.0.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,14 +15,14 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
15
15
|
// Handle connectivity broadcasts
|
|
16
16
|
const handleConnectivityBroadcast = useCallback((payload) => {
|
|
17
17
|
const { event, payload: data } = payload;
|
|
18
|
-
const connectivityData = data.
|
|
18
|
+
const connectivityData = data.record || data.old_record;
|
|
19
19
|
// Only process GPS tracker data (no session_id)
|
|
20
20
|
if (!connectivityData?.device_id || connectivityData.session_id) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
const deviceId = connectivityData.device_id;
|
|
24
24
|
const updatedConnectivity = { ...connectivity };
|
|
25
|
-
switch (
|
|
25
|
+
switch (data.operation) {
|
|
26
26
|
case "INSERT":
|
|
27
27
|
if (!updatedConnectivity[deviceId]) {
|
|
28
28
|
updatedConnectivity[deviceId] = [];
|
|
@@ -53,6 +53,7 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
53
53
|
}
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
|
+
console.log("[Connectivity] updating tracker connectivity in response to broadcast");
|
|
56
57
|
dispatch(setActiveHerdGpsTrackersConnectivity(updatedConnectivity));
|
|
57
58
|
}, [connectivity]);
|
|
58
59
|
// Fetch initial connectivity data
|
|
@@ -95,9 +96,9 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
95
96
|
}));
|
|
96
97
|
dispatch(setActiveHerdGpsTrackersConnectivity(connectivityData));
|
|
97
98
|
console.log(`[Connectivity] Loaded data for ${Object.keys(connectivityData).length} devices`);
|
|
98
|
-
}, [activeHerdId]);
|
|
99
|
+
}, [activeHerdId, herdModules]);
|
|
99
100
|
useEffect(() => {
|
|
100
|
-
if (!scoutSupabase || !activeHerdId)
|
|
101
|
+
if (!scoutSupabase || !activeHerdId || herdModules.length == 0)
|
|
101
102
|
return;
|
|
102
103
|
// Clean up existing channels
|
|
103
104
|
channels.current.forEach((channel) => scoutSupabase.removeChannel(channel));
|
|
@@ -121,5 +122,5 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
121
122
|
channels.current.forEach((ch) => scoutSupabase.removeChannel(ch));
|
|
122
123
|
channels.current = [];
|
|
123
124
|
};
|
|
124
|
-
}, [activeHerdId]);
|
|
125
|
+
}, [activeHerdId, herdModules]);
|
|
125
126
|
}
|
|
@@ -9,21 +9,20 @@ export function useScoutRealtimeDevices(scoutSupabase) {
|
|
|
9
9
|
const activeHerdId = useSelector((state) => state.scout.active_herd_id);
|
|
10
10
|
// Device broadcast handler
|
|
11
11
|
const handleDeviceBroadcast = useCallback((payload) => {
|
|
12
|
-
console.log("[Devices] Broadcast received:", payload.payload.
|
|
13
|
-
const event = payload.payload.event;
|
|
12
|
+
console.log("[Devices] Broadcast received:", payload.payload.operation);
|
|
14
13
|
const data = payload.payload;
|
|
15
|
-
switch (
|
|
14
|
+
switch (data.operation) {
|
|
16
15
|
case "INSERT":
|
|
17
|
-
if (data.
|
|
18
|
-
dispatch(addDevice(data.
|
|
16
|
+
if (data.record)
|
|
17
|
+
dispatch(addDevice(data.record));
|
|
19
18
|
break;
|
|
20
19
|
case "UPDATE":
|
|
21
|
-
if (data.
|
|
22
|
-
dispatch(updateDevice(data.
|
|
20
|
+
if (data.record)
|
|
21
|
+
dispatch(updateDevice(data.record));
|
|
23
22
|
break;
|
|
24
23
|
case "DELETE":
|
|
25
|
-
if (data.
|
|
26
|
-
dispatch(deleteDevice(data.
|
|
24
|
+
if (data.old_record)
|
|
25
|
+
dispatch(deleteDevice(data.old_record));
|
|
27
26
|
break;
|
|
28
27
|
}
|
|
29
28
|
}, [dispatch]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useCallback, useRef } from "react";
|
|
2
2
|
import { useAppDispatch } from "../store/hooks";
|
|
3
|
-
import { EnumScoutStateStatus,
|
|
3
|
+
import { EnumScoutStateStatus, setHerdModules, setStatus, setHerdModulesLoadingState, setHerdModulesLoadedInMs, setHerdModulesApiDuration, setUserApiDuration, setDataProcessingDuration, setLocalStorageDuration, setUser, setDataSource, setDataSourceInfo, } from "../store/scout";
|
|
4
4
|
import { EnumHerdModulesLoadingState } from "../types/herd_module";
|
|
5
5
|
import { server_load_herd_modules } from "../helpers/herds";
|
|
6
6
|
import { server_get_user } from "../helpers/users";
|
|
@@ -275,32 +275,38 @@ export function useScoutRefresh(options = {}) {
|
|
|
275
275
|
const dataProcessingDuration = Date.now() - dataProcessingStartTime;
|
|
276
276
|
timingRefs.current.dataProcessingDuration = dataProcessingDuration;
|
|
277
277
|
dispatch(setDataProcessingDuration(dataProcessingDuration));
|
|
278
|
-
// Step 5: Handle localStorage operations
|
|
278
|
+
// // Step 5: Handle localStorage operations
|
|
279
279
|
const localStorageStartTime = Date.now();
|
|
280
|
-
try {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
280
|
+
// try {
|
|
281
|
+
// // Check local storage for a last selected herd
|
|
282
|
+
// const lastSelectedHerd = localStorage.getItem("last_selected_herd");
|
|
283
|
+
// if (lastSelectedHerd) {
|
|
284
|
+
// const found_herd = compatible_new_herd_modules.find(
|
|
285
|
+
// (hm) => hm.herd.id.toString() === lastSelectedHerd,
|
|
286
|
+
// )?.herd;
|
|
287
|
+
// // If herd is found then set it
|
|
288
|
+
// if (found_herd) {
|
|
289
|
+
// dispatch(setActiveHerdId(found_herd.id.toString()));
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
292
|
+
// // If there is no last selected herd then select the first one
|
|
293
|
+
// else if (compatible_new_herd_modules.length > 0) {
|
|
294
|
+
// const firstHerdId = compatible_new_herd_modules[0].herd.id.toString();
|
|
295
|
+
// localStorage.setItem("last_selected_herd", firstHerdId);
|
|
296
|
+
// dispatch(setActiveHerdId(firstHerdId));
|
|
297
|
+
// }
|
|
298
|
+
// } catch (localStorageError) {
|
|
299
|
+
// console.warn(
|
|
300
|
+
// "[useScoutRefresh] localStorage not available:",
|
|
301
|
+
// localStorageError,
|
|
302
|
+
// );
|
|
303
|
+
// // Fallback: select first herd without localStorage
|
|
304
|
+
// if (compatible_new_herd_modules.length > 0) {
|
|
305
|
+
// dispatch(
|
|
306
|
+
// setActiveHerdId(compatible_new_herd_modules[0].herd.id.toString()),
|
|
307
|
+
// );
|
|
308
|
+
// }
|
|
309
|
+
// }
|
|
304
310
|
const localStorageDuration = Date.now() - localStorageStartTime;
|
|
305
311
|
timingRefs.current.localStorageDuration = localStorageDuration;
|
|
306
312
|
dispatch(setLocalStorageDuration(localStorageDuration));
|