Skip to content

Commit

Permalink
feat: begin implementing websocket handler
Browse files Browse the repository at this point in the history
- add new tailwindcss plugin for kobalte ui
- begin setting up logic to handle camera loaders
  • Loading branch information
ZanzyTHEbar committed Feb 2, 2023
1 parent 29760dc commit 07377a9
Show file tree
Hide file tree
Showing 12 changed files with 5,545 additions and 22 deletions.
3 changes: 2 additions & 1 deletion GUI/ETVR/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"dependencies": {
"@builder.io/partytown": "^0.7.3",
"@kobalte/core": "^0.6.0",
"@kobalte/tailwindcss": "^0.4.1",
"@solid-primitives/i18n": "^1.1.2",
"@solid-primitives/map": "^0.3.1",
"@solidjs/meta": "^0.28.0",
Expand All @@ -72,4 +73,4 @@
"yarn": "^1.22.19",
"yup": "^0.32.11"
}
}
}
9 changes: 6 additions & 3 deletions GUI/ETVR/src/components/Camera/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Button } from '@kobalte/core'
import { FaSolidGear } from 'solid-icons/fa'
import CameraStatusIndicator from './CameraIndicator/CameraIndicator'
import { ICamera } from '@src/store/camera/camera'
import { ActiveStatus } from '@src/utils/utils'
import WebSocketHandler from '@components/WebSocket'
import { ICamera } from '@store/camera/camera'
import { ActiveStatus } from '@utils/utils'

export interface IProps extends ICamera {
onClick: () => void
Expand All @@ -18,7 +19,9 @@ const Camera = (props: IProps) => {
</div>
<div class="flex items-center">
<div class="flex items-center h-[100%]">
<div class=" text-[#FFFF] bg-[#FFFF] w-[155px] h-[155px] rounded-[14px]" />
<div class=" text-[#FFFF] bg-[#FFFF] w-[155px] h-[155px] rounded-[14px]">
<WebSocketHandler borderRadius="rounded-[14px]" />
</div>
</div>
<div class="bg-[#292D36] ml-[14px] rounded-[14px] h-[100%] p-[14px] ">
<div class="text-center pb-[14px]">
Expand Down
5 changes: 4 additions & 1 deletion GUI/ETVR/src/components/List/List.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button } from '@kobalte/core'
import { FaSolidGear } from 'solid-icons/fa'
import WebSocketHandler from '@components/WebSocket'
import { ICamera } from '@src/store/camera/camera'
import { ActiveStatus, CapitalizeFirstLetter } from '@src/utils/utils'
export interface IList extends ICamera {
Expand All @@ -11,7 +12,9 @@ const List = (props: IList) => {
<div class="grid grid-flow-col auto-cols-fr pl-[12px] pt-[12px] pb-[12px] rounded-[10px] mb-[20px] bg-[#333742] text-white">
<div class="flex items-center w-[500px]">
<div>
<div class="text-[#FFFF] bg-[#FFFF] w-[60px] h-[60px] rounded-[5px]" />
<div class="text-[#FFFF] bg-[#FFFF] w-[60px] h-[60px] rounded-[5px]">
<WebSocketHandler borderRadius="rounded-[5px]" />
</div>
</div>
<div>
<div class="flex items-center justify-center text-left pl-[10px]">
Expand Down
10 changes: 0 additions & 10 deletions GUI/ETVR/src/components/WebSocket/index.ts

This file was deleted.

50 changes: 50 additions & 0 deletions GUI/ETVR/src/components/WebSocket/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Image } from '@kobalte/core'
import { onMount, Show } from 'solid-js'
import icons from '@assets/images/index'
import { showCameraView } from '@store/ui/selectors'
import { initWebSocket } from '@utils/hooks/websocket'

interface IProps {
borderRadius: string
}

// TODO: Handle camera loaders here
const LoaderHandler = (props: IProps) => {
return (
<Image.Root>
<Image.Img
src={icons.logo}
alt="logo"
width="100%"
height="100%"
class={`${props.borderRadius}`}
/>
</Image.Root>
)
}

const WebSocketHandler = (props: IProps) => {
onMount(async () => {
initWebSocket()
})

return (
<div>
<Show
when={showCameraView()}
fallback={() => <LoaderHandler borderRadius={props.borderRadius} />}>
<video
id="camera__view"
/* mousedown="mouseDown($event)"
mouseup="mouseUp($event)"
mousemove="mouseMove($event)"
wheel="wheel($event)" */
class="camera__view"
autoplay
/>
</Show>
</div>
)
}

export default WebSocketHandler
2 changes: 1 addition & 1 deletion GUI/ETVR/src/components/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Image } from '@kobalte/core'
import { Link } from '@solidjs/router'
import CustomPopover from './CustomPopover/index'
import CustomPopover from './CustomPopover'
import icons from '@assets/images/index'
import './styles.css'

Expand Down
2 changes: 2 additions & 0 deletions GUI/ETVR/src/store/ui/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { createMemo } from 'solid-js'
import { uiState } from './ui'

export const connectingStatus = createMemo(() => uiState().connecting)
export const loaderStatus = createMemo(() => uiState().loader)
export const openModalStatus = createMemo(() => uiState().openModal)
export const menuOpenStatus = createMemo(() => uiState().menuOpen)
export const connectedUserName = createMemo(() => uiState().connectedUser)
export const showCameraView = createMemo(() => uiState().showCameraView)
export const notifications = createMemo(() => uiState().notifications)
export const displayMode = createMemo(() => uiState().displayMode)
18 changes: 18 additions & 0 deletions GUI/ETVR/src/store/ui/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IUiStore {
connecting?: boolean
openModal?: boolean
menuOpen?: IMenuOpen | null
showCameraView?: boolean
connectedUser: string
notifications?: ToasterStore<string>
displayMode: POPOVER_ID
Expand All @@ -48,6 +49,7 @@ export const defaultState = {
openModal: false,
menuOpen: null,
connectedUser: '',
showCameraView: false,
notifications: new ToasterStore<string>(),
displayMode: POPOVER_ID.GRIP,
}
Expand Down Expand Up @@ -93,6 +95,22 @@ export const setConnectedUser = (userName: string) => {
)
}

export const setLoader = (type: loaderType, value: boolean) => {
setState(
produce((s) => {
if (s.loader) s.loader[type] = value
}),
)
}

export const setShowCameraView = (showCameraView: boolean) => {
setState(
produce((s) => {
s.showCameraView = showCameraView
}),
)
}

export const notify = (title: string, body: string | undefined) => {
new Notification(title, { body: body || '' })
}
Expand Down
15 changes: 10 additions & 5 deletions GUI/ETVR/src/utils/hooks/websocket/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rtcWebSocket, rtcTimeout } from '@store/api/selectors'
import { rtcWebSocket, rtcTimeout, rtcConnectInterval } from '@store/api/selectors'
import { setRTCStatus, setConnectInterval, setRTCTimeout } from '@store/api/websocket'
import { RTCState } from '@utils/enums'

