Skip to content

Commit ad0c1d8

Browse files
committed
fix: direct mutation of store bug
1 parent a161b65 commit ad0c1d8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

GUI/ETVR/src/store/camera/camera.ts

+9
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ export const setCameraStatus = (camera: ICamera, status: CameraStatus) => {
108108
)
109109
}
110110

111+
export const setCameraWS = (camera: ICamera, ws: object) => {
112+
setState(
113+
produce((s) => {
114+
s.cameras = s.cameras.filter((c: { address: string }) => c.address !== camera.address)
115+
s.cameras.push({ ...camera, ws })
116+
}),
117+
)
118+
}
119+
111120
export const setSelectedCamera = (camera: ICamera) => {
112121
setState(
113122
produce((s) => {

GUI/ETVR/src/utils/hooks/websocket/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useWebSocket } from 'solidjs-use'
22
import { addNotification, ENotificationType } from '@hooks/notifications'
33
import { getGlobalNotificationsType } from '@store/app/settings/selectors'
4-
import { CameraStatus, setCameraStatus } from '@store/camera/camera'
4+
import { CameraStatus, setCameraStatus, setCameraWS } from '@store/camera/camera'
55
import { cameras } from '@store/camera/selectors'
66
import { isEmpty } from '@utils/index'
77
const PORT = 7856
@@ -32,7 +32,7 @@ export const generateWebsocketClients = () => {
3232
pongTimeout: 1000,
3333
},
3434
})
35-
camera.ws = { status, data, send, open, close }
35+
setCameraWS(camera, { status, data, send, open, close })
3636
return
3737
}
3838
})

0 commit comments

Comments
 (0)