Free Motion Capture for Everyone πβ¨
TypeScript
lets make something work, eh?
jonmatthis45aabff32c1c
diff --git a/freemocap-ui/src/components/PauseUnpauseButton.tsx b/freemocap-ui/src/components/PauseUnpauseButton.tsxindex 51b1db43..c6fb2148 100644--- a/freemocap-ui/src/components/PauseUnpauseButton.tsx+++ b/freemocap-ui/src/components/PauseUnpauseButton.tsx@@ -4,7 +4,7 @@ import {Button, CircularProgress, keyframes} from '@mui/material';import {styled} from '@mui/system';import PlayArrowIcon from '@mui/icons-material/PlayArrow';import PauseIcon from '@mui/icons-material/Pause';-import {urlService} from "@/services/urlService";+import {pauseUnpauseThunk} from "@/store/thunks/pause-unpause-thunk";interface PauseUnpauseButtonProps {disabled?: boolean;@@ -39,60 +39,25 @@ export const PauseUnpauseButton: React.FC<PauseUnpauseButtonProps> = ({}) => {const [isPaused, setIsPaused] = useState(false);const [isLoading, setIsLoading] = useState(false);- // Add a timeout to prevent indefinite loading state- const handleApiCall = async (url: string, successAction: () => void) => {- setIsLoading(true);- // Create an AbortController to handle timeout- const controller = new AbortController();- const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout- try {- const response = await fetch(url, {- method: 'GET',- signal: controller.signal- });+ const handleClick = async () => {+ setIsLoading(true);- if (response.ok) {- successAction();- } else {- console.error(`API call failed: ${response.statusText}`);- }+ try {+ await pauseUnpauseThunk();+ // Toggle the paused state after successful API call+ setIsPaused(prev => !prev);} catch (error) {- console.error('An error occured:', error);+ console.error('Failed to pause/unpause cameras:', error);} finally {- clearTimeout(timeoutId);setIsLoading(false);}};- const handlePause = () => {- const pauseUrl = urlService.getSkellycamUrls().pauseCameras;- handleApiCall(pauseUrl, () => {- console.log('Paused successfully');- setIsPaused(true);- });- };-- const handleUnpause = () => {- const unpauseUrl = urlService.getSkellycamUrls().unpauseCameras;- handleApiCall(unpauseUrl, () => {- console.log('Unpaused successfully');- setIsPaused(false);- });- };-- const handleClick = () => {- if (isPaused) {- handleUnpause();- } else {- handlePause();- }- };-return (<PulsingButton- onClick={handleClick}+ onClick={ handleClick}variant="contained"pulsing={isPaused ? true : undefined}fullWidthdiff --git a/freemocap-ui/src/components/recording-info-panel/recording-subcomponents/StartStopRecordingButton.tsx b/freemocap-ui/src/components/recording-info-panel/recording-subcomponents/StartStopRecordingButton.tsxindex 5c1f5aea..83a3bde6 100644--- a/freemocap-ui/src/components/recording-info-panel/recording-subcomponents/StartStopRecordingButton.tsx+++ b/freemocap-ui/src/components/recording-info-panel/recording-subcomponents/StartStopRecordingButton.tsx@@ -25,7 +25,7 @@ const PulsingButton = styled(Button)(({isRecording}: { isRecording: boolean | unbackgroundColor: isRecording ? '#8d0a02' : '#005d94',borderStyle: 'solid',borderWidth: '3px',- borderColor: '#00ccff',+ borderColor: '#ff55ff',padding: 10,'&:hover': {borderColor: '#fb1402',diff --git a/freemocap-ui/src/components/server-settings-panel/ServerSettingsPanel.tsx b/freemocap-ui/src/components/server-settings-panel/ServerSettingsPanel.tsxindex 17941813..fd82921f 100644--- a/freemocap-ui/src/components/server-settings-panel/ServerSettingsPanel.tsx+++ b/freemocap-ui/src/components/server-settings-panel/ServerSettingsPanel.tsx@@ -34,7 +34,6 @@ export const ServerSettingsPanel = () => {return (<Box sx={{padding: 2, color: 'text.primary'}}><SimpleTreeView- defaultExpandedItems={['server-status']}slots={{collapseIcon: ExpandMoreIcon,expandIcon: ChevronRightIcon@@ -64,7 +63,7 @@ export const ServerSettingsPanel = () => {<Box sx={{pl: 2, pt: 1, borderTop: '2px solid', borderColor: 'darkcyan'}}><ServerConnectionStatus/><WebsocketConnectionStatus/>- <TreeItem itemId="server-settings" label="Server Settings">+ <TreeItem itemId="server-settings" label="Server Settings" disabled={true}><Box sx={{pl: 2, pt: 1, display: 'flex', flexDirection: 'column', gap: 2}}><FormControlLabelcontrol={@@ -108,7 +107,7 @@ export const ServerSettingsPanel = () => {</Box></TreeItem>- <TreeItem itemId="display-settings" label="Display Settings">+ <TreeItem itemId="display-settings" label="Display Settings" disabled={true}><Box sx={{pl: 2, pt: 1, display: 'flex', flexDirection: 'column', gap: 2}}><FormControlLabelcontrol={diff --git a/freemocap-ui/src/components/server-settings-panel/WebsocketConnectionStatus.tsx b/freemocap-ui/src/components/server-settings-panel/WebsocketConnectionStatus.tsxindex cf93133a..ea870386 100644--- a/freemocap-ui/src/components/server-settings-panel/WebsocketConnectionStatus.tsx+++ b/freemocap-ui/src/components/server-settings-panel/WebsocketConnectionStatus.tsx@@ -1,12 +1,10 @@import {Box, Tooltip, Typography} from "@mui/material";import {useWebSocketContext} from "@/context/websocket-context/WebSocketContext";-import {urlService} from "@/services/urlService";import CheckIcon from '@mui/icons-material/Check';import CloseIcon from '@mui/icons-material/Close';const WebsocketConnectionStatus = () => {const {isConnected, disconnect, connect} = useWebSocketContext();- const wsUrl = urlService.getWebSocketUrl();const handleToggleConnection = () => {if (isConnected) {diff --git a/freemocap-ui/src/components/ui-components/LeftSidePanelContent.tsx b/freemocap-ui/src/components/ui-components/LeftSidePanelContent.tsxindex 956de991..176ea073 100644--- a/freemocap-ui/src/components/ui-components/LeftSidePanelContent.tsx+++ b/freemocap-ui/src/components/ui-components/LeftSidePanelContent.tsx@@ -128,8 +128,8 @@ export const LeftSidePanelContent = () => {overflowX: 'hidden',...scrollbarStyles}}>- <AvailableCamerasPanel/><RecordingInfoPanel/>+ <AvailableCamerasPanel/><ProcessingPipelinePanel/></Box>diff --git a/freemocap-ui/src/config/appConfig.ts b/freemocap-ui/src/config/appConfig.tsdeleted file mode 100644index baf0f311..00000000--- a/freemocap-ui/src/config/appConfig.ts+++ /dev/null@@ -1,28 +0,0 @@-/**- * Application Configuration for Electron- *- * This module centralizes all configuration settings for the application,- * including environment-specific settings, API endpoints, and other constants.- */--const config = {- // Server configuration- server: {- host: 'localhost', // Default for local development- port: 8007, // Default port- protocol: 'http',- wsProtocol: 'ws',- basePath: '',- },-- // Application settings- // TODO - replace hardcoded values throughout the app with these settings- settings: {- defaultRecordingDirectory: '',- maxReconnectAttempts: 30,- reconnectBackoffFactor: 2,- maxReconnectDelay: 30000, // 30 seconds- }-};--export default config;diff --git a/freemocap-ui/src/config/appUrlService.ts b/freemocap-ui/src/config/appUrlService.tsnew file mode 100644index 00000000..3621fa29--- /dev/null+++ b/freemocap-ui/src/config/appUrlService.ts@@ -0,0 +1,50 @@+++export interface DefaultUrlConfig {+ host: string;+ port: number;+}++// Default URL configuration+const defaultUrlConfig: DefaultUrlConfig = {+ host: 'localhost',+ port: 8007,+};+++// Get the base HTTP URL+const getBaseHttpUrl = () => {+ const { host, port } = defaultUrlConfig;+ return `http://${host}:${port}`;+};++// Get a specific API URL+const getApiUrl = (path: string) => {+ return `${getBaseHttpUrl()}${path}`;+};++// Get WebSocket URL+const getWebSocketUrl = () => {+ const { host, port } = defaultUrlConfig;+ return `ws://${host}:${port}/skellycam/websocket/connect`;+};++// Get all HTTP endpoint URLs+const getHttpEndpointUrls = () => {+ return {+ detectCameras: getApiUrl('/skellycam/camera/detect'),+ createGroup: getApiUrl('/skellycam/camera/group/create'),+ closeAll: getApiUrl('/skellycam/camera/group/close/all'),+ updateConfigs: getApiUrl('/skellycam/camera/update'),+ startRecording: getApiUrl('/skellycam/camera/group/all/record/start'),+ stopRecording: getApiUrl('/skellycam/camera/group/all/record/stop'),+ pauseUnpauseCameras: getApiUrl('/skellycam/camera/group/all/pause_unpause'),+ };+};++export const urlService = {+ getBaseHttpUrl,+ getApiUrl,+ getWebSocketUrl,+ getHttpEndpointUrls,+};\ No newline at end of filediff --git a/freemocap-ui/src/services/urlService.ts b/freemocap-ui/src/services/urlService.tsdeleted file mode 100644index f5152e55..00000000--- a/freemocap-ui/src/services/urlService.ts+++ /dev/null@@ -1,57 +0,0 @@-/**- * URL Service- *- * Provides centralized URL generation for all API endpoints and WebSocket connections.- * This ensures consistency across the application and simplifies changes to URL structure.- */--import config from '@/config/appConfig';--class UrlService {- /**- * Builds the base URL for HTTP requests- */- getBaseHttpUrl(): string {- const { protocol, host, port } = config.server;- return `${protocol}://${host}:${port}${config.server.basePath}`;- }-- /**- * Builds the base WebSocket URL- */- getBaseWsUrl(): string {- const { wsProtocol, host, port } = config.server;- return `${wsProtocol}://${host}:${port}${config.server.basePath}`;- }-- /**- * Generates a complete API URL from a path- */- getApiUrl(path: string): string {- return `${this.getBaseHttpUrl()}${path}`;- }-- /**- * Generates a WebSocket connection URL- */- getWebSocketUrl(path: string = '/websocket/connect'): string {- return `${this.getBaseWsUrl()}${path}`;- }-- // Camera API endpoints- getSkellycamUrls() {- return {- detectCameras: this.getApiUrl('/skellycam/camera/detect'),- createCameraGroup: this.getApiUrl('/skellycam/camera/group/create'),- closeAllCameras: this.getApiUrl('/skellycam/camera/group/close/all'),- updateCameraConfigs: this.getApiUrl('/skellycam/camera/update'),- startRecording: this.getApiUrl('/skellycam/camera/group/all/record/start'),- stopRecording: this.getApiUrl('/skellycam/camera/group/all/record/stop'),- pauseCameras: this.getApiUrl('/skellycam/camera/group/all/pause'),- unpauseCameras: this.getApiUrl('/skellycam/camera/group/all/unpause'),- };- }-}--// Export as a singleton-export const urlService = new UrlService();diff --git a/freemocap-ui/src/store/thunks/close-cameras-thunks.ts b/freemocap-ui/src/store/thunks/close-cameras-thunks.tsindex bb6b62f4..1e9bd369 100644--- a/freemocap-ui/src/store/thunks/close-cameras-thunks.ts+++ b/freemocap-ui/src/store/thunks/close-cameras-thunks.ts@@ -1,5 +1,5 @@import {createAsyncThunk} from '@reduxjs/toolkit';-import {urlService} from "@/services/urlService";+import {urlService} from "@/config/appUrlService";@@ -8,7 +8,7 @@ export const closeCameras = createAsyncThunk(async () => {console.log(`Closing cameras...`);try {- const closeCamerasURL = urlService.getSkellycamUrls().closeAllCameras+ const closeCamerasURL = urlService.getHttpEndpointUrls().closeAll;console.log(`Sending close request to ${closeCamerasURL}`);diff --git a/freemocap-ui/src/store/thunks/connect-to-cameras-thunk.ts b/freemocap-ui/src/store/thunks/connect-to-cameras-thunk.tsindex 4421be34..0cd91eb7 100644--- a/freemocap-ui/src/store/thunks/connect-to-cameras-thunk.ts+++ b/freemocap-ui/src/store/thunks/connect-to-cameras-thunk.ts@@ -5,8 +5,8 @@ import {setLoading,updateCameraConfigs} from "@/store/slices/cameras-slices/camerasSlice";-import { urlService } from "@/services/urlService";import {CameraConfig} from "@/store/slices/cameras-slices/camera-types";+import {urlService} from "@/config/appUrlService";export const connectToCameras = createAsyncThunk('cameras/connect',@@ -21,7 +21,7 @@ export const connectToCameras = createAsyncThunk(}dispatch(setLoading(true));- const connectUrl = urlService.getSkellycamUrls().createCameraGroup;+ const connectUrl = urlService.getHttpEndpointUrls().createGroup;const payload = {camera_configs: cameraConfigsdiff --git a/freemocap-ui/src/store/thunks/detect-cameras-thunks/detect-cameras-server-thunk.ts b/freemocap-ui/src/store/thunks/detect-cameras-thunks/detect-cameras-server-thunk.tsindex fd766106..a2955563 100644--- a/freemocap-ui/src/store/thunks/detect-cameras-thunks/detect-cameras-server-thunk.ts+++ b/freemocap-ui/src/store/thunks/detect-cameras-thunks/detect-cameras-server-thunk.ts@@ -10,8 +10,8 @@ import {CameraDevice,createDefaultCameraConfig} from "@/store/slices/cameras-slices/camera-types";-import { urlService } from "@/services/urlService";import {RootState} from "@/store/AppStateStore";+import {urlService} from "@/config/appUrlService";export const detectCameraDevices = createAsyncThunk<CameraDevice[]@@ -21,7 +21,7 @@ export const detectCameraDevices = createAsyncThunk<dispatch(setLoading(true));try {- const connectUrl = urlService.getSkellycamUrls().detectCameras;+ const connectUrl = urlService.getHttpEndpointUrls().detectCameras;console.log(`Detecting cameras at ${connectUrl}`);const response = await fetch(connectUrl, {diff --git a/freemocap-ui/src/store/thunks/pause-unpause-thunk.ts b/freemocap-ui/src/store/thunks/pause-unpause-thunk.tsnew file mode 100644index 00000000..ea5dc265--- /dev/null+++ b/freemocap-ui/src/store/thunks/pause-unpause-thunk.ts@@ -0,0 +1,12 @@+import {urlService} from "@/config/appUrlService";++export const pauseUnpauseThunk = async () => {+ const pauseUnpauseUrl = urlService.getHttpEndpointUrls().pauseUnpauseCameras;+ const response = await fetch(pauseUnpauseUrl, {method: 'GET'});++ if (!response.ok) {+ throw new Error(`HTTP error! status: ${response.status}`);+ }++ return response;+};\ No newline at end of filediff --git a/freemocap-ui/src/store/thunks/start-stop-recording-thunks.ts b/freemocap-ui/src/store/thunks/start-stop-recording-thunks.tsindex d470a9e4..1dea1f82 100644--- a/freemocap-ui/src/store/thunks/start-stop-recording-thunks.ts+++ b/freemocap-ui/src/store/thunks/start-stop-recording-thunks.ts@@ -2,8 +2,7 @@import {createAsyncThunk} from '@reduxjs/toolkit';import {z} from 'zod';import {setRecordingInfo} from "@/store/slices/recordingInfoSlice";-import {selectConfigsForSelectedCameras} from "@/store/slices/cameras-slices/camerasSlice";-import {urlService} from "@/services/urlService";+import {urlService} from "@/config/appUrlService";const RecordStartRequestSchema = z.object({recording_name: z.string(),@@ -21,7 +20,7 @@ export const startRecording = createAsyncThunk<void, StartRecordingParams>(async ({recordingName, recordingDirectory}, {dispatch,}) => {console.log(`Starting recording with name: ${recordingName} in directory: ${recordingDirectory}`);try {- const recStartUrl = urlService.getSkellycamUrls().startRecording;+ const recStartUrl = urlService.getHttpEndpointUrls().startRecording;const requestPayload = RecordStartRequestSchema.parse({recording_name: recordingName,@@ -59,7 +58,7 @@ export const stopRecording = createAsyncThunk<void, void>(async (_, {dispatch}) => {console.log('Stopping recording...');try {- const recStopUrl = urlService.getSkellycamUrls().stopRecording;+ const recStopUrl = urlService.getHttpEndpointUrls().stopRecording;const response = await fetch(recStopUrl, {method: 'GET',});diff --git a/freemocap-ui/src/store/thunks/update-camera-configs-thunk.ts b/freemocap-ui/src/store/thunks/update-camera-configs-thunk.tsindex b9413e85..6c6fb52b 100644--- a/freemocap-ui/src/store/thunks/update-camera-configs-thunk.ts+++ b/freemocap-ui/src/store/thunks/update-camera-configs-thunk.ts@@ -6,14 +6,13 @@ import {setLoading, updateCameraConfig, updateCameraConfigs} from "@/store/slices/cameras-slices/camerasSlice";import { CameraConfig } from "../slices/cameras-slices/camera-types";-import {urlService} from "@/services/urlService";-+import {urlService} from "@/config/appUrlService";export const updateCameraConfigsThunk = createAsyncThunk('camera/update',async (_, { dispatch, getState }) => {const state = getState() as any;dispatch(setLoading(true));- const connectUrl = urlService.getSkellycamUrls().updateCameraConfigs+ const connectUrl = urlService.getHttpEndpointUrls().updateConfigs;const payload = {camera_configs: selectConfigsForSelectedCameras(state)diff --git a/uv.lock b/uv.lockindex a408e309..9fccc62c 100644--- a/uv.lock+++ b/uv.lock@@ -1758,7 +1758,7 @@ dependencies = [[[package]]name = "skellytracker"version = "2024.9.1019"-source = { git = "https://github.com/freemocap/skellytracker?branch=jon%2Fdevelopment#af80f5aa2d86fcf2a11c4cd4a0a2d655e01f2454" }+source = { git = "https://github.com/freemocap/skellytracker?branch=jon%2Fdevelopment#ae3bd730c12e8dcd79fa4ea00e9b8f21e4505f3f" }dependencies = [{ name = "numpy" },{ name = "numpydantic" },