Expand Down Expand Up @@ -32,6 +32,9 @@ export const check = () => {
const initWebSocket = () => {
setRTCStatus(RTCState.CONNECTING)
rtcWebSocket().onopen = () => {
setRTCTimeout(250) // reset timer to 250 on open of websocket connection
clearTimeout(rtcConnectInterval()) // clear Interval on open of websocket connection

setRTCStatus(RTCState.CONNECTED)
setInterval(() => {
sendToRTCServer({
Expand All @@ -43,6 +46,8 @@ const initWebSocket = () => {
},
})
}, 1000 * 10)

console.log('[WebSocket Client]: Connection Opened')
}
//* TODO: Add notification to the user
rtcWebSocket().onerror = (e) => {
Expand All @@ -52,17 +57,17 @@ const initWebSocket = () => {
}
//* TODO: Add notification to the user
rtcWebSocket().onclose = (e) => {
//increment retry interval
setRTCTimeout((rtcTimeout() as number) + (rtcTimeout() as number))
//call check function after timeout
setConnectInterval(setTimeout(check, Math.min(10000, rtcTimeout() as number)))
console.log(
`[WebSocket Client]: Socket is closed. Reconnect will be attempted in ${Math.min(
10000 / 1000,
((rtcTimeout() as number) + (rtcTimeout() as number)) / 1000,
)} second.`,
e.reason,
)
//increment retry interval
setRTCTimeout((rtcTimeout() as number) + (rtcTimeout() as number))
//call check function after timeout
setConnectInterval(setTimeout(check, Math.min(10000, rtcTimeout() as number)))
}
}

Expand Down
6 changes: 5 additions & 1 deletion GUI/ETVR/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ module.exports = {
},

// eslint-disable-next-line no-undef
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
require('@kobalte/tailwindcss')({ prefix: 'kb' }),
],
}
Loading

0 comments on commit 07377a9

Please sign in to comment.