Skip to content

Commit 86c918a

Browse files
committed
feat: implement loader handler
1 parent 09e159a commit 86c918a

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

GUI/ETVR/src/components/Camera/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Camera = (props: IProps) => {
1515
<div class="responsive-flex-container w-full h-full flex items-center flex-row">
1616
<div class="responsive-iframe-container flex items-center h-full w-full ">
1717
<div class="h-full w-full">
18-
<WebSocketHandler />
18+
<WebSocketHandler status={props.status} />
1919
</div>
2020
</div>
2121
<div class="flex flex-col justify-between responsive-spacer-container bg-[#292D36] rounded-b-xl min-[1749px]:rounded-xl max-w-[209px] h-full w-full p-3">

GUI/ETVR/src/components/WebSocket/index.tsx

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
import { Show } from 'solid-js'
22
import { OrangeLoader } from '@components/Loader'
3+
import { CameraStatus } from '@store/camera/camera'
34
import { showCameraView } from '@store/ui/selectors'
45

5-
// TODO: Grab selected camera from store, connect if not connected, and display video stream on component mounted
6+
// TODO: Grab selected camera from store, connect if not connected, and display video stream on component mounted
7+
interface IWsProps {
8+
status: CameraStatus
9+
}
10+
11+
// TODO: Make other loader components for other statuses
12+
export const LoaderHandler = (props: IWsProps) => {
13+
return (
14+
<>
15+
<Show when={props.status == CameraStatus.LOADING}>
16+
<OrangeLoader width={100} unit={'%'} />
17+
</Show>
18+
<Show when={props.status == CameraStatus.ACTIVE}>
19+
<OrangeLoader width={100} unit={'%'} />
20+
</Show>
21+
<Show when={props.status == CameraStatus.DISABLED}>
22+
<OrangeLoader width={100} unit={'%'} />
23+
</Show>
24+
<Show when={props.status == CameraStatus.FAILED}>
25+
<OrangeLoader width={100} unit={'%'} />
26+
</Show>
27+
<Show when={props.status == CameraStatus.NONE}>
28+
<OrangeLoader width={100} unit={'%'} />
29+
</Show>
30+
</>
31+
)
32+
}
633

7-
const WebSocketHandler = () => {
34+
const WebSocketHandler = (props: IWsProps) => {
835
return (
936
<div class={'w-full h-full'}>
1037
<Show
@@ -14,7 +41,7 @@ const WebSocketHandler = () => {
1441
class={
1542
'text-[#FFFF] flex justify-center bg-[#2b2f38] rounded-t-xl min-[1750px]:rounded-xl w-full h-full'
1643
}>
17-
<OrangeLoader width={100} unit={'%'} />
44+
<LoaderHandler status={props.status} />
1845
</div>
1946
)}>
2047
<video class="bg-black rounded-t-xl w-full h-full" autoplay>

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

+5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
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'
45
import { cameras } from '@store/camera/selectors'
56
import { isEmpty } from '@utils/index'
67
const PORT = 7856
78
const LOCAL_HOST = 'wss://127.0.0.1'
89

910
export const generateWebsocketClients = () => {
1011
cameras().map((camera, i) => {
12+
setCameraStatus(camera, CameraStatus.LOADING)
1113
if (isEmpty(camera.ws)) {
14+
setCameraStatus(camera, CameraStatus.NONE)
1215
const { status, data, send, open, close } = useWebSocket(`${LOCAL_HOST}:${PORT + i}`, {
1316
autoReconnect: {
1417
retries: 3,
1518
delay: 1000,
1619
onFailed() {
20+
setCameraStatus(camera, CameraStatus.FAILED)
1721
addNotification({
1822
type: ENotificationType.ERROR,
1923
action: getGlobalNotificationsType(),
@@ -29,6 +33,7 @@ export const generateWebsocketClients = () => {
2933
},
3034
})
3135
camera.ws = { status, data, send, open, close }
36+
return
3237
}
3338
})
3439
}

0 commit comments

Comments
 (0)