Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add permanent storage for deviceId #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/renderer/bridge/ipcs/devices/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ export function sendVideoInputDeviceList(devices: VideoDevice[]) {
export function sendActiveVideoInputId(id: string) {
const { GET_ACTIVE_VIDEO_INPUT_ID } = IPC.DEVICES

if (id) {
localStorage.setItem('deviceId', id)
}

ipcRenderer.send(GET_ACTIVE_VIDEO_INPUT_ID, id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function whenVideoInputChanges(fn: (...args: any[]) => void) {
const { WHEN_VIDEO_INPUT_CHANGES } = IPC.DEVICES

ipcRenderer.on(WHEN_VIDEO_INPUT_CHANGES, (_, ...args) => {
localStorage.setItem('deviceId', args[0])
fn(...args)
})
}
9 changes: 7 additions & 2 deletions src/renderer/hooks/useLookForVideoInputDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export function useLookForVideoInputDevices({
if (deviceId || !shouldLookForDevices) return

isLookingForDevices = setInterval(() => {
const deviceId = videoInputDevicesRef.current[0]?.deviceId
const target = localStorage.getItem('deviceId')

const deviceId =
videoInputDevicesRef.current?.find(
(device) => device.deviceId === target
)?.deviceId ?? videoInputDevicesRef.current[0]?.deviceId

callback()

Expand All @@ -23,7 +28,7 @@ export function useLookForVideoInputDevices({
setShouldLookForDevices(false)
}

setDeviceId(videoInputDevicesRef.current[0]?.deviceId)
setDeviceId(deviceId)
}, 1000)

return () => clearInterval(isLookingForDevices)
Expand Down