import { DSP, DSPTypes, AppPage } from '../types'; import { SetDsps, NotifyFn } from './dspShared'; import { forDSP408, create as createDSP408 } from '../features/dsp408/dsp408'; import { DSP408Api } from '../features/dsp408/dsp408'; // import { forDSP204 } from './dsp204'; export type DSPInstance = { dsp: Extract; api: DSP408Api }; // | { dsp: Extract; api: DSP408Api }; export function createDSPInstance(dsp: DSP, setDsps: SetDsps, notify: NotifyFn): DSPInstance { switch (dsp.type) { case 'DSP408': return { dsp, api: forDSP408(dsp, setDsps, notify) }; case 'DSP204': throw new Error('DSP204 not yet implemented'); } } export async function addDSP( setDsps: SetDsps, setSelected: React.Dispatch>, setPage: React.Dispatch>, notify: NotifyFn, params: { name: string; type: DSPTypes; ip: string; port: number; deviceId: number; demo: boolean; } ) { try { const newDsp: DSP = params.type === 'DSP408' ? await createDSP408(params) : await Promise.reject('DSP204 not implemented'); setDsps((prev) => [...prev, newDsp]); setSelected(newDsp.id); setPage('view-dsp'); } catch (err) { notify(`Failed to add DSP: ${String(err)}`, 'error', params.name); } }