|
1 | 1 | import { createMemo } from 'solid-js'
|
2 | 2 | import { createStore, produce } from 'solid-js/store'
|
3 | 3 |
|
4 |
| -export enum CameraStatus { |
| 4 | +export enum MdnsStatus { |
5 | 5 | ACTIVE = 'ACTIVE',
|
6 | 6 | DISABLED = 'DISABLED',
|
7 | 7 | LOADING = 'LOADING',
|
8 | 8 | FAILED = 'FAILED',
|
9 | 9 | }
|
10 | 10 |
|
11 |
| -export enum CameraType { |
12 |
| - WIRELESS = 'WIRELESS', |
13 |
| -} |
14 |
| - |
15 |
| -export interface ICamera { |
16 |
| - status: CameraStatus |
17 |
| - type: CameraType |
18 |
| - address: string |
19 |
| - activeCameraSection: string |
20 |
| -} |
21 |
| - |
22 | 11 | interface IMdnsStore {
|
23 |
| - connectedUser: string |
24 |
| - restClient: string |
25 |
| - camerasMap: ICameraComponents |
26 |
| -} |
27 |
| - |
28 |
| -interface ICameraComponents { |
29 |
| - [key: string]: ICamera |
30 |
| -} |
31 |
| - |
32 |
| -/* TEMPORARY - REMOVE WHEN NOT NEEDED */ |
33 |
| -/* const staticCamerasGenerator = new Array(5).fill(0).map(() => ({ |
34 |
| - status: CameraStatus.LOADING, |
35 |
| - type: CameraType.WIRELESS, |
36 |
| - address: `${Math.floor(Math.random() * 255)}`, |
37 |
| - activeCameraSection: 'Left Eye', |
38 |
| -})) */ |
39 |
| - |
40 |
| -const tempCameraComponents: ICameraComponents = { |
41 |
| - '192.168.0.204': { |
42 |
| - status: CameraStatus.LOADING, |
43 |
| - type: CameraType.WIRELESS, |
44 |
| - address: '192.168.0.204', |
45 |
| - activeCameraSection: 'Left Eye', |
46 |
| - }, |
47 |
| - '192.168.0.232': { |
48 |
| - status: CameraStatus.LOADING, |
49 |
| - type: CameraType.WIRELESS, |
50 |
| - address: '192.168.0.232', |
51 |
| - activeCameraSection: 'Left Eye', |
52 |
| - }, |
53 |
| - |
| 12 | + mdnsStatus: MdnsStatus |
54 | 13 | }
|
55 | 14 |
|
56 | 15 | export const defaultState: IMdnsStore = {
|
57 |
| - connectedUser: '', |
58 |
| - restClient: '', |
59 |
| - camerasMap: tempCameraComponents |
| 16 | + mdnsStatus: MdnsStatus.DISABLED, |
60 | 17 | }
|
61 | 18 |
|
62 | 19 | const [state, setState] = createStore<IMdnsStore>(defaultState)
|
63 | 20 |
|
64 |
| -export const setConnectedUser = (userName: string) => { |
65 |
| - setState( |
66 |
| - produce((s) => { |
67 |
| - s.connectedUser = userName |
68 |
| - }) |
69 |
| - ) |
70 |
| -} |
71 |
| - |
72 |
| -export const setAddCamera = (camera: ICamera) => { |
73 |
| - setState( |
74 |
| - produce((s) => { |
75 |
| - s.camerasMap[camera.address] = camera |
76 |
| - }) |
77 |
| - ) |
78 |
| -} |
79 |
| - |
80 |
| -export const setRemoveCamera = (cameraAddress: string) => { |
| 21 | +export const setMdnsStatus = (status: MdnsStatus) => { |
81 | 22 | setState(
|
82 | 23 | produce((s) => {
|
83 |
| - delete s.camerasMap[cameraAddress] |
| 24 | + s.mdnsStatus = status |
84 | 25 | })
|
85 | 26 | )
|
86 | 27 | }
|
|
0 commit comments