Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20a9b21027 | ||
|
|
779bf8ff43 | ||
|
|
fbd7d837c7 |
1
mobile/.env.example
Normal file
1
mobile/.env.example
Normal file
@@ -0,0 +1 @@
|
|||||||
|
EXPO_PUBLIC_DEFAULT_SERVER_URL=http://192.168.1.100:8080
|
||||||
26
mobile/.eslintrc.js
Normal file
26
mobile/.eslintrc.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
sourceType: 'module',
|
||||||
|
ecmaFeatures: {
|
||||||
|
jsx: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: ['@typescript-eslint', 'react', 'react-hooks'],
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:react/recommended',
|
||||||
|
'plugin:react-hooks/recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
],
|
||||||
|
settings: {
|
||||||
|
react: {
|
||||||
|
version: 'detect',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'react/react-in-jsx-scope': 'off',
|
||||||
|
},
|
||||||
|
};
|
||||||
41
mobile/.gitignore
vendored
Normal file
41
mobile/.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Expo
|
||||||
|
.expo/
|
||||||
|
dist/
|
||||||
|
web-build/
|
||||||
|
expo-env.d.ts
|
||||||
|
|
||||||
|
# Native
|
||||||
|
.kotlin/
|
||||||
|
*.orig.*
|
||||||
|
*.jks
|
||||||
|
*.p8
|
||||||
|
*.p12
|
||||||
|
*.key
|
||||||
|
*.mobileprovision
|
||||||
|
|
||||||
|
# Metro
|
||||||
|
.metro-health-check*
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.*
|
||||||
|
yarn-debug.*
|
||||||
|
yarn-error.*
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env*.local
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# generated native folders
|
||||||
|
/ios
|
||||||
|
/android
|
||||||
4
mobile/.prettierrc
Normal file
4
mobile/.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
||||||
38
mobile/App.tsx
Normal file
38
mobile/App.tsx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { NavigationContainer, DarkTheme } from '@react-navigation/native';
|
||||||
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
||||||
|
import { StatusBar } from 'expo-status-bar';
|
||||||
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||||
|
import { ThemeProvider } from './src/theme/ThemeContext';
|
||||||
|
import { RootNavigator } from './src/navigation/RootNavigator';
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
useEffect(() => {
|
||||||
|
(globalThis as { __appStartTime?: number }).__appStartTime = Date.now();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const navigationTheme = {
|
||||||
|
...DarkTheme,
|
||||||
|
colors: {
|
||||||
|
...DarkTheme.colors,
|
||||||
|
background: '#0A0E1A',
|
||||||
|
card: '#0D1117',
|
||||||
|
text: '#E2E8F0',
|
||||||
|
border: '#1E293B',
|
||||||
|
primary: '#32B8C6',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
||||||
|
<SafeAreaProvider>
|
||||||
|
<ThemeProvider>
|
||||||
|
<NavigationContainer theme={navigationTheme}>
|
||||||
|
<RootNavigator />
|
||||||
|
</NavigationContainer>
|
||||||
|
</ThemeProvider>
|
||||||
|
</SafeAreaProvider>
|
||||||
|
<StatusBar style="light" />
|
||||||
|
</GestureHandlerRootView>
|
||||||
|
);
|
||||||
|
}
|
||||||
12
mobile/app.config.ts
Normal file
12
mobile/app.config.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export default {
|
||||||
|
name: 'WiFi-DensePose',
|
||||||
|
slug: 'wifi-densepose',
|
||||||
|
version: '1.0.0',
|
||||||
|
ios: {
|
||||||
|
bundleIdentifier: 'com.ruvnet.wifidensepose',
|
||||||
|
},
|
||||||
|
android: {
|
||||||
|
package: 'com.ruvnet.wifidensepose',
|
||||||
|
},
|
||||||
|
// Use expo-env and app-level defaults from the project configuration when available.
|
||||||
|
};
|
||||||
30
mobile/app.json
Normal file
30
mobile/app.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"expo": {
|
||||||
|
"name": "mobile",
|
||||||
|
"slug": "mobile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"orientation": "portrait",
|
||||||
|
"icon": "./assets/icon.png",
|
||||||
|
"userInterfaceStyle": "light",
|
||||||
|
"splash": {
|
||||||
|
"image": "./assets/splash-icon.png",
|
||||||
|
"resizeMode": "contain",
|
||||||
|
"backgroundColor": "#ffffff"
|
||||||
|
},
|
||||||
|
"ios": {
|
||||||
|
"supportsTablet": true
|
||||||
|
},
|
||||||
|
"android": {
|
||||||
|
"adaptiveIcon": {
|
||||||
|
"backgroundColor": "#E6F4FE",
|
||||||
|
"foregroundImage": "./assets/android-icon-foreground.png",
|
||||||
|
"backgroundImage": "./assets/android-icon-background.png",
|
||||||
|
"monochromeImage": "./assets/android-icon-monochrome.png"
|
||||||
|
},
|
||||||
|
"predictiveBackGestureEnabled": false
|
||||||
|
},
|
||||||
|
"web": {
|
||||||
|
"favicon": "./assets/favicon.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
mobile/assets/android-icon-background.png
Normal file
BIN
mobile/assets/android-icon-background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
mobile/assets/android-icon-foreground.png
Normal file
BIN
mobile/assets/android-icon-foreground.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
BIN
mobile/assets/android-icon-monochrome.png
Normal file
BIN
mobile/assets/android-icon-monochrome.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
BIN
mobile/assets/favicon.png
Normal file
BIN
mobile/assets/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
mobile/assets/icon.png
Normal file
BIN
mobile/assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 384 KiB |
BIN
mobile/assets/splash-icon.png
Normal file
BIN
mobile/assets/splash-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
9
mobile/babel.config.js
Normal file
9
mobile/babel.config.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
module.exports = function (api) {
|
||||||
|
api.cache(true);
|
||||||
|
return {
|
||||||
|
presets: ['babel-preset-expo'],
|
||||||
|
plugins: [
|
||||||
|
'react-native-reanimated/plugin'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
};
|
||||||
0
mobile/e2e/.maestro/config.yaml
Normal file
0
mobile/e2e/.maestro/config.yaml
Normal file
0
mobile/e2e/live_screen.yaml
Normal file
0
mobile/e2e/live_screen.yaml
Normal file
0
mobile/e2e/mat_screen.yaml
Normal file
0
mobile/e2e/mat_screen.yaml
Normal file
0
mobile/e2e/offline_fallback.yaml
Normal file
0
mobile/e2e/offline_fallback.yaml
Normal file
0
mobile/e2e/settings_screen.yaml
Normal file
0
mobile/e2e/settings_screen.yaml
Normal file
0
mobile/e2e/vitals_screen.yaml
Normal file
0
mobile/e2e/vitals_screen.yaml
Normal file
0
mobile/e2e/zones_screen.yaml
Normal file
0
mobile/e2e/zones_screen.yaml
Normal file
17
mobile/eas.json
Normal file
17
mobile/eas.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"cli": {
|
||||||
|
"version": ">= 4.0.0"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"development": {
|
||||||
|
"developmentClient": true,
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"autoIncrement": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
4
mobile/index.ts
Normal file
4
mobile/index.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { registerRootComponent } from 'expo';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
registerRootComponent(App);
|
||||||
8
mobile/jest.config.js
Normal file
8
mobile/jest.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: 'jest-expo',
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
|
||||||
|
testPathIgnorePatterns: ['/src/__tests__/'],
|
||||||
|
transformIgnorePatterns: [
|
||||||
|
'node_modules/(?!(expo|expo-.+|react-native|@react-native|react-native-webview|react-native-reanimated|react-native-svg|react-native-safe-area-context|react-native-screens|@react-navigation|@expo|@unimodules|expo-modules-core)/)',
|
||||||
|
],
|
||||||
|
};
|
||||||
11
mobile/jest.setup.ts
Normal file
11
mobile/jest.setup.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
jest.mock('@react-native-async-storage/async-storage', () =>
|
||||||
|
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
|
||||||
|
);
|
||||||
|
|
||||||
|
jest.mock('react-native-wifi-reborn', () => ({
|
||||||
|
loadWifiList: jest.fn(async () => []),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('react-native-reanimated', () =>
|
||||||
|
require('react-native-reanimated/mock')
|
||||||
|
);
|
||||||
16327
mobile/package-lock.json
generated
Normal file
16327
mobile/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
mobile/package.json
Normal file
49
mobile/package.json
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "mobile",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"start": "expo start",
|
||||||
|
"android": "expo start --android",
|
||||||
|
"ios": "expo start --ios",
|
||||||
|
"web": "expo start --web",
|
||||||
|
"test": "jest",
|
||||||
|
"lint": "eslint ."
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@expo/vector-icons": "^15.0.2",
|
||||||
|
"@react-native-async-storage/async-storage": "2.2.0",
|
||||||
|
"@react-navigation/bottom-tabs": "^7.15.3",
|
||||||
|
"@react-navigation/native": "^7.1.31",
|
||||||
|
"axios": "^1.13.6",
|
||||||
|
"expo": "~55.0.4",
|
||||||
|
"expo-status-bar": "~55.0.4",
|
||||||
|
"react": "19.2.0",
|
||||||
|
"react-native": "0.83.2",
|
||||||
|
"react-native-gesture-handler": "~2.30.0",
|
||||||
|
"react-native-reanimated": "4.2.1",
|
||||||
|
"react-native-safe-area-context": "~5.6.2",
|
||||||
|
"react-native-screens": "~4.23.0",
|
||||||
|
"react-native-svg": "15.15.3",
|
||||||
|
"react-native-webview": "13.16.0",
|
||||||
|
"react-native-wifi-reborn": "^4.13.6",
|
||||||
|
"victory-native": "^41.20.2",
|
||||||
|
"zustand": "^5.0.11"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@testing-library/jest-native": "^5.4.3",
|
||||||
|
"@testing-library/react-native": "^13.3.3",
|
||||||
|
"@types/jest": "^30.0.0",
|
||||||
|
"@types/react": "~19.2.2",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
||||||
|
"@typescript-eslint/parser": "^8.56.1",
|
||||||
|
"babel-preset-expo": "^55.0.10",
|
||||||
|
"eslint": "^10.0.2",
|
||||||
|
"jest": "^30.2.0",
|
||||||
|
"jest-expo": "^55.0.9",
|
||||||
|
"prettier": "^3.8.1",
|
||||||
|
"react-native-worklets": "^0.7.4",
|
||||||
|
"typescript": "~5.9.2"
|
||||||
|
},
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/components/GaugeArc.test.tsx
Normal file
5
mobile/src/__tests__/components/GaugeArc.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/components/HudOverlay.test.tsx
Normal file
5
mobile/src/__tests__/components/HudOverlay.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/components/OccupancyGrid.test.tsx
Normal file
5
mobile/src/__tests__/components/OccupancyGrid.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/components/SignalBar.test.tsx
Normal file
5
mobile/src/__tests__/components/SignalBar.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/components/SparklineChart.test.tsx
Normal file
5
mobile/src/__tests__/components/SparklineChart.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/components/StatusDot.test.tsx
Normal file
5
mobile/src/__tests__/components/StatusDot.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/hooks/usePoseStream.test.ts
Normal file
5
mobile/src/__tests__/hooks/usePoseStream.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/hooks/useRssiScanner.test.ts
Normal file
5
mobile/src/__tests__/hooks/useRssiScanner.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/hooks/useServerReachability.test.ts
Normal file
5
mobile/src/__tests__/hooks/useServerReachability.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/screens/LiveScreen.test.tsx
Normal file
5
mobile/src/__tests__/screens/LiveScreen.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/screens/MATScreen.test.tsx
Normal file
5
mobile/src/__tests__/screens/MATScreen.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/screens/SettingsScreen.test.tsx
Normal file
5
mobile/src/__tests__/screens/SettingsScreen.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/screens/VitalsScreen.test.tsx
Normal file
5
mobile/src/__tests__/screens/VitalsScreen.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/screens/ZonesScreen.test.tsx
Normal file
5
mobile/src/__tests__/screens/ZonesScreen.test.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/services/api.service.test.ts
Normal file
5
mobile/src/__tests__/services/api.service.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/services/rssi.service.test.ts
Normal file
5
mobile/src/__tests__/services/rssi.service.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/services/simulation.service.test.ts
Normal file
5
mobile/src/__tests__/services/simulation.service.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/services/ws.service.test.ts
Normal file
5
mobile/src/__tests__/services/ws.service.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/stores/matStore.test.ts
Normal file
5
mobile/src/__tests__/stores/matStore.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/stores/poseStore.test.ts
Normal file
5
mobile/src/__tests__/stores/poseStore.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/stores/settingsStore.test.ts
Normal file
5
mobile/src/__tests__/stores/settingsStore.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/utils/colorMap.test.ts
Normal file
5
mobile/src/__tests__/utils/colorMap.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/utils/ringBuffer.test.ts
Normal file
5
mobile/src/__tests__/utils/ringBuffer.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
5
mobile/src/__tests__/utils/urlValidator.test.ts
Normal file
5
mobile/src/__tests__/utils/urlValidator.test.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
describe('placeholder', () => {
|
||||||
|
it('passes', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
0
mobile/src/assets/images/wifi-icon.png
Normal file
0
mobile/src/assets/images/wifi-icon.png
Normal file
585
mobile/src/assets/webview/gaussian-splats.html
Normal file
585
mobile/src/assets/webview/gaussian-splats.html
Normal file
@@ -0,0 +1,585 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||||
|
/>
|
||||||
|
<meta
|
||||||
|
http-equiv="Content-Security-Policy"
|
||||||
|
content="default-src 'self'; script-src 'self' https://cdnjs.cloudflare.com https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'"
|
||||||
|
/>
|
||||||
|
<title>WiFi DensePose Splat Viewer</title>
|
||||||
|
<style>
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#gaussian-splat-root {
|
||||||
|
margin: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #0a0e1a;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#gaussian-splat-root {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="gaussian-splat-root"></div>
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r165/three.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/three@0.165.0/examples/js/controls/OrbitControls.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const postMessageToRN = (message) => {
|
||||||
|
if (!window.ReactNativeWebView || typeof window.ReactNativeWebView.postMessage !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
window.ReactNativeWebView.postMessage(JSON.stringify(message));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to post RN message', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const postError = (message) => {
|
||||||
|
postMessageToRN({
|
||||||
|
type: 'ERROR',
|
||||||
|
payload: {
|
||||||
|
message: typeof message === 'string' ? message : 'Unknown bridge error',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use global THREE from CDN
|
||||||
|
const getThree = () => window.THREE;
|
||||||
|
|
||||||
|
// ---- Custom Splat Shaders --------------------------------------------
|
||||||
|
|
||||||
|
const SPLAT_VERTEX = `
|
||||||
|
attribute float splatSize;
|
||||||
|
attribute vec3 splatColor;
|
||||||
|
attribute float splatOpacity;
|
||||||
|
|
||||||
|
varying vec3 vColor;
|
||||||
|
varying float vOpacity;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vColor = splatColor;
|
||||||
|
vOpacity = splatOpacity;
|
||||||
|
|
||||||
|
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
||||||
|
gl_PointSize = splatSize * (300.0 / -mvPosition.z);
|
||||||
|
gl_Position = projectionMatrix * mvPosition;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SPLAT_FRAGMENT = `
|
||||||
|
varying vec3 vColor;
|
||||||
|
varying float vOpacity;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// Circular soft-edge disc
|
||||||
|
float dist = length(gl_PointCoord - vec2(0.5));
|
||||||
|
if (dist > 0.5) discard;
|
||||||
|
float alpha = smoothstep(0.5, 0.2, dist) * vOpacity;
|
||||||
|
gl_FragColor = vec4(vColor, alpha);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
// ---- Color helpers ---------------------------------------------------
|
||||||
|
|
||||||
|
/** Map a scalar 0-1 to blue -> green -> red gradient */
|
||||||
|
function valueToColor(v) {
|
||||||
|
const clamped = Math.max(0, Math.min(1, v));
|
||||||
|
// blue(0) -> cyan(0.25) -> green(0.5) -> yellow(0.75) -> red(1)
|
||||||
|
let r;
|
||||||
|
let g;
|
||||||
|
let b;
|
||||||
|
if (clamped < 0.5) {
|
||||||
|
const t = clamped * 2;
|
||||||
|
r = 0;
|
||||||
|
g = t;
|
||||||
|
b = 1 - t;
|
||||||
|
} else {
|
||||||
|
const t = (clamped - 0.5) * 2;
|
||||||
|
r = t;
|
||||||
|
g = 1 - t;
|
||||||
|
b = 0;
|
||||||
|
}
|
||||||
|
return [r, g, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- GaussianSplatRenderer -------------------------------------------
|
||||||
|
|
||||||
|
class GaussianSplatRenderer {
|
||||||
|
/** @param {HTMLElement} container - DOM element to attach the renderer to */
|
||||||
|
constructor(container, opts = {}) {
|
||||||
|
const THREE = getThree();
|
||||||
|
if (!THREE) {
|
||||||
|
throw new Error('Three.js not loaded');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.container = container;
|
||||||
|
this.width = opts.width || container.clientWidth || 800;
|
||||||
|
this.height = opts.height || 500;
|
||||||
|
|
||||||
|
// Scene
|
||||||
|
this.scene = new THREE.Scene();
|
||||||
|
this.scene.background = new THREE.Color(0x0a0e1a);
|
||||||
|
|
||||||
|
// Camera — perspective looking down at the room
|
||||||
|
this.camera = new THREE.PerspectiveCamera(45, this.width / this.height, 0.1, 200);
|
||||||
|
this.camera.position.set(0, 10, 12);
|
||||||
|
this.camera.lookAt(0, 0, 0);
|
||||||
|
|
||||||
|
// Renderer
|
||||||
|
this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
||||||
|
this.renderer.setSize(this.width, this.height);
|
||||||
|
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
||||||
|
container.appendChild(this.renderer.domElement);
|
||||||
|
|
||||||
|
// Lights
|
||||||
|
const ambient = new THREE.AmbientLight(0x9ec7ff, 0.35);
|
||||||
|
this.scene.add(ambient);
|
||||||
|
|
||||||
|
const directional = new THREE.DirectionalLight(0x9ec7ff, 0.65);
|
||||||
|
directional.position.set(4, 10, 6);
|
||||||
|
directional.castShadow = false;
|
||||||
|
this.scene.add(directional);
|
||||||
|
|
||||||
|
// Grid & room
|
||||||
|
this._createRoom(THREE);
|
||||||
|
|
||||||
|
// Signal field splats (20x20 = 400 points on the floor plane)
|
||||||
|
this.gridSize = 20;
|
||||||
|
this._createFieldSplats(THREE);
|
||||||
|
|
||||||
|
// Node markers (ESP32 / router positions)
|
||||||
|
this._createNodeMarkers(THREE);
|
||||||
|
|
||||||
|
// Body disruption blob
|
||||||
|
this._createBodyBlob(THREE);
|
||||||
|
|
||||||
|
// Orbit controls for drag + pinch zoom
|
||||||
|
this.controls = new THREE.OrbitControls(this.camera, this.renderer.domElement);
|
||||||
|
this.controls.target.set(0, 0, 0);
|
||||||
|
this.controls.minDistance = 6;
|
||||||
|
this.controls.maxDistance = 40;
|
||||||
|
this.controls.enableDamping = true;
|
||||||
|
this.controls.dampingFactor = 0.08;
|
||||||
|
this.controls.update();
|
||||||
|
|
||||||
|
// Animation state
|
||||||
|
this._animFrame = null;
|
||||||
|
this._lastData = null;
|
||||||
|
this._fpsFrames = [];
|
||||||
|
this._lastFpsReport = 0;
|
||||||
|
|
||||||
|
// Start render loop
|
||||||
|
this._animate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Scene setup ---------------------------------------------------
|
||||||
|
|
||||||
|
_createRoom(THREE) {
|
||||||
|
// Floor grid (on y = 0), 20 units
|
||||||
|
const grid = new THREE.GridHelper(20, 20, 0x1a3a4a, 0x0d1f28);
|
||||||
|
grid.position.y = 0;
|
||||||
|
this.scene.add(grid);
|
||||||
|
|
||||||
|
// Room boundary wireframe
|
||||||
|
const boxGeo = new THREE.BoxGeometry(20, 6, 20);
|
||||||
|
const edges = new THREE.EdgesGeometry(boxGeo);
|
||||||
|
const line = new THREE.LineSegments(
|
||||||
|
edges,
|
||||||
|
new THREE.LineBasicMaterial({ color: 0x1a4a5a, opacity: 0.3, transparent: true }),
|
||||||
|
);
|
||||||
|
line.position.y = 3;
|
||||||
|
this.scene.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
_createFieldSplats(THREE) {
|
||||||
|
const count = this.gridSize * this.gridSize;
|
||||||
|
|
||||||
|
const positions = new Float32Array(count * 3);
|
||||||
|
const sizes = new Float32Array(count);
|
||||||
|
const colors = new Float32Array(count * 3);
|
||||||
|
const opacities = new Float32Array(count);
|
||||||
|
|
||||||
|
// Lay splats on the floor plane (y = 0.05 to sit just above grid)
|
||||||
|
for (let iz = 0; iz < this.gridSize; iz++) {
|
||||||
|
for (let ix = 0; ix < this.gridSize; ix++) {
|
||||||
|
const idx = iz * this.gridSize + ix;
|
||||||
|
positions[idx * 3 + 0] = (ix - this.gridSize / 2) + 0.5; // x
|
||||||
|
positions[idx * 3 + 1] = 0.05; // y
|
||||||
|
positions[idx * 3 + 2] = (iz - this.gridSize / 2) + 0.5; // z
|
||||||
|
|
||||||
|
sizes[idx] = 1.5;
|
||||||
|
colors[idx * 3] = 0.1;
|
||||||
|
colors[idx * 3 + 1] = 0.2;
|
||||||
|
colors[idx * 3 + 2] = 0.6;
|
||||||
|
opacities[idx] = 0.15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const geo = new THREE.BufferGeometry();
|
||||||
|
geo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||||
|
geo.setAttribute('splatSize', new THREE.BufferAttribute(sizes, 1));
|
||||||
|
geo.setAttribute('splatColor', new THREE.BufferAttribute(colors, 3));
|
||||||
|
geo.setAttribute('splatOpacity', new THREE.BufferAttribute(opacities, 1));
|
||||||
|
|
||||||
|
const mat = new THREE.ShaderMaterial({
|
||||||
|
vertexShader: SPLAT_VERTEX,
|
||||||
|
fragmentShader: SPLAT_FRAGMENT,
|
||||||
|
transparent: true,
|
||||||
|
depthWrite: false,
|
||||||
|
blending: THREE.AdditiveBlending,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.fieldPoints = new THREE.Points(geo, mat);
|
||||||
|
this.scene.add(this.fieldPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
_createNodeMarkers(THREE) {
|
||||||
|
// Router at center — green sphere
|
||||||
|
const routerGeo = new THREE.SphereGeometry(0.3, 16, 16);
|
||||||
|
const routerMat = new THREE.MeshBasicMaterial({ color: 0x00ff88, transparent: true, opacity: 0.8 });
|
||||||
|
this.routerMarker = new THREE.Mesh(routerGeo, routerMat);
|
||||||
|
this.routerMarker.position.set(0, 0.5, 0);
|
||||||
|
this.scene.add(this.routerMarker);
|
||||||
|
|
||||||
|
// ESP32 node — cyan sphere (default position, updated from data)
|
||||||
|
const nodeGeo = new THREE.SphereGeometry(0.25, 16, 16);
|
||||||
|
const nodeMat = new THREE.MeshBasicMaterial({ color: 0x00ccff, transparent: true, opacity: 0.8 });
|
||||||
|
this.nodeMarker = new THREE.Mesh(nodeGeo, nodeMat);
|
||||||
|
this.nodeMarker.position.set(2, 0.5, 1.5);
|
||||||
|
this.scene.add(this.nodeMarker);
|
||||||
|
}
|
||||||
|
|
||||||
|
_createBodyBlob(THREE) {
|
||||||
|
// A cluster of splats representing body disruption
|
||||||
|
const count = 64;
|
||||||
|
const positions = new Float32Array(count * 3);
|
||||||
|
const sizes = new Float32Array(count);
|
||||||
|
const colors = new Float32Array(count * 3);
|
||||||
|
const opacities = new Float32Array(count);
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
// Random sphere distribution
|
||||||
|
const theta = Math.random() * Math.PI * 2;
|
||||||
|
const phi = Math.acos(2 * Math.random() - 1);
|
||||||
|
const r = Math.random() * 1.5;
|
||||||
|
positions[i * 3] = r * Math.sin(phi) * Math.cos(theta);
|
||||||
|
positions[i * 3 + 1] = r * Math.cos(phi) + 2;
|
||||||
|
positions[i * 3 + 2] = r * Math.sin(phi) * Math.sin(theta);
|
||||||
|
|
||||||
|
sizes[i] = 2 + Math.random() * 3;
|
||||||
|
colors[i * 3] = 0.2;
|
||||||
|
colors[i * 3 + 1] = 0.8;
|
||||||
|
colors[i * 3 + 2] = 0.3;
|
||||||
|
opacities[i] = 0.0; // hidden until presence detected
|
||||||
|
}
|
||||||
|
|
||||||
|
const geo = new THREE.BufferGeometry();
|
||||||
|
geo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||||
|
geo.setAttribute('splatSize', new THREE.BufferAttribute(sizes, 1));
|
||||||
|
geo.setAttribute('splatColor', new THREE.BufferAttribute(colors, 3));
|
||||||
|
geo.setAttribute('splatOpacity', new THREE.BufferAttribute(opacities, 1));
|
||||||
|
|
||||||
|
const mat = new THREE.ShaderMaterial({
|
||||||
|
vertexShader: SPLAT_VERTEX,
|
||||||
|
fragmentShader: SPLAT_FRAGMENT,
|
||||||
|
transparent: true,
|
||||||
|
depthWrite: false,
|
||||||
|
blending: THREE.AdditiveBlending,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.bodyBlob = new THREE.Points(geo, mat);
|
||||||
|
this.scene.add(this.bodyBlob);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Data update --------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the visualization with new sensing data.
|
||||||
|
* @param {object} data - sensing_update JSON from ws_server
|
||||||
|
*/
|
||||||
|
update(data) {
|
||||||
|
this._lastData = data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
|
const features = data.features || {};
|
||||||
|
const classification = data.classification || {};
|
||||||
|
const signalField = data.signal_field || {};
|
||||||
|
const nodes = data.nodes || [];
|
||||||
|
|
||||||
|
// -- Update signal field splats ------------------------------------
|
||||||
|
if (signalField.values && this.fieldPoints) {
|
||||||
|
const geo = this.fieldPoints.geometry;
|
||||||
|
const clr = geo.attributes.splatColor.array;
|
||||||
|
const sizes = geo.attributes.splatSize.array;
|
||||||
|
const opac = geo.attributes.splatOpacity.array;
|
||||||
|
const vals = signalField.values;
|
||||||
|
const count = Math.min(vals.length, this.gridSize * this.gridSize);
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const v = vals[i];
|
||||||
|
const [r, g, b] = valueToColor(v);
|
||||||
|
clr[i * 3] = r;
|
||||||
|
clr[i * 3 + 1] = g;
|
||||||
|
clr[i * 3 + 2] = b;
|
||||||
|
sizes[i] = 1.0 + v * 4.0;
|
||||||
|
opac[i] = 0.1 + v * 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
geo.attributes.splatColor.needsUpdate = true;
|
||||||
|
geo.attributes.splatSize.needsUpdate = true;
|
||||||
|
geo.attributes.splatOpacity.needsUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Update body blob ----------------------------------------------
|
||||||
|
if (this.bodyBlob) {
|
||||||
|
const bGeo = this.bodyBlob.geometry;
|
||||||
|
const bOpac = bGeo.attributes.splatOpacity.array;
|
||||||
|
const bClr = bGeo.attributes.splatColor.array;
|
||||||
|
const bSize = bGeo.attributes.splatSize.array;
|
||||||
|
|
||||||
|
const presence = classification.presence || false;
|
||||||
|
const motionLvl = classification.motion_level || 'absent';
|
||||||
|
const confidence = classification.confidence || 0;
|
||||||
|
const breathing = features.breathing_band_power || 0;
|
||||||
|
|
||||||
|
// Breathing pulsation
|
||||||
|
const breathPulse = 1.0 + Math.sin(Date.now() * 0.004) * Math.min(breathing * 3, 0.4);
|
||||||
|
|
||||||
|
for (let i = 0; i < bOpac.length; i++) {
|
||||||
|
if (presence) {
|
||||||
|
bOpac[i] = confidence * 0.4;
|
||||||
|
|
||||||
|
// Color by motion level
|
||||||
|
if (motionLvl === 'active') {
|
||||||
|
bClr[i * 3] = 1.0;
|
||||||
|
bClr[i * 3 + 1] = 0.2;
|
||||||
|
bClr[i * 3 + 2] = 0.1;
|
||||||
|
} else {
|
||||||
|
bClr[i * 3] = 0.1;
|
||||||
|
bClr[i * 3 + 1] = 0.8;
|
||||||
|
bClr[i * 3 + 2] = 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
bSize[i] = (2 + Math.random() * 2) * breathPulse;
|
||||||
|
} else {
|
||||||
|
bOpac[i] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bGeo.attributes.splatOpacity.needsUpdate = true;
|
||||||
|
bGeo.attributes.splatColor.needsUpdate = true;
|
||||||
|
bGeo.attributes.splatSize.needsUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Update node positions -----------------------------------------
|
||||||
|
if (nodes.length > 0 && nodes[0].position && this.nodeMarker) {
|
||||||
|
const pos = nodes[0].position;
|
||||||
|
this.nodeMarker.position.set(pos[0], 0.5, pos[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Render loop -------------------------------------------------
|
||||||
|
|
||||||
|
_animate() {
|
||||||
|
this._animFrame = requestAnimationFrame(() => this._animate());
|
||||||
|
|
||||||
|
const now = performance.now();
|
||||||
|
|
||||||
|
// Gentle router glow pulse
|
||||||
|
if (this.routerMarker) {
|
||||||
|
const pulse = 0.6 + 0.3 * Math.sin(now * 0.003);
|
||||||
|
this.routerMarker.material.opacity = pulse;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.controls.update();
|
||||||
|
this.renderer.render(this.scene, this.camera);
|
||||||
|
|
||||||
|
this._fpsFrames.push(now);
|
||||||
|
while (this._fpsFrames.length > 0 && this._fpsFrames[0] < now - 1000) {
|
||||||
|
this._fpsFrames.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (now - this._lastFpsReport >= 1000) {
|
||||||
|
const fps = this._fpsFrames.length;
|
||||||
|
this._lastFpsReport = now;
|
||||||
|
postMessageToRN({
|
||||||
|
type: 'FPS_TICK',
|
||||||
|
payload: { fps },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Resize / cleanup --------------------------------------------
|
||||||
|
|
||||||
|
resize(width, height) {
|
||||||
|
if (!width || !height) return;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.camera.aspect = width / height;
|
||||||
|
this.camera.updateProjectionMatrix();
|
||||||
|
this.renderer.setSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
if (this._animFrame) {
|
||||||
|
cancelAnimationFrame(this._animFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.controls?.dispose();
|
||||||
|
this.renderer.dispose();
|
||||||
|
if (this.renderer.domElement.parentNode) {
|
||||||
|
this.renderer.domElement.parentNode.removeChild(this.renderer.domElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expose renderer constructor for debugging/interop
|
||||||
|
window.GaussianSplatRenderer = GaussianSplatRenderer;
|
||||||
|
|
||||||
|
let renderer = null;
|
||||||
|
let pendingFrame = null;
|
||||||
|
let pendingResize = null;
|
||||||
|
|
||||||
|
const postSafeReady = () => {
|
||||||
|
postMessageToRN({ type: 'READY' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const routeMessage = (event) => {
|
||||||
|
let raw = event.data;
|
||||||
|
if (typeof raw === 'object' && raw != null && 'data' in raw) {
|
||||||
|
raw = raw.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = raw;
|
||||||
|
if (typeof raw === 'string') {
|
||||||
|
try {
|
||||||
|
message = JSON.parse(raw);
|
||||||
|
} catch (err) {
|
||||||
|
postError('Failed to parse RN message payload');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!message || typeof message !== 'object') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type === 'FRAME_UPDATE') {
|
||||||
|
const payload = message.payload || null;
|
||||||
|
if (!payload) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!renderer) {
|
||||||
|
pendingFrame = payload;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
renderer.update(payload);
|
||||||
|
} catch (error) {
|
||||||
|
postError((error && error.message) || 'Failed to update frame');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type === 'RESIZE') {
|
||||||
|
const dims = message.payload || {};
|
||||||
|
const w = Number(dims.width);
|
||||||
|
const h = Number(dims.height);
|
||||||
|
if (!Number.isFinite(w) || !Number.isFinite(h) || !w || !h) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!renderer) {
|
||||||
|
pendingResize = { width: w, height: h };
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
renderer.resize(w, h);
|
||||||
|
} catch (error) {
|
||||||
|
postError((error && error.message) || 'Failed to resize renderer');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type === 'DISPOSE') {
|
||||||
|
if (!renderer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
renderer.dispose();
|
||||||
|
} catch (error) {
|
||||||
|
postError((error && error.message) || 'Failed to dispose renderer');
|
||||||
|
}
|
||||||
|
renderer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildRenderer = () => {
|
||||||
|
const container = document.getElementById('gaussian-splat-root');
|
||||||
|
if (!container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
renderer = new GaussianSplatRenderer(container, {
|
||||||
|
width: container.clientWidth || window.innerWidth,
|
||||||
|
height: container.clientHeight || window.innerHeight,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (pendingFrame) {
|
||||||
|
renderer.update(pendingFrame);
|
||||||
|
pendingFrame = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pendingResize) {
|
||||||
|
renderer.resize(pendingResize.width, pendingResize.height);
|
||||||
|
pendingResize = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
postSafeReady();
|
||||||
|
} catch (error) {
|
||||||
|
renderer = null;
|
||||||
|
postError((error && error.message) || 'Failed to initialize renderer');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', buildRenderer);
|
||||||
|
} else {
|
||||||
|
buildRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('message', routeMessage);
|
||||||
|
window.addEventListener('resize', () => {
|
||||||
|
if (!renderer) {
|
||||||
|
pendingResize = {
|
||||||
|
width: window.innerWidth,
|
||||||
|
height: window.innerHeight,
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
renderer.resize(window.innerWidth, window.innerHeight);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
0
mobile/src/assets/webview/mat-dashboard.html
Normal file
0
mobile/src/assets/webview/mat-dashboard.html
Normal file
70
mobile/src/components/ConnectionBanner.tsx
Normal file
70
mobile/src/components/ConnectionBanner.tsx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
import { ThemedText } from './ThemedText';
|
||||||
|
|
||||||
|
type ConnectionState = 'connected' | 'simulated' | 'disconnected';
|
||||||
|
|
||||||
|
type ConnectionBannerProps = {
|
||||||
|
status: ConnectionState;
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolveState = (status: ConnectionState) => {
|
||||||
|
if (status === 'connected') {
|
||||||
|
return {
|
||||||
|
label: 'LIVE STREAM',
|
||||||
|
backgroundColor: '#0F6B2A',
|
||||||
|
textColor: '#E2FFEA',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === 'disconnected') {
|
||||||
|
return {
|
||||||
|
label: 'DISCONNECTED',
|
||||||
|
backgroundColor: '#8A1E2A',
|
||||||
|
textColor: '#FFE3E7',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
label: 'SIMULATED DATA',
|
||||||
|
backgroundColor: '#9A5F0C',
|
||||||
|
textColor: '#FFF3E1',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ConnectionBanner = ({ status }: ConnectionBannerProps) => {
|
||||||
|
const state = resolveState(status);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.banner,
|
||||||
|
{
|
||||||
|
backgroundColor: state.backgroundColor,
|
||||||
|
borderBottomColor: state.textColor,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<ThemedText preset="labelMd" style={[styles.text, { color: state.textColor }]}>
|
||||||
|
{state.label}
|
||||||
|
</ThemedText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
banner: {
|
||||||
|
position: 'absolute',
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
zIndex: 100,
|
||||||
|
paddingVertical: 6,
|
||||||
|
borderBottomWidth: 2,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
letterSpacing: 2,
|
||||||
|
fontWeight: '700',
|
||||||
|
},
|
||||||
|
});
|
||||||
66
mobile/src/components/ErrorBoundary.tsx
Normal file
66
mobile/src/components/ErrorBoundary.tsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { Component, ErrorInfo, ReactNode } from 'react';
|
||||||
|
import { Button, StyleSheet, View } from 'react-native';
|
||||||
|
import { ThemedText } from './ThemedText';
|
||||||
|
import { ThemedView } from './ThemedView';
|
||||||
|
|
||||||
|
type ErrorBoundaryProps = {
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ErrorBoundaryState = {
|
||||||
|
hasError: boolean;
|
||||||
|
error?: Error;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||||
|
constructor(props: ErrorBoundaryProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = { hasError: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
||||||
|
return { hasError: true, error };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||||
|
console.error('ErrorBoundary caught an error', error, errorInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRetry = () => {
|
||||||
|
this.setState({ hasError: false, error: undefined });
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.state.hasError) {
|
||||||
|
return (
|
||||||
|
<ThemedView style={styles.container}>
|
||||||
|
<ThemedText preset="displayMd">Something went wrong</ThemedText>
|
||||||
|
<ThemedText preset="bodySm" style={styles.message}>
|
||||||
|
{this.state.error?.message ?? 'An unexpected error occurred.'}
|
||||||
|
</ThemedText>
|
||||||
|
<View style={styles.buttonWrap}>
|
||||||
|
<Button title="Retry" onPress={this.handleRetry} />
|
||||||
|
</View>
|
||||||
|
</ThemedView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: 20,
|
||||||
|
gap: 12,
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
textAlign: 'center',
|
||||||
|
},
|
||||||
|
buttonWrap: {
|
||||||
|
marginTop: 8,
|
||||||
|
},
|
||||||
|
});
|
||||||
96
mobile/src/components/GaugeArc.tsx
Normal file
96
mobile/src/components/GaugeArc.tsx
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
import Animated, { useAnimatedProps, useSharedValue, withTiming } from 'react-native-reanimated';
|
||||||
|
import Svg, { Circle, G, Text as SvgText } from 'react-native-svg';
|
||||||
|
|
||||||
|
type GaugeArcProps = {
|
||||||
|
value: number;
|
||||||
|
max: number;
|
||||||
|
label: string;
|
||||||
|
unit: string;
|
||||||
|
color: string;
|
||||||
|
size?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AnimatedCircle = Animated.createAnimatedComponent(Circle);
|
||||||
|
|
||||||
|
export const GaugeArc = ({ value, max, label, unit, color, size = 140 }: GaugeArcProps) => {
|
||||||
|
const radius = (size - 20) / 2;
|
||||||
|
const circumference = 2 * Math.PI * radius;
|
||||||
|
const arcLength = circumference * 0.75;
|
||||||
|
const strokeWidth = 12;
|
||||||
|
const progress = useSharedValue(0);
|
||||||
|
|
||||||
|
const normalized = Math.max(0, Math.min(max > 0 ? value / max : 0, 1));
|
||||||
|
const displayText = `${value.toFixed(1)} ${unit}`;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
progress.value = withTiming(normalized, { duration: 600 });
|
||||||
|
}, [normalized, progress]);
|
||||||
|
|
||||||
|
const animatedStroke = useAnimatedProps(() => {
|
||||||
|
const dashOffset = arcLength - arcLength * progress.value;
|
||||||
|
return {
|
||||||
|
strokeDashoffset: dashOffset,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.wrapper}>
|
||||||
|
<Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
||||||
|
<G transform={`rotate(-135 ${size / 2} ${size / 2})`}>
|
||||||
|
<Circle
|
||||||
|
cx={size / 2}
|
||||||
|
cy={size / 2}
|
||||||
|
r={radius}
|
||||||
|
strokeWidth={strokeWidth}
|
||||||
|
stroke="#1E293B"
|
||||||
|
fill="none"
|
||||||
|
strokeDasharray={`${arcLength} ${circumference}`}
|
||||||
|
strokeLinecap="round"
|
||||||
|
/>
|
||||||
|
<AnimatedCircle
|
||||||
|
cx={size / 2}
|
||||||
|
cy={size / 2}
|
||||||
|
r={radius}
|
||||||
|
strokeWidth={strokeWidth}
|
||||||
|
stroke={color}
|
||||||
|
fill="none"
|
||||||
|
strokeDasharray={`${arcLength} ${circumference}`}
|
||||||
|
strokeLinecap="round"
|
||||||
|
animatedProps={animatedStroke}
|
||||||
|
/>
|
||||||
|
</G>
|
||||||
|
<SvgText
|
||||||
|
x={size / 2}
|
||||||
|
y={size / 2 - 4}
|
||||||
|
fill="#E2E8F0"
|
||||||
|
fontSize={18}
|
||||||
|
fontFamily="Courier New"
|
||||||
|
fontWeight="700"
|
||||||
|
textAnchor="middle"
|
||||||
|
>
|
||||||
|
{displayText}
|
||||||
|
</SvgText>
|
||||||
|
<SvgText
|
||||||
|
x={size / 2}
|
||||||
|
y={size / 2 + 16}
|
||||||
|
fill="#94A3B8"
|
||||||
|
fontSize={10}
|
||||||
|
fontFamily="Courier New"
|
||||||
|
textAnchor="middle"
|
||||||
|
letterSpacing="0.6"
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</SvgText>
|
||||||
|
</Svg>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
wrapper: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
0
mobile/src/components/HudOverlay.tsx
Normal file
0
mobile/src/components/HudOverlay.tsx
Normal file
60
mobile/src/components/LoadingSpinner.tsx
Normal file
60
mobile/src/components/LoadingSpinner.tsx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { StyleSheet, ViewStyle } from 'react-native';
|
||||||
|
import Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
|
||||||
|
import Svg, { Circle } from 'react-native-svg';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
|
||||||
|
type LoadingSpinnerProps = {
|
||||||
|
size?: number;
|
||||||
|
color?: string;
|
||||||
|
style?: ViewStyle;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LoadingSpinner = ({ size = 36, color = colors.accent, style }: LoadingSpinnerProps) => {
|
||||||
|
const rotation = useSharedValue(0);
|
||||||
|
const strokeWidth = Math.max(4, size * 0.14);
|
||||||
|
const center = size / 2;
|
||||||
|
const radius = center - strokeWidth;
|
||||||
|
const circumference = 2 * Math.PI * radius;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
rotation.value = withRepeat(withTiming(360, { duration: 900, easing: Easing.linear }), -1);
|
||||||
|
}, [rotation]);
|
||||||
|
|
||||||
|
const animatedStyle = useAnimatedStyle(() => ({
|
||||||
|
transform: [{ rotateZ: `${rotation.value}deg` }],
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View style={[styles.container, { width: size, height: size }, style, animatedStyle]} pointerEvents="none">
|
||||||
|
<Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
||||||
|
<Circle
|
||||||
|
cx={center}
|
||||||
|
cy={center}
|
||||||
|
r={radius}
|
||||||
|
stroke="rgba(255,255,255,0.2)"
|
||||||
|
strokeWidth={strokeWidth}
|
||||||
|
fill="none"
|
||||||
|
/>
|
||||||
|
<Circle
|
||||||
|
cx={center}
|
||||||
|
cy={center}
|
||||||
|
r={radius}
|
||||||
|
stroke={color}
|
||||||
|
strokeWidth={strokeWidth}
|
||||||
|
fill="none"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeDasharray={`${circumference * 0.3} ${circumference * 0.7}`}
|
||||||
|
strokeDashoffset={circumference * 0.2}
|
||||||
|
/>
|
||||||
|
</Svg>
|
||||||
|
</Animated.View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
71
mobile/src/components/ModeBadge.tsx
Normal file
71
mobile/src/components/ModeBadge.tsx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { StyleSheet } from 'react-native';
|
||||||
|
import { ThemedText } from './ThemedText';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
|
||||||
|
type Mode = 'CSI' | 'RSSI' | 'SIM' | 'LIVE';
|
||||||
|
|
||||||
|
const modeStyle: Record<
|
||||||
|
Mode,
|
||||||
|
{
|
||||||
|
background: string;
|
||||||
|
border: string;
|
||||||
|
color: string;
|
||||||
|
}
|
||||||
|
> = {
|
||||||
|
CSI: {
|
||||||
|
background: 'rgba(50, 184, 198, 0.25)',
|
||||||
|
border: colors.accent,
|
||||||
|
color: colors.accent,
|
||||||
|
},
|
||||||
|
RSSI: {
|
||||||
|
background: 'rgba(255, 165, 2, 0.2)',
|
||||||
|
border: colors.warn,
|
||||||
|
color: colors.warn,
|
||||||
|
},
|
||||||
|
SIM: {
|
||||||
|
background: 'rgba(255, 71, 87, 0.18)',
|
||||||
|
border: colors.simulated,
|
||||||
|
color: colors.simulated,
|
||||||
|
},
|
||||||
|
LIVE: {
|
||||||
|
background: 'rgba(46, 213, 115, 0.18)',
|
||||||
|
border: colors.connected,
|
||||||
|
color: colors.connected,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
type ModeBadgeProps = {
|
||||||
|
mode: Mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ModeBadge = ({ mode }: ModeBadgeProps) => {
|
||||||
|
const style = modeStyle[mode];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemedText
|
||||||
|
preset="labelMd"
|
||||||
|
style={[
|
||||||
|
styles.badge,
|
||||||
|
{
|
||||||
|
backgroundColor: style.background,
|
||||||
|
borderColor: style.border,
|
||||||
|
color: style.color,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{mode}
|
||||||
|
</ThemedText>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
badge: {
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: 999,
|
||||||
|
borderWidth: 1,
|
||||||
|
overflow: 'hidden',
|
||||||
|
letterSpacing: 1,
|
||||||
|
textAlign: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
147
mobile/src/components/OccupancyGrid.tsx
Normal file
147
mobile/src/components/OccupancyGrid.tsx
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import { useEffect, useMemo, useRef } from 'react';
|
||||||
|
import { StyleProp, ViewStyle } from 'react-native';
|
||||||
|
import Animated, { interpolateColor, useAnimatedProps, useSharedValue, withTiming, type SharedValue } from 'react-native-reanimated';
|
||||||
|
import Svg, { Circle, G, Rect } from 'react-native-svg';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
|
||||||
|
type Point = {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OccupancyGridProps = {
|
||||||
|
values: number[];
|
||||||
|
personPositions?: Point[];
|
||||||
|
size?: number;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const GRID_DIMENSION = 20;
|
||||||
|
const CELLS = GRID_DIMENSION * GRID_DIMENSION;
|
||||||
|
|
||||||
|
const toColor = (value: number): string => {
|
||||||
|
const clamped = Math.max(0, Math.min(1, value));
|
||||||
|
let r: number;
|
||||||
|
let g: number;
|
||||||
|
let b: number;
|
||||||
|
|
||||||
|
if (clamped < 0.5) {
|
||||||
|
const t = clamped * 2;
|
||||||
|
r = Math.round(255 * 0);
|
||||||
|
g = Math.round(255 * t);
|
||||||
|
b = Math.round(255 * (1 - t));
|
||||||
|
} else {
|
||||||
|
const t = (clamped - 0.5) * 2;
|
||||||
|
r = Math.round(255 * t);
|
||||||
|
g = Math.round(255 * (1 - t));
|
||||||
|
b = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `rgb(${r}, ${g}, ${b})`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AnimatedRect = Animated.createAnimatedComponent(Rect);
|
||||||
|
|
||||||
|
const normalizeValues = (values: number[]) => {
|
||||||
|
const normalized = new Array(CELLS).fill(0);
|
||||||
|
for (let i = 0; i < CELLS; i += 1) {
|
||||||
|
const value = values?.[i] ?? 0;
|
||||||
|
normalized[i] = Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0;
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CellProps = {
|
||||||
|
index: number;
|
||||||
|
size: number;
|
||||||
|
progress: SharedValue<number>;
|
||||||
|
previousColors: string[];
|
||||||
|
nextColors: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const Cell = ({ index, size, progress, previousColors, nextColors }: CellProps) => {
|
||||||
|
const col = index % GRID_DIMENSION;
|
||||||
|
const row = Math.floor(index / GRID_DIMENSION);
|
||||||
|
const cellSize = size / GRID_DIMENSION;
|
||||||
|
const x = col * cellSize;
|
||||||
|
const y = row * cellSize;
|
||||||
|
|
||||||
|
const animatedProps = useAnimatedProps(() => ({
|
||||||
|
fill: interpolateColor(
|
||||||
|
progress.value,
|
||||||
|
[0, 1],
|
||||||
|
[previousColors[index] ?? colors.surfaceAlt, nextColors[index] ?? colors.surfaceAlt],
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AnimatedRect
|
||||||
|
x={x}
|
||||||
|
y={y}
|
||||||
|
width={cellSize}
|
||||||
|
height={cellSize}
|
||||||
|
rx={1}
|
||||||
|
animatedProps={animatedProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const OccupancyGrid = ({
|
||||||
|
values,
|
||||||
|
personPositions = [],
|
||||||
|
size = 320,
|
||||||
|
style,
|
||||||
|
}: OccupancyGridProps) => {
|
||||||
|
const normalizedValues = useMemo(() => normalizeValues(values), [values]);
|
||||||
|
const previousColors = useRef<string[]>(normalizedValues.map(toColor));
|
||||||
|
const nextColors = useRef<string[]>(normalizedValues.map(toColor));
|
||||||
|
const progress = useSharedValue(1);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const next = normalizeValues(values);
|
||||||
|
previousColors.current = normalizedValues.map(toColor);
|
||||||
|
nextColors.current = next.map(toColor);
|
||||||
|
progress.value = 0;
|
||||||
|
progress.value = withTiming(1, { duration: 500 });
|
||||||
|
}, [values, normalizedValues, progress]);
|
||||||
|
|
||||||
|
const markers = useMemo(() => {
|
||||||
|
const cellSize = size / GRID_DIMENSION;
|
||||||
|
return personPositions.map(({ x, y }, idx) => {
|
||||||
|
const clampedX = Math.max(0, Math.min(GRID_DIMENSION - 1, Math.round(x)));
|
||||||
|
const clampedY = Math.max(0, Math.min(GRID_DIMENSION - 1, Math.round(y)));
|
||||||
|
const cx = (clampedX + 0.5) * cellSize;
|
||||||
|
const cy = (clampedY + 0.5) * cellSize;
|
||||||
|
const markerRadius = Math.max(3, cellSize * 0.25);
|
||||||
|
return (
|
||||||
|
<Circle
|
||||||
|
key={`person-${idx}`}
|
||||||
|
cx={cx}
|
||||||
|
cy={cy}
|
||||||
|
r={markerRadius}
|
||||||
|
fill={colors.accent}
|
||||||
|
stroke={colors.textPrimary}
|
||||||
|
strokeWidth={1}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}, [personPositions, size]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Svg width={size} height={size} style={style} viewBox={`0 0 ${size} ${size}`}>
|
||||||
|
<G>
|
||||||
|
{Array.from({ length: CELLS }).map((_, index) => (
|
||||||
|
<Cell
|
||||||
|
key={index}
|
||||||
|
index={index}
|
||||||
|
size={size}
|
||||||
|
progress={progress}
|
||||||
|
previousColors={previousColors.current}
|
||||||
|
nextColors={nextColors.current}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</G>
|
||||||
|
{markers}
|
||||||
|
</Svg>
|
||||||
|
);
|
||||||
|
};
|
||||||
62
mobile/src/components/SignalBar.tsx
Normal file
62
mobile/src/components/SignalBar.tsx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
||||||
|
import { ThemedText } from './ThemedText';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
|
||||||
|
type SignalBarProps = {
|
||||||
|
value: number;
|
||||||
|
label: string;
|
||||||
|
color?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const clamp01 = (value: number) => Math.max(0, Math.min(1, value));
|
||||||
|
|
||||||
|
export const SignalBar = ({ value, label, color = colors.accent }: SignalBarProps) => {
|
||||||
|
const progress = useSharedValue(clamp01(value));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
progress.value = withTiming(clamp01(value), { duration: 250 });
|
||||||
|
}, [value, progress]);
|
||||||
|
|
||||||
|
const animatedFill = useAnimatedStyle(() => ({
|
||||||
|
width: `${progress.value * 100}%`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<ThemedText preset="bodySm" style={styles.label}>
|
||||||
|
{label}
|
||||||
|
</ThemedText>
|
||||||
|
<View style={styles.track}>
|
||||||
|
<Animated.View style={[styles.fill, { backgroundColor: color }, animatedFill]} />
|
||||||
|
</View>
|
||||||
|
<ThemedText preset="bodySm" style={styles.percent}>
|
||||||
|
{Math.round(clamp01(value) * 100)}%
|
||||||
|
</ThemedText>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
gap: 6,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
marginBottom: 4,
|
||||||
|
},
|
||||||
|
track: {
|
||||||
|
height: 8,
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: colors.surfaceAlt,
|
||||||
|
overflow: 'hidden',
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
height: '100%',
|
||||||
|
borderRadius: 4,
|
||||||
|
},
|
||||||
|
percent: {
|
||||||
|
textAlign: 'right',
|
||||||
|
color: colors.textSecondary,
|
||||||
|
},
|
||||||
|
});
|
||||||
64
mobile/src/components/SparklineChart.tsx
Normal file
64
mobile/src/components/SparklineChart.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import { View, ViewStyle } from 'react-native';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
|
||||||
|
type SparklineChartProps = {
|
||||||
|
data: number[];
|
||||||
|
color?: string;
|
||||||
|
height?: number;
|
||||||
|
style?: ViewStyle;
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultHeight = 72;
|
||||||
|
|
||||||
|
export const SparklineChart = ({
|
||||||
|
data,
|
||||||
|
color = colors.accent,
|
||||||
|
height = defaultHeight,
|
||||||
|
style,
|
||||||
|
}: SparklineChartProps) => {
|
||||||
|
const normalizedData = data.length > 0 ? data : [0];
|
||||||
|
|
||||||
|
const chartData = useMemo(
|
||||||
|
() =>
|
||||||
|
normalizedData.map((value, index) => ({
|
||||||
|
x: index,
|
||||||
|
y: value,
|
||||||
|
})),
|
||||||
|
[normalizedData],
|
||||||
|
);
|
||||||
|
|
||||||
|
const yValues = normalizedData.map((value) => Number(value) || 0);
|
||||||
|
const yMin = Math.min(...yValues);
|
||||||
|
const yMax = Math.max(...yValues);
|
||||||
|
const yPadding = yMax - yMin === 0 ? 1 : (yMax - yMin) * 0.2;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={style}>
|
||||||
|
<View
|
||||||
|
accessibilityRole="image"
|
||||||
|
style={{
|
||||||
|
height,
|
||||||
|
width: '100%',
|
||||||
|
borderRadius: 4,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: color,
|
||||||
|
opacity: 0.2,
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{chartData.map((point) => (
|
||||||
|
<View key={point.x} style={{ position: 'absolute', left: `${(point.x / Math.max(normalizedData.length - 1, 1)) * 100}%` }} />
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
83
mobile/src/components/StatusDot.tsx
Normal file
83
mobile/src/components/StatusDot.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { StyleSheet, ViewStyle } from 'react-native';
|
||||||
|
import Animated, {
|
||||||
|
cancelAnimation,
|
||||||
|
Easing,
|
||||||
|
useAnimatedStyle,
|
||||||
|
useSharedValue,
|
||||||
|
withRepeat,
|
||||||
|
withSequence,
|
||||||
|
withTiming,
|
||||||
|
} from 'react-native-reanimated';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
|
||||||
|
type StatusType = 'connected' | 'simulated' | 'disconnected' | 'connecting';
|
||||||
|
|
||||||
|
type StatusDotProps = {
|
||||||
|
status: StatusType;
|
||||||
|
size?: number;
|
||||||
|
style?: ViewStyle;
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolveColor = (status: StatusType): string => {
|
||||||
|
if (status === 'connecting') return colors.warn;
|
||||||
|
return colors[status];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const StatusDot = ({ status, size = 10, style }: StatusDotProps) => {
|
||||||
|
const scale = useSharedValue(1);
|
||||||
|
const opacity = useSharedValue(1);
|
||||||
|
const isConnecting = status === 'connecting';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isConnecting) {
|
||||||
|
scale.value = withRepeat(
|
||||||
|
withSequence(
|
||||||
|
withTiming(1.35, { duration: 800, easing: Easing.out(Easing.cubic) }),
|
||||||
|
withTiming(1, { duration: 800, easing: Easing.in(Easing.cubic) }),
|
||||||
|
),
|
||||||
|
-1,
|
||||||
|
);
|
||||||
|
opacity.value = withRepeat(
|
||||||
|
withSequence(
|
||||||
|
withTiming(0.4, { duration: 800, easing: Easing.out(Easing.quad) }),
|
||||||
|
withTiming(1, { duration: 800, easing: Easing.in(Easing.quad) }),
|
||||||
|
),
|
||||||
|
-1,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelAnimation(scale);
|
||||||
|
cancelAnimation(opacity);
|
||||||
|
scale.value = 1;
|
||||||
|
opacity.value = 1;
|
||||||
|
}, [isConnecting, opacity, scale]);
|
||||||
|
|
||||||
|
const animatedStyle = useAnimatedStyle(() => ({
|
||||||
|
transform: [{ scale: scale.value }],
|
||||||
|
opacity: opacity.value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View
|
||||||
|
style={[
|
||||||
|
styles.dot,
|
||||||
|
{
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
backgroundColor: resolveColor(status),
|
||||||
|
borderRadius: size / 2,
|
||||||
|
},
|
||||||
|
animatedStyle,
|
||||||
|
style,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
dot: {
|
||||||
|
borderRadius: 999,
|
||||||
|
},
|
||||||
|
});
|
||||||
28
mobile/src/components/ThemedText.tsx
Normal file
28
mobile/src/components/ThemedText.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { ComponentPropsWithoutRef } from 'react';
|
||||||
|
import { StyleProp, Text, TextStyle } from 'react-native';
|
||||||
|
import { useTheme } from '../hooks/useTheme';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
import { typography } from '../theme/typography';
|
||||||
|
|
||||||
|
type TextPreset = keyof typeof typography;
|
||||||
|
type ColorKey = keyof typeof colors;
|
||||||
|
|
||||||
|
type ThemedTextProps = Omit<ComponentPropsWithoutRef<typeof Text>, 'style'> & {
|
||||||
|
preset?: TextPreset;
|
||||||
|
color?: ColorKey;
|
||||||
|
style?: StyleProp<TextStyle>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ThemedText = ({
|
||||||
|
preset = 'bodyMd',
|
||||||
|
color = 'textPrimary',
|
||||||
|
style,
|
||||||
|
...props
|
||||||
|
}: ThemedTextProps) => {
|
||||||
|
const { colors, typography } = useTheme();
|
||||||
|
|
||||||
|
const presetStyle = (typography as Record<TextPreset, TextStyle>)[preset];
|
||||||
|
const colorStyle = { color: colors[color] };
|
||||||
|
|
||||||
|
return <Text {...props} style={[presetStyle, colorStyle, style]} />;
|
||||||
|
};
|
||||||
24
mobile/src/components/ThemedView.tsx
Normal file
24
mobile/src/components/ThemedView.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { PropsWithChildren, forwardRef } from 'react';
|
||||||
|
import { View, ViewProps } from 'react-native';
|
||||||
|
import { useTheme } from '../hooks/useTheme';
|
||||||
|
|
||||||
|
type ThemedViewProps = PropsWithChildren<ViewProps>;
|
||||||
|
|
||||||
|
export const ThemedView = forwardRef<View, ThemedViewProps>(({ children, style, ...props }, ref) => {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
backgroundColor: colors.bg,
|
||||||
|
},
|
||||||
|
style,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
});
|
||||||
14
mobile/src/constants/api.ts
Normal file
14
mobile/src/constants/api.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
export const API_ROOT = '/api/v1';
|
||||||
|
|
||||||
|
export const API_POSE_STATUS_PATH = '/api/v1/pose/status';
|
||||||
|
export const API_POSE_FRAMES_PATH = '/api/v1/pose/frames';
|
||||||
|
export const API_POSE_ZONES_PATH = '/api/v1/pose/zones';
|
||||||
|
export const API_POSE_CURRENT_PATH = '/api/v1/pose/current';
|
||||||
|
export const API_STREAM_STATUS_PATH = '/api/v1/stream/status';
|
||||||
|
export const API_STREAM_POSE_PATH = '/api/v1/stream/pose';
|
||||||
|
export const API_MAT_EVENTS_PATH = '/api/v1/mat/events';
|
||||||
|
|
||||||
|
export const API_HEALTH_PATH = '/health';
|
||||||
|
export const API_HEALTH_SYSTEM_PATH = '/health/health';
|
||||||
|
export const API_HEALTH_READY_PATH = '/health/ready';
|
||||||
|
export const API_HEALTH_LIVE_PATH = '/health/live';
|
||||||
20
mobile/src/constants/simulation.ts
Normal file
20
mobile/src/constants/simulation.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export const SIMULATION_TICK_INTERVAL_MS = 500;
|
||||||
|
export const SIMULATION_GRID_SIZE = 20;
|
||||||
|
|
||||||
|
export const RSSI_BASE_DBM = -45;
|
||||||
|
export const RSSI_AMPLITUDE_DBM = 3;
|
||||||
|
|
||||||
|
export const VARIANCE_BASE = 1.5;
|
||||||
|
export const VARIANCE_AMPLITUDE = 1.0;
|
||||||
|
|
||||||
|
export const MOTION_BAND_MIN = 0.05;
|
||||||
|
export const MOTION_BAND_AMPLITUDE = 0.15;
|
||||||
|
export const BREATHING_BAND_MIN = 0.03;
|
||||||
|
export const BREATHING_BAND_AMPLITUDE = 0.08;
|
||||||
|
|
||||||
|
export const SIGNAL_FIELD_PRESENCE_LEVEL = 0.8;
|
||||||
|
|
||||||
|
export const BREATHING_BPM_MIN = 12;
|
||||||
|
export const BREATHING_BPM_MAX = 24;
|
||||||
|
export const HEART_BPM_MIN = 58;
|
||||||
|
export const HEART_BPM_MAX = 96;
|
||||||
3
mobile/src/constants/websocket.ts
Normal file
3
mobile/src/constants/websocket.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const WS_PATH = '/api/v1/stream/pose';
|
||||||
|
export const RECONNECT_DELAYS = [1000, 2000, 4000, 8000, 16000];
|
||||||
|
export const MAX_RECONNECT_ATTEMPTS = 10;
|
||||||
31
mobile/src/hooks/usePoseStream.ts
Normal file
31
mobile/src/hooks/usePoseStream.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { wsService } from '@/services/ws.service';
|
||||||
|
import { usePoseStore } from '@/stores/poseStore';
|
||||||
|
import { useSettingsStore } from '@/stores/settingsStore';
|
||||||
|
|
||||||
|
export interface UsePoseStreamResult {
|
||||||
|
connectionStatus: ReturnType<typeof usePoseStore.getState>['connectionStatus'];
|
||||||
|
lastFrame: ReturnType<typeof usePoseStore.getState>['lastFrame'];
|
||||||
|
isSimulated: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePoseStream(): UsePoseStreamResult {
|
||||||
|
const serverUrl = useSettingsStore((state) => state.serverUrl);
|
||||||
|
const connectionStatus = usePoseStore((state) => state.connectionStatus);
|
||||||
|
const lastFrame = usePoseStore((state) => state.lastFrame);
|
||||||
|
const isSimulated = usePoseStore((state) => state.isSimulated);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const unsubscribe = wsService.subscribe((frame) => {
|
||||||
|
usePoseStore.getState().handleFrame(frame);
|
||||||
|
});
|
||||||
|
wsService.connect(serverUrl);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
wsService.disconnect();
|
||||||
|
};
|
||||||
|
}, [serverUrl]);
|
||||||
|
|
||||||
|
return { connectionStatus, lastFrame, isSimulated };
|
||||||
|
}
|
||||||
31
mobile/src/hooks/useRssiScanner.ts
Normal file
31
mobile/src/hooks/useRssiScanner.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { rssiService, type WifiNetwork } from '@/services/rssi.service';
|
||||||
|
import { useSettingsStore } from '@/stores/settingsStore';
|
||||||
|
|
||||||
|
export function useRssiScanner(): { networks: WifiNetwork[]; isScanning: boolean } {
|
||||||
|
const enabled = useSettingsStore((state) => state.rssiScanEnabled);
|
||||||
|
const [networks, setNetworks] = useState<WifiNetwork[]>([]);
|
||||||
|
const [isScanning, setIsScanning] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!enabled) {
|
||||||
|
rssiService.stopScanning();
|
||||||
|
setIsScanning(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsubscribe = rssiService.subscribe((result) => {
|
||||||
|
setNetworks(result);
|
||||||
|
});
|
||||||
|
rssiService.startScanning(2000);
|
||||||
|
setIsScanning(true);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
rssiService.stopScanning();
|
||||||
|
setIsScanning(false);
|
||||||
|
};
|
||||||
|
}, [enabled]);
|
||||||
|
|
||||||
|
return { networks, isScanning };
|
||||||
|
}
|
||||||
52
mobile/src/hooks/useServerReachability.ts
Normal file
52
mobile/src/hooks/useServerReachability.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { apiService } from '@/services/api.service';
|
||||||
|
|
||||||
|
interface ServerReachability {
|
||||||
|
reachable: boolean;
|
||||||
|
latencyMs: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const POLL_MS = 10000;
|
||||||
|
|
||||||
|
export function useServerReachability(): ServerReachability {
|
||||||
|
const [state, setState] = useState<ServerReachability>({
|
||||||
|
reachable: false,
|
||||||
|
latencyMs: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let active = true;
|
||||||
|
|
||||||
|
const check = async () => {
|
||||||
|
const started = Date.now();
|
||||||
|
try {
|
||||||
|
await apiService.getStatus();
|
||||||
|
if (!active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState({
|
||||||
|
reachable: true,
|
||||||
|
latencyMs: Date.now() - started,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
if (!active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState({
|
||||||
|
reachable: false,
|
||||||
|
latencyMs: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void check();
|
||||||
|
const timer = setInterval(check, POLL_MS);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
active = false;
|
||||||
|
clearInterval(timer);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
4
mobile/src/hooks/useTheme.ts
Normal file
4
mobile/src/hooks/useTheme.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { ThemeContext, ThemeContextValue } from '../theme/ThemeContext';
|
||||||
|
|
||||||
|
export const useTheme = (): ThemeContextValue => useContext(ThemeContext);
|
||||||
0
mobile/src/hooks/useWebViewBridge.ts
Normal file
0
mobile/src/hooks/useWebViewBridge.ts
Normal file
162
mobile/src/navigation/MainTabs.tsx
Normal file
162
mobile/src/navigation/MainTabs.tsx
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
import React, { Suspense, useEffect, useState } from 'react';
|
||||||
|
import { ActivityIndicator } from 'react-native';
|
||||||
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||||
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
|
import { ThemedText } from '../components/ThemedText';
|
||||||
|
import { ThemedView } from '../components/ThemedView';
|
||||||
|
import { colors } from '../theme/colors';
|
||||||
|
import { MainTabsParamList } from './types';
|
||||||
|
|
||||||
|
const createPlaceholder = (label: string) => {
|
||||||
|
const Placeholder = () => (
|
||||||
|
<ThemedView style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<ThemedText preset="bodyLg">{label} screen not implemented yet</ThemedText>
|
||||||
|
<ThemedText preset="bodySm" color="textSecondary">
|
||||||
|
Placeholder shell
|
||||||
|
</ThemedText>
|
||||||
|
</ThemedView>
|
||||||
|
);
|
||||||
|
const LazyPlaceholder = React.lazy(async () => ({ default: Placeholder }));
|
||||||
|
|
||||||
|
const Wrapped = () => (
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<ThemedView style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<ActivityIndicator color={colors.accent} />
|
||||||
|
<ThemedText preset="bodySm" color="textSecondary" style={{ marginTop: 8 }}>
|
||||||
|
Loading {label}
|
||||||
|
</ThemedText>
|
||||||
|
</ThemedView>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<LazyPlaceholder />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
|
||||||
|
return Wrapped;
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadScreen = (path: string, label: string) => {
|
||||||
|
const fallback = createPlaceholder(label);
|
||||||
|
return React.lazy(async () => {
|
||||||
|
try {
|
||||||
|
const module = (await import(path)) as { default: React.ComponentType };
|
||||||
|
if (module?.default) {
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// keep fallback for shell-only screens
|
||||||
|
}
|
||||||
|
return { default: fallback } as { default: React.ComponentType };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const LiveScreen = loadScreen('../screens/LiveScreen', 'Live');
|
||||||
|
const VitalsScreen = loadScreen('../screens/VitalsScreen', 'Vitals');
|
||||||
|
const ZonesScreen = loadScreen('../screens/ZonesScreen', 'Zones');
|
||||||
|
const MATScreen = loadScreen('../screens/MATScreen', 'MAT');
|
||||||
|
const SettingsScreen = loadScreen('../screens/SettingsScreen', 'Settings');
|
||||||
|
|
||||||
|
const toIconName = (routeName: keyof MainTabsParamList) => {
|
||||||
|
switch (routeName) {
|
||||||
|
case 'Live':
|
||||||
|
return 'wifi';
|
||||||
|
case 'Vitals':
|
||||||
|
return 'heart';
|
||||||
|
case 'Zones':
|
||||||
|
return 'grid';
|
||||||
|
case 'MAT':
|
||||||
|
return 'shield-checkmark';
|
||||||
|
case 'Settings':
|
||||||
|
return 'settings';
|
||||||
|
default:
|
||||||
|
return 'ellipse';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMatAlertCount = async (): Promise<number> => {
|
||||||
|
try {
|
||||||
|
const mod = (await import('../stores/matStore')) as Record<string, unknown>;
|
||||||
|
const candidates = [mod.useMatStore, mod.useStore].filter((candidate) => {
|
||||||
|
return (
|
||||||
|
!!candidate &&
|
||||||
|
typeof candidate === 'function' &&
|
||||||
|
typeof (candidate as { getState?: () => unknown }).getState === 'function'
|
||||||
|
);
|
||||||
|
}) as Array<{ getState: () => { alerts?: unknown[] } }>;
|
||||||
|
|
||||||
|
for (const store of candidates) {
|
||||||
|
const alerts = store.getState().alerts;
|
||||||
|
if (Array.isArray(alerts)) {
|
||||||
|
return alerts.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const screens: ReadonlyArray<{ name: keyof MainTabsParamList; component: React.ComponentType }> = [
|
||||||
|
{ name: 'Live', component: LiveScreen },
|
||||||
|
{ name: 'Vitals', component: VitalsScreen },
|
||||||
|
{ name: 'Zones', component: ZonesScreen },
|
||||||
|
{ name: 'MAT', component: MATScreen },
|
||||||
|
{ name: 'Settings', component: SettingsScreen },
|
||||||
|
];
|
||||||
|
|
||||||
|
const Tab = createBottomTabNavigator<MainTabsParamList>();
|
||||||
|
|
||||||
|
const Suspended = ({ component: Component }: { component: React.ComponentType }) => (
|
||||||
|
<Suspense fallback={<ActivityIndicator color={colors.accent} />}>
|
||||||
|
<Component />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const MainTabs = () => {
|
||||||
|
const [matAlertCount, setMatAlertCount] = useState(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const readCount = async () => {
|
||||||
|
const count = await getMatAlertCount();
|
||||||
|
setMatAlertCount(count);
|
||||||
|
};
|
||||||
|
|
||||||
|
void readCount();
|
||||||
|
const timer = setInterval(readCount, 2000);
|
||||||
|
return () => clearInterval(timer);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tab.Navigator
|
||||||
|
screenOptions={({ route }) => ({
|
||||||
|
headerShown: false,
|
||||||
|
tabBarActiveTintColor: colors.accent,
|
||||||
|
tabBarInactiveTintColor: colors.textSecondary,
|
||||||
|
tabBarStyle: {
|
||||||
|
backgroundColor: '#0D1117',
|
||||||
|
borderTopColor: colors.border,
|
||||||
|
borderTopWidth: 1,
|
||||||
|
},
|
||||||
|
tabBarIcon: ({ color, size }) => <Ionicons name={toIconName(route.name)} size={size} color={color} />,
|
||||||
|
tabBarLabelStyle: {
|
||||||
|
fontFamily: 'Courier New',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
fontSize: 10,
|
||||||
|
},
|
||||||
|
tabBarLabel: ({ children, color }) => <ThemedText style={{ color }}>{children}</ThemedText>,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{screens.map(({ name, component }) => (
|
||||||
|
<Tab.Screen
|
||||||
|
key={name}
|
||||||
|
name={name}
|
||||||
|
options={{
|
||||||
|
tabBarBadge: name === 'MAT' ? (matAlertCount > 0 ? matAlertCount : undefined) : undefined,
|
||||||
|
}}
|
||||||
|
component={() => <Suspended component={component} />}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Tab.Navigator>
|
||||||
|
);
|
||||||
|
};
|
||||||
5
mobile/src/navigation/RootNavigator.tsx
Normal file
5
mobile/src/navigation/RootNavigator.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { MainTabs } from './MainTabs';
|
||||||
|
|
||||||
|
export const RootNavigator = () => {
|
||||||
|
return <MainTabs />;
|
||||||
|
};
|
||||||
11
mobile/src/navigation/types.ts
Normal file
11
mobile/src/navigation/types.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export type RootStackParamList = {
|
||||||
|
MainTabs: undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type MainTabsParamList = {
|
||||||
|
Live: undefined;
|
||||||
|
Vitals: undefined;
|
||||||
|
Zones: undefined;
|
||||||
|
MAT: undefined;
|
||||||
|
Settings: undefined;
|
||||||
|
};
|
||||||
41
mobile/src/screens/LiveScreen/GaussianSplatWebView.tsx
Normal file
41
mobile/src/screens/LiveScreen/GaussianSplatWebView.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { LayoutChangeEvent, StyleSheet } from 'react-native';
|
||||||
|
import type { RefObject } from 'react';
|
||||||
|
import { WebView, type WebViewMessageEvent } from 'react-native-webview';
|
||||||
|
import GAUSSIAN_SPLATS_HTML from '@/assets/webview/gaussian-splats.html';
|
||||||
|
|
||||||
|
type GaussianSplatWebViewProps = {
|
||||||
|
onMessage: (event: WebViewMessageEvent) => void;
|
||||||
|
onError: () => void;
|
||||||
|
webViewRef: RefObject<WebView | null>;
|
||||||
|
onLayout?: (event: LayoutChangeEvent) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GaussianSplatWebView = ({
|
||||||
|
onMessage,
|
||||||
|
onError,
|
||||||
|
webViewRef,
|
||||||
|
onLayout,
|
||||||
|
}: GaussianSplatWebViewProps) => {
|
||||||
|
const html = typeof GAUSSIAN_SPLATS_HTML === 'string' ? GAUSSIAN_SPLATS_HTML : '';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<WebView
|
||||||
|
ref={webViewRef}
|
||||||
|
source={{ html }}
|
||||||
|
originWhitelist={['*']}
|
||||||
|
allowFileAccess={false}
|
||||||
|
javaScriptEnabled
|
||||||
|
onMessage={onMessage}
|
||||||
|
onError={onError}
|
||||||
|
onLayout={onLayout}
|
||||||
|
style={styles.webView}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
webView: {
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: '#0A0E1A',
|
||||||
|
},
|
||||||
|
});
|
||||||
164
mobile/src/screens/LiveScreen/LiveHUD.tsx
Normal file
164
mobile/src/screens/LiveScreen/LiveHUD.tsx
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
import { Pressable, StyleSheet, View } from 'react-native';
|
||||||
|
import { memo, useCallback, useState } from 'react';
|
||||||
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
||||||
|
import { StatusDot } from '@/components/StatusDot';
|
||||||
|
import { ModeBadge } from '@/components/ModeBadge';
|
||||||
|
import { ThemedText } from '@/components/ThemedText';
|
||||||
|
import { formatConfidence, formatRssi } from '@/utils/formatters';
|
||||||
|
import { colors, spacing } from '@/theme';
|
||||||
|
import type { ConnectionStatus } from '@/types/sensing';
|
||||||
|
|
||||||
|
type LiveMode = 'LIVE' | 'SIM' | 'RSSI';
|
||||||
|
|
||||||
|
type LiveHUDProps = {
|
||||||
|
rssi?: number;
|
||||||
|
connectionStatus: ConnectionStatus;
|
||||||
|
fps: number;
|
||||||
|
confidence: number;
|
||||||
|
personCount: number;
|
||||||
|
mode: LiveMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const statusTextMap: Record<ConnectionStatus, string> = {
|
||||||
|
connected: 'Connected',
|
||||||
|
simulated: 'Simulated',
|
||||||
|
connecting: 'Connecting',
|
||||||
|
disconnected: 'Disconnected',
|
||||||
|
};
|
||||||
|
|
||||||
|
const statusDotStatusMap: Record<ConnectionStatus, 'connected' | 'simulated' | 'disconnected' | 'connecting'> = {
|
||||||
|
connected: 'connected',
|
||||||
|
simulated: 'simulated',
|
||||||
|
connecting: 'connecting',
|
||||||
|
disconnected: 'disconnected',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LiveHUD = memo(
|
||||||
|
({ rssi, connectionStatus, fps, confidence, personCount, mode }: LiveHUDProps) => {
|
||||||
|
const [panelVisible, setPanelVisible] = useState(true);
|
||||||
|
const panelAlpha = useSharedValue(1);
|
||||||
|
|
||||||
|
const togglePanel = useCallback(() => {
|
||||||
|
const next = !panelVisible;
|
||||||
|
setPanelVisible(next);
|
||||||
|
panelAlpha.value = withTiming(next ? 1 : 0, { duration: 220 });
|
||||||
|
}, [panelAlpha, panelVisible]);
|
||||||
|
|
||||||
|
const animatedPanelStyle = useAnimatedStyle(() => ({
|
||||||
|
opacity: panelAlpha.value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const statusText = statusTextMap[connectionStatus];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable style={StyleSheet.absoluteFill} onPress={togglePanel}>
|
||||||
|
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, animatedPanelStyle]}>
|
||||||
|
{/* App title */}
|
||||||
|
<View style={styles.topLeft}>
|
||||||
|
<ThemedText preset="labelLg" style={styles.appTitle}>
|
||||||
|
WiFi-DensePose
|
||||||
|
</ThemedText>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Status + FPS */}
|
||||||
|
<View style={styles.topRight}>
|
||||||
|
<View style={styles.row}>
|
||||||
|
<StatusDot status={statusDotStatusMap[connectionStatus]} size={10} />
|
||||||
|
<ThemedText preset="labelMd" style={styles.statusText}>
|
||||||
|
{statusText}
|
||||||
|
</ThemedText>
|
||||||
|
</View>
|
||||||
|
{fps > 0 && (
|
||||||
|
<View style={styles.row}>
|
||||||
|
<ThemedText preset="labelMd">{fps} FPS</ThemedText>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* Bottom panel */}
|
||||||
|
<View style={styles.bottomPanel}>
|
||||||
|
<View style={styles.bottomCell}>
|
||||||
|
<ThemedText preset="bodySm">RSSI</ThemedText>
|
||||||
|
<ThemedText preset="displayMd" style={styles.bigValue}>
|
||||||
|
{formatRssi(rssi)}
|
||||||
|
</ThemedText>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.bottomCell}>
|
||||||
|
<ModeBadge mode={mode} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.bottomCellRight}>
|
||||||
|
<ThemedText preset="bodySm">Confidence</ThemedText>
|
||||||
|
<ThemedText preset="bodyMd" style={styles.metaText}>
|
||||||
|
{formatConfidence(confidence)}
|
||||||
|
</ThemedText>
|
||||||
|
<ThemedText preset="bodySm">People: {personCount}</ThemedText>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Animated.View>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
topLeft: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: spacing.md,
|
||||||
|
left: spacing.md,
|
||||||
|
},
|
||||||
|
appTitle: {
|
||||||
|
color: colors.textPrimary,
|
||||||
|
},
|
||||||
|
topRight: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: spacing.md,
|
||||||
|
right: spacing.md,
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
gap: 4,
|
||||||
|
},
|
||||||
|
row: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: spacing.sm,
|
||||||
|
},
|
||||||
|
statusText: {
|
||||||
|
color: colors.textPrimary,
|
||||||
|
},
|
||||||
|
bottomPanel: {
|
||||||
|
position: 'absolute',
|
||||||
|
left: spacing.sm,
|
||||||
|
right: spacing.sm,
|
||||||
|
bottom: spacing.sm,
|
||||||
|
minHeight: 72,
|
||||||
|
borderRadius: 12,
|
||||||
|
backgroundColor: 'rgba(10,14,26,0.72)',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: 'rgba(50,184,198,0.35)',
|
||||||
|
paddingHorizontal: spacing.md,
|
||||||
|
paddingVertical: spacing.sm,
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
bottomCell: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
bottomCellRight: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
},
|
||||||
|
bigValue: {
|
||||||
|
color: colors.accent,
|
||||||
|
marginTop: 2,
|
||||||
|
marginBottom: 2,
|
||||||
|
},
|
||||||
|
metaText: {
|
||||||
|
color: colors.textPrimary,
|
||||||
|
marginBottom: 4,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
LiveHUD.displayName = 'LiveHUD';
|
||||||
215
mobile/src/screens/LiveScreen/index.tsx
Normal file
215
mobile/src/screens/LiveScreen/index.tsx
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
import { Button, LayoutChangeEvent, StyleSheet, View } from 'react-native';
|
||||||
|
import type { WebView } from 'react-native-webview';
|
||||||
|
import type { WebViewMessageEvent } from 'react-native-webview';
|
||||||
|
import { ErrorBoundary } from '@/components/ErrorBoundary';
|
||||||
|
import { LoadingSpinner } from '@/components/LoadingSpinner';
|
||||||
|
import { ThemedText } from '@/components/ThemedText';
|
||||||
|
import { ThemedView } from '@/components/ThemedView';
|
||||||
|
import { usePoseStream } from '@/hooks/usePoseStream';
|
||||||
|
import { colors, spacing } from '@/theme';
|
||||||
|
import type { ConnectionStatus, SensingFrame } from '@/types/sensing';
|
||||||
|
import { useGaussianBridge } from './useGaussianBridge';
|
||||||
|
import { GaussianSplatWebView } from './GaussianSplatWebView';
|
||||||
|
import { LiveHUD } from './LiveHUD';
|
||||||
|
|
||||||
|
type LiveMode = 'LIVE' | 'SIM' | 'RSSI';
|
||||||
|
|
||||||
|
const getMode = (
|
||||||
|
status: ConnectionStatus,
|
||||||
|
isSimulated: boolean,
|
||||||
|
frame: SensingFrame | null,
|
||||||
|
): LiveMode => {
|
||||||
|
if (isSimulated || frame?.source === 'simulated') {
|
||||||
|
return 'SIM';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === 'connected') {
|
||||||
|
return 'LIVE';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'RSSI';
|
||||||
|
};
|
||||||
|
|
||||||
|
const dispatchWebViewMessage = (webViewRef: { current: WebView | null }, message: unknown) => {
|
||||||
|
const webView = webViewRef.current;
|
||||||
|
if (!webView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = JSON.stringify(message);
|
||||||
|
webView.injectJavaScript(
|
||||||
|
`window.dispatchEvent(new MessageEvent('message', { data: ${JSON.stringify(payload)} })); true;`,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LiveScreen = () => {
|
||||||
|
const webViewRef = useRef<WebView | null>(null);
|
||||||
|
const { lastFrame, connectionStatus, isSimulated } = usePoseStream();
|
||||||
|
const bridge = useGaussianBridge(webViewRef);
|
||||||
|
|
||||||
|
const [webError, setWebError] = useState<string | null>(null);
|
||||||
|
const [viewerKey, setViewerKey] = useState(0);
|
||||||
|
const sendTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
const pendingFrameRef = useRef<SensingFrame | null>(null);
|
||||||
|
const lastSentAtRef = useRef(0);
|
||||||
|
|
||||||
|
const clearSendTimeout = useCallback(() => {
|
||||||
|
if (!sendTimeoutRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(sendTimeoutRef.current);
|
||||||
|
sendTimeoutRef.current = null;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!lastFrame) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingFrameRef.current = lastFrame;
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
const flush = () => {
|
||||||
|
if (!bridge.isReady || !pendingFrameRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bridge.sendFrame(pendingFrameRef.current);
|
||||||
|
lastSentAtRef.current = Date.now();
|
||||||
|
pendingFrameRef.current = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const waitMs = Math.max(0, 500 - (now - lastSentAtRef.current));
|
||||||
|
|
||||||
|
if (waitMs <= 0) {
|
||||||
|
flush();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearSendTimeout();
|
||||||
|
sendTimeoutRef.current = setTimeout(() => {
|
||||||
|
sendTimeoutRef.current = null;
|
||||||
|
flush();
|
||||||
|
}, waitMs);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearSendTimeout();
|
||||||
|
};
|
||||||
|
}, [bridge.isReady, lastFrame, bridge.sendFrame, clearSendTimeout]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
dispatchWebViewMessage(webViewRef, { type: 'DISPOSE' });
|
||||||
|
clearSendTimeout();
|
||||||
|
pendingFrameRef.current = null;
|
||||||
|
};
|
||||||
|
}, [clearSendTimeout]);
|
||||||
|
|
||||||
|
const onMessage = useCallback(
|
||||||
|
(event: WebViewMessageEvent) => {
|
||||||
|
bridge.onMessage(event);
|
||||||
|
},
|
||||||
|
[bridge],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onLayout = useCallback((event: LayoutChangeEvent) => {
|
||||||
|
const { width, height } = event.nativeEvent.layout;
|
||||||
|
if (width <= 0 || height <= 0 || Number.isNaN(width) || Number.isNaN(height)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchWebViewMessage(webViewRef, {
|
||||||
|
type: 'RESIZE',
|
||||||
|
payload: {
|
||||||
|
width: Math.max(1, Math.floor(width)),
|
||||||
|
height: Math.max(1, Math.floor(height)),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleWebError = useCallback(() => {
|
||||||
|
setWebError('Live renderer failed to initialize');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleRetry = useCallback(() => {
|
||||||
|
setWebError(null);
|
||||||
|
bridge.reset();
|
||||||
|
setViewerKey((value) => value + 1);
|
||||||
|
}, [bridge]);
|
||||||
|
|
||||||
|
const rssi = lastFrame?.features?.mean_rssi;
|
||||||
|
const personCount = lastFrame?.classification?.presence ? 1 : 0;
|
||||||
|
const mode = getMode(connectionStatus, isSimulated, lastFrame);
|
||||||
|
|
||||||
|
if (webError || bridge.error) {
|
||||||
|
return (
|
||||||
|
<ThemedView style={styles.fallbackWrap}>
|
||||||
|
<ThemedText preset="bodyLg">Live visualization failed</ThemedText>
|
||||||
|
<ThemedText preset="bodySm" color="textSecondary" style={styles.errorText}>
|
||||||
|
{webError ?? bridge.error}
|
||||||
|
</ThemedText>
|
||||||
|
<Button title="Retry" onPress={handleRetry} />
|
||||||
|
</ThemedView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ErrorBoundary>
|
||||||
|
<View style={styles.container}>
|
||||||
|
<GaussianSplatWebView
|
||||||
|
key={viewerKey}
|
||||||
|
webViewRef={webViewRef}
|
||||||
|
onMessage={onMessage}
|
||||||
|
onError={handleWebError}
|
||||||
|
onLayout={onLayout}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<LiveHUD
|
||||||
|
connectionStatus={connectionStatus}
|
||||||
|
fps={bridge.fps}
|
||||||
|
rssi={rssi}
|
||||||
|
confidence={lastFrame?.classification?.confidence ?? 0}
|
||||||
|
personCount={personCount}
|
||||||
|
mode={mode}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!bridge.isReady && (
|
||||||
|
<View style={styles.loadingWrap}>
|
||||||
|
<LoadingSpinner />
|
||||||
|
<ThemedText preset="bodyMd" style={styles.loadingText}>
|
||||||
|
Loading live renderer
|
||||||
|
</ThemedText>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: colors.bg,
|
||||||
|
},
|
||||||
|
loadingWrap: {
|
||||||
|
...StyleSheet.absoluteFillObject,
|
||||||
|
backgroundColor: colors.bg,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
},
|
||||||
|
loadingText: {
|
||||||
|
color: colors.textSecondary,
|
||||||
|
},
|
||||||
|
fallbackWrap: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: spacing.md,
|
||||||
|
padding: spacing.lg,
|
||||||
|
},
|
||||||
|
errorText: {
|
||||||
|
textAlign: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
97
mobile/src/screens/LiveScreen/useGaussianBridge.ts
Normal file
97
mobile/src/screens/LiveScreen/useGaussianBridge.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
import type { RefObject } from 'react';
|
||||||
|
import type { WebViewMessageEvent } from 'react-native-webview';
|
||||||
|
import { WebView } from 'react-native-webview';
|
||||||
|
import type { SensingFrame } from '@/types/sensing';
|
||||||
|
|
||||||
|
export type GaussianBridgeMessageType = 'READY' | 'FPS_TICK' | 'ERROR';
|
||||||
|
|
||||||
|
type BridgeMessage = {
|
||||||
|
type: GaussianBridgeMessageType;
|
||||||
|
payload?: {
|
||||||
|
fps?: number;
|
||||||
|
message?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const toJsonScript = (message: unknown): string => {
|
||||||
|
const serialized = JSON.stringify(message);
|
||||||
|
return `window.dispatchEvent(new MessageEvent('message', { data: ${JSON.stringify(serialized)} })); true;`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGaussianBridge = (webViewRef: RefObject<WebView | null>) => {
|
||||||
|
const [isReady, setIsReady] = useState(false);
|
||||||
|
const [fps, setFps] = useState(0);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const send = useCallback((message: unknown) => {
|
||||||
|
const webView = webViewRef.current;
|
||||||
|
if (!webView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
webView.injectJavaScript(toJsonScript(message));
|
||||||
|
}, [webViewRef]);
|
||||||
|
|
||||||
|
const sendFrame = useCallback(
|
||||||
|
(frame: SensingFrame) => {
|
||||||
|
send({
|
||||||
|
type: 'FRAME_UPDATE',
|
||||||
|
payload: frame,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[send],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onMessage = useCallback((event: WebViewMessageEvent) => {
|
||||||
|
let parsed: BridgeMessage | null = null;
|
||||||
|
const raw = event.nativeEvent.data;
|
||||||
|
|
||||||
|
if (typeof raw === 'string') {
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(raw) as BridgeMessage;
|
||||||
|
} catch {
|
||||||
|
setError('Invalid bridge message format');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (typeof raw === 'object' && raw !== null) {
|
||||||
|
parsed = raw as BridgeMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parsed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.type === 'READY') {
|
||||||
|
setIsReady(true);
|
||||||
|
setError(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.type === 'FPS_TICK') {
|
||||||
|
const fpsValue = parsed.payload?.fps;
|
||||||
|
if (typeof fpsValue === 'number' && Number.isFinite(fpsValue)) {
|
||||||
|
setFps(Math.max(0, Math.floor(fpsValue)));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed.type === 'ERROR') {
|
||||||
|
setError(parsed.payload?.message ?? 'Unknown bridge error');
|
||||||
|
setIsReady(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
sendFrame,
|
||||||
|
onMessage,
|
||||||
|
isReady,
|
||||||
|
fps,
|
||||||
|
error,
|
||||||
|
reset: () => {
|
||||||
|
setIsReady(false);
|
||||||
|
setFps(0);
|
||||||
|
setError(null);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
0
mobile/src/screens/MATScreen/AlertCard.tsx
Normal file
0
mobile/src/screens/MATScreen/AlertCard.tsx
Normal file
0
mobile/src/screens/MATScreen/AlertList.tsx
Normal file
0
mobile/src/screens/MATScreen/AlertList.tsx
Normal file
0
mobile/src/screens/MATScreen/MatWebView.tsx
Normal file
0
mobile/src/screens/MATScreen/MatWebView.tsx
Normal file
0
mobile/src/screens/MATScreen/SurvivorCounter.tsx
Normal file
0
mobile/src/screens/MATScreen/SurvivorCounter.tsx
Normal file
0
mobile/src/screens/MATScreen/index.tsx
Normal file
0
mobile/src/screens/MATScreen/index.tsx
Normal file
0
mobile/src/screens/MATScreen/useMatBridge.ts
Normal file
0
mobile/src/screens/MATScreen/useMatBridge.ts
Normal file
0
mobile/src/screens/SettingsScreen/RssiToggle.tsx
Normal file
0
mobile/src/screens/SettingsScreen/RssiToggle.tsx
Normal file
0
mobile/src/screens/SettingsScreen/ThemePicker.tsx
Normal file
0
mobile/src/screens/SettingsScreen/ThemePicker.tsx
Normal file
0
mobile/src/screens/SettingsScreen/index.tsx
Normal file
0
mobile/src/screens/SettingsScreen/index.tsx
Normal file
0
mobile/src/screens/VitalsScreen/BreathingGauge.tsx
Normal file
0
mobile/src/screens/VitalsScreen/BreathingGauge.tsx
Normal file
0
mobile/src/screens/VitalsScreen/HeartRateGauge.tsx
Normal file
0
mobile/src/screens/VitalsScreen/HeartRateGauge.tsx
Normal file
0
mobile/src/screens/VitalsScreen/MetricCard.tsx
Normal file
0
mobile/src/screens/VitalsScreen/MetricCard.tsx
Normal file
0
mobile/src/screens/VitalsScreen/index.tsx
Normal file
0
mobile/src/screens/VitalsScreen/index.tsx
Normal file
0
mobile/src/screens/ZonesScreen/FloorPlanSvg.tsx
Normal file
0
mobile/src/screens/ZonesScreen/FloorPlanSvg.tsx
Normal file
0
mobile/src/screens/ZonesScreen/ZoneLegend.tsx
Normal file
0
mobile/src/screens/ZonesScreen/ZoneLegend.tsx
Normal file
0
mobile/src/screens/ZonesScreen/index.tsx
Normal file
0
mobile/src/screens/ZonesScreen/index.tsx
Normal file
0
mobile/src/screens/ZonesScreen/useOccupancyGrid.ts
Normal file
0
mobile/src/screens/ZonesScreen/useOccupancyGrid.ts
Normal file
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user