Skip to content

Commit 07377a9

Browse files
committed
feat: begin implementing websocket handler
- add new tailwindcss plugin for kobalte ui - begin setting up logic to handle camera loaders
1 parent 29760dc commit 07377a9

File tree

12 files changed

+5545
-22
lines changed

12 files changed

+5545
-22
lines changed

GUI/ETVR/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"dependencies": {
5050
"@builder.io/partytown": "^0.7.3",
5151
"@kobalte/core": "^0.6.0",
52+
"@kobalte/tailwindcss": "^0.4.1",
5253
"@solid-primitives/i18n": "^1.1.2",
5354
"@solid-primitives/map": "^0.3.1",
5455
"@solidjs/meta": "^0.28.0",
@@ -72,4 +73,4 @@
7273
"yarn": "^1.22.19",
7374
"yup": "^0.32.11"
7475
}
75-
}
76+
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Button } from '@kobalte/core'
22
import { FaSolidGear } from 'solid-icons/fa'
33
import CameraStatusIndicator from './CameraIndicator/CameraIndicator'
4-
import { ICamera } from '@src/store/camera/camera'
5-
import { ActiveStatus } from '@src/utils/utils'
4+
import WebSocketHandler from '@components/WebSocket'
5+
import { ICamera } from '@store/camera/camera'
6+
import { ActiveStatus } from '@utils/utils'
67

78
export interface IProps extends ICamera {
89
onClick: () => void
@@ -18,7 +19,9 @@ const Camera = (props: IProps) => {
1819
</div>
1920
<div class="flex items-center">
2021
<div class="flex items-center h-[100%]">
21-
<div class=" text-[#FFFF] bg-[#FFFF] w-[155px] h-[155px] rounded-[14px]" />
22+
<div class=" text-[#FFFF] bg-[#FFFF] w-[155px] h-[155px] rounded-[14px]">
23+
<WebSocketHandler borderRadius="rounded-[14px]" />
24+
</div>
2225
</div>
2326
<div class="bg-[#292D36] ml-[14px] rounded-[14px] h-[100%] p-[14px] ">
2427
<div class="text-center pb-[14px]">

GUI/ETVR/src/components/List/List.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Button } from '@kobalte/core'
22
import { FaSolidGear } from 'solid-icons/fa'
3+
import WebSocketHandler from '@components/WebSocket'
34
import { ICamera } from '@src/store/camera/camera'
45
import { ActiveStatus, CapitalizeFirstLetter } from '@src/utils/utils'
56
export interface IList extends ICamera {
@@ -11,7 +12,9 @@ const List = (props: IList) => {
1112
<div class="grid grid-flow-col auto-cols-fr pl-[12px] pt-[12px] pb-[12px] rounded-[10px] mb-[20px] bg-[#333742] text-white">
1213
<div class="flex items-center w-[500px]">
1314
<div>
14-
<div class="text-[#FFFF] bg-[#FFFF] w-[60px] h-[60px] rounded-[5px]" />
15+
<div class="text-[#FFFF] bg-[#FFFF] w-[60px] h-[60px] rounded-[5px]">
16+
<WebSocketHandler borderRadius="rounded-[5px]" />
17+
</div>
1518
</div>
1619
<div>
1720
<div class="flex items-center justify-center text-left pl-[10px]">

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

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Image } from '@kobalte/core'
2+
import { onMount, Show } from 'solid-js'
3+
import icons from '@assets/images/index'
4+
import { showCameraView } from '@store/ui/selectors'
5+
import { initWebSocket } from '@utils/hooks/websocket'
6+
7+
interface IProps {
8+
borderRadius: string
9+
}
10+
11+
// TODO: Handle camera loaders here
12+
const LoaderHandler = (props: IProps) => {
13+
return (
14+
<Image.Root>
15+
<Image.Img
16+
src={icons.logo}
17+
alt="logo"
18+
width="100%"
19+
height="100%"
20+
class={`${props.borderRadius}`}
21+
/>
22+
</Image.Root>
23+
)
24+
}
25+
26+
const WebSocketHandler = (props: IProps) => {
27+
onMount(async () => {
28+
initWebSocket()
29+
})
30+
31+
return (
32+
<div>
33+
<Show
34+
when={showCameraView()}
35+
fallback={() => <LoaderHandler borderRadius={props.borderRadius} />}>
36+
<video
37+
id="camera__view"
38+
/* mousedown="mouseDown($event)"
39+
mouseup="mouseUp($event)"
40+
mousemove="mouseMove($event)"
41+
wheel="wheel($event)" */
42+
class="camera__view"
43+
autoplay
44+
/>
45+
</Show>
46+
</div>
47+
)
48+
}
49+
50+
export default WebSocketHandler

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Image } from '@kobalte/core'
22
import { Link } from '@solidjs/router'
3-
import CustomPopover from './CustomPopover/index'
3+
import CustomPopover from './CustomPopover'
44
import icons from '@assets/images/index'
55
import './styles.css'
66

GUI/ETVR/src/store/ui/selectors.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { createMemo } from 'solid-js'
22
import { uiState } from './ui'
33

44
export const connectingStatus = createMemo(() => uiState().connecting)
5+
export const loaderStatus = createMemo(() => uiState().loader)
56
export const openModalStatus = createMemo(() => uiState().openModal)
67
export const menuOpenStatus = createMemo(() => uiState().menuOpen)
78
export const connectedUserName = createMemo(() => uiState().connectedUser)
9+
export const showCameraView = createMemo(() => uiState().showCameraView)
810
export const notifications = createMemo(() => uiState().notifications)
911
export const displayMode = createMemo(() => uiState().displayMode)

GUI/ETVR/src/store/ui/ui.ts

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface IUiStore {
2727
connecting?: boolean
2828
openModal?: boolean
2929
menuOpen?: IMenuOpen | null
30+
showCameraView?: boolean
3031
connectedUser: string
3132
notifications?: ToasterStore<string>
3233
displayMode: POPOVER_ID
@@ -48,6 +49,7 @@ export const defaultState = {
4849
openModal: false,
4950
menuOpen: null,
5051
connectedUser: '',
52+
showCameraView: false,
5153
notifications: new ToasterStore<string>(),
5254
displayMode: POPOVER_ID.GRIP,
5355
}
@@ -93,6 +95,22 @@ export const setConnectedUser = (userName: string) => {
9395
)
9496
}
9597

98+
export const setLoader = (type: loaderType, value: boolean) => {
99+
setState(
100+
produce((s) => {
101+
if (s.loader) s.loader[type] = value
102+
}),
103+
)
104+
}
105+
106+
export const setShowCameraView = (showCameraView: boolean) => {
107+
setState(
108+
produce((s) => {
109+
s.showCameraView = showCameraView
110+
}),
111+
)
112+
}
113+
96114
export const notify = (title: string, body: string | undefined) => {
97115
new Notification(title, { body: body || '' })
98116
}

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rtcWebSocket, rtcTimeout } from '@store/api/selectors'
1+
import { rtcWebSocket, rtcTimeout, rtcConnectInterval } from '@store/api/selectors'
22
import { setRTCStatus, setConnectInterval, setRTCTimeout } from '@store/api/websocket'
33
import { RTCState } from '@utils/enums'
44

