remnantchat/src/contexts/ShellContext.ts
Jeremy Kahn 291ed0c2b9
feat(connection-test): Display tracker connection status (#128)
* feat(ConnectionTest): track tracker state
* feat(ConnectionTest): show tracker searching state
* chore(deps): use github:jeremyckahn/trystero#feature/get-tracker-connections
* feat(connection-test): hide network indicator in non-room routes
* feat(connection-test): show peer searching status
* feat(connection-test): hide peer searching UI when not in a room
2023-07-13 09:50:54 -05:00

67 lines
2.3 KiB
TypeScript

import { createContext, Dispatch, SetStateAction } from 'react'
import { AlertOptions } from 'models/shell'
import { AudioState, ScreenShareState, VideoState, Peer } from 'models/chat'
import { PeerConnectionType } from 'services/PeerRoom/PeerRoom'
import { ConnectionTestResults } from 'components/Shell/useConnectionTest'
interface ShellContextProps {
tabHasFocus: boolean
showRoomControls: boolean
setShowRoomControls: Dispatch<SetStateAction<boolean>>
setTitle: Dispatch<SetStateAction<string>>
showAlert: (message: string, options?: AlertOptions) => void
roomId?: string
setRoomId: Dispatch<SetStateAction<string | undefined>>
password?: string
setPassword: Dispatch<SetStateAction<string | undefined>>
isPeerListOpen: boolean
setIsPeerListOpen: Dispatch<SetStateAction<boolean>>
peerList: Peer[]
setPeerList: Dispatch<SetStateAction<Peer[]>>
peerConnectionTypes: Record<string, PeerConnectionType>
setPeerConnectionTypes: Dispatch<
SetStateAction<Record<string, PeerConnectionType>>
>
audioState: AudioState
setAudioState: Dispatch<SetStateAction<AudioState>>
videoState: VideoState
setVideoState: Dispatch<SetStateAction<VideoState>>
screenState: ScreenShareState
setScreenState: Dispatch<SetStateAction<ScreenShareState>>
peerAudios: Record<string, HTMLAudioElement>
setPeerAudios: Dispatch<SetStateAction<Record<string, HTMLAudioElement>>>
customUsername: string
setCustomUsername: Dispatch<SetStateAction<string>>
connectionTestResults: ConnectionTestResults
}
export const ShellContext = createContext<ShellContextProps>({
tabHasFocus: true,
showRoomControls: false,
setShowRoomControls: () => {},
setTitle: () => {},
showAlert: () => {},
roomId: undefined,
setRoomId: () => {},
password: undefined,
setPassword: () => {},
isPeerListOpen: false,
setIsPeerListOpen: () => {},
peerList: [],
setPeerList: () => {},
peerConnectionTypes: {},
setPeerConnectionTypes: () => {},
audioState: AudioState.STOPPED,
setAudioState: () => {},
videoState: VideoState.STOPPED,
setVideoState: () => {},
screenState: ScreenShareState.NOT_SHARING,
setScreenState: () => {},
peerAudios: {},
setPeerAudios: () => {},
customUsername: '',
setCustomUsername: () => {},
connectionTestResults: { hasHost: false, hasRelay: false, hasTracker: false },
})