Skip to content

Commit

Permalink
fix ws URL
Browse files Browse the repository at this point in the history
  • Loading branch information
simbafs committed Aug 2, 2024
1 parent 943143d commit b80cfb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/src/hooks/useAttendance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { useToken } from './useToken'
import useWS from './useWS'
import { shouldParse } from '@/libs/util'
import { Diff } from './useDiff'
import { useOrigin } from './useOrigin'

// useAttendance get init value of attendance from server and listen to websocket for updates
export function useAttendance() {
const token = useToken()
const { socket, lastMessage } = useWS(`ws://localhost:3000/ws?token=${token}`)
const wsURL = useOrigin().replace('http', 'ws') + '/ws?token=' + token
console.log({ wsURL })
const { socket, lastMessage } = useWS(wsURL)
const [attendance, updateAttendance] = useReducer(
(
state: Attendance,
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/hooks/useOrigin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useEffect, useState } from 'react'

export function useOrigin() {
const [origin, setOrigin] = useState('')

useEffect(() => {
setOrigin(window.location.origin)
}, [])

return origin
}

0 comments on commit b80cfb8

Please sign in to comment.