@@ -32,6 +32,9 @@ export const check = () => {
3232
const initWebSocket = () => {
3333
setRTCStatus(RTCState.CONNECTING)
3434
rtcWebSocket().onopen = () => {
35+
setRTCTimeout(250) // reset timer to 250 on open of websocket connection
36+
clearTimeout(rtcConnectInterval()) // clear Interval on open of websocket connection
37+
3538
setRTCStatus(RTCState.CONNECTED)
3639
setInterval(() => {
3740
sendToRTCServer({
@@ -43,6 +46,8 @@ const initWebSocket = () => {
4346
},
4447
})
4548
}, 1000 * 10)
49+
50+
console.log('[WebSocket Client]: Connection Opened')
4651
}
4752
//* TODO: Add notification to the user
4853
rtcWebSocket().onerror = (e) => {
@@ -52,17 +57,17 @@ const initWebSocket = () => {
5257
}
5358
//* TODO: Add notification to the user
5459
rtcWebSocket().onclose = (e) => {
55-
//increment retry interval
56-
setRTCTimeout((rtcTimeout() as number) + (rtcTimeout() as number))
57-
//call check function after timeout
58-
setConnectInterval(setTimeout(check, Math.min(10000, rtcTimeout() as number)))
5960
console.log(
6061
`[WebSocket Client]: Socket is closed. Reconnect will be attempted in ${Math.min(
6162
10000 / 1000,
6263
((rtcTimeout() as number) + (rtcTimeout() as number)) / 1000,
6364
)} second.`,
6465
e.reason,
6566
)
67+
//increment retry interval
68+
setRTCTimeout((rtcTimeout() as number) + (rtcTimeout() as number))
69+
//call check function after timeout
70+
setConnectInterval(setTimeout(check, Math.min(10000, rtcTimeout() as number)))
6671
}
6772
}
6873

GUI/ETVR/tailwind.config.cjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@ module.exports = {
5151
},
5252

5353
// eslint-disable-next-line no-undef
54-
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
54+
plugins: [
55+
require('@tailwindcss/forms'),
56+
require('@tailwindcss/typography'),
57+
require('@kobalte/tailwindcss')({ prefix: 'kb' }),
58+
],
5559
}

0 commit comments

Comments
 (0)