Skip to content

Commit e8b4eb8

Browse files
author
Ryan Vogel
committed
fix(mobile-voice): restore camera and discovery in dev builds
1 parent 7c18b95 commit e8b4eb8

2 files changed

Lines changed: 37 additions & 37 deletions

File tree

packages/mobile-voice/src/app/index.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,22 +2735,22 @@ export default function DictationScreen() {
27352735
scanLockRef.current = false
27362736
const current =
27372737
camera ??
2738-
(await import("expo-camera")
2739-
.catch(() => null)
2740-
.then((mod) => {
2741-
if (!mod) return null
2742-
2738+
(() => {
2739+
try {
2740+
// Expo dev builds were failing to resolve this native module through async import().
2741+
const mod = require("expo-camera") as typeof import("expo-camera") & {
2742+
Camera?: { requestCameraPermissionsAsync?: unknown }
2743+
}
27432744
const direct = (mod as { requestCameraPermissionsAsync?: unknown }).requestCameraPermissionsAsync
2744-
const fromCamera = (mod as { Camera?: { requestCameraPermissionsAsync?: unknown } }).Camera
2745-
?.requestCameraPermissionsAsync
2745+
const fromCamera = mod.Camera?.requestCameraPermissionsAsync
27462746
let requestCameraPermissionsAsync: (() => Promise<{ granted: boolean }>) | null = null
27472747
if (typeof direct === "function") {
27482748
requestCameraPermissionsAsync = direct as () => Promise<{ granted: boolean }>
27492749
} else if (typeof fromCamera === "function") {
27502750
requestCameraPermissionsAsync = fromCamera as () => Promise<{ granted: boolean }>
27512751
}
27522752

2753-
if (!requestCameraPermissionsAsync) {
2753+
if (!mod.CameraView || !requestCameraPermissionsAsync) {
27542754
return null
27552755
}
27562756

@@ -2760,7 +2760,10 @@ export default function DictationScreen() {
27602760
}
27612761
setCamera(next)
27622762
return next
2763-
}))
2763+
} catch {
2764+
return null
2765+
}
2766+
})()
27642767
if (!current) {
27652768
Alert.alert("Scanner unavailable", "This build does not include camera support. Reinstall the latest dev build.")
27662769
return

packages/mobile-voice/src/hooks/use-mdns-discovery.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -214,41 +214,38 @@ export function useMdnsDiscovery(input: UseMdnsDiscoveryInput) {
214214

215215
startScanRef.current = startScan
216216

217-
void import("react-native-zeroconf")
218-
.then((module) => {
219-
if (!active) return
220-
221-
const mod = module as ZeroconfModule
222-
const Zeroconf = mod.default
223-
if (typeof Zeroconf !== "function") {
224-
setDiscoveryAvailable(false)
225-
setDiscoveryStatus("error")
226-
setDiscoveryError("mDNS module unavailable")
227-
return
228-
}
229-
230-
zeroconf = new Zeroconf()
231-
androidImplType = Platform.OS === "android" ? (mod.ImplType?.DNSSD ?? "DNSSD") : undefined
232-
setDiscoveryAvailable(true)
217+
try {
218+
// Expo dev builds were failing to resolve this native module through async import().
219+
const mod = require("react-native-zeroconf") as ZeroconfModule
220+
const Zeroconf = mod.default
221+
if (typeof Zeroconf !== "function") {
222+
setDiscoveryAvailable(false)
223+
setDiscoveryStatus("error")
224+
setDiscoveryError("mDNS module unavailable")
225+
return
226+
}
233227

234-
zeroconf.on("resolved", rebuildServices)
235-
zeroconf.on("remove", rebuildServices)
236-
zeroconf.on("update", rebuildServices)
237-
zeroconf.on("error", (error) => {
238-
if (!active) return
239-
setDiscoveryStatus("error")
240-
setDiscoveryError(toErrorMessage(error))
241-
})
228+
zeroconf = new Zeroconf()
229+
androidImplType = Platform.OS === "android" ? (mod.ImplType?.DNSSD ?? "DNSSD") : undefined
230+
setDiscoveryAvailable(true)
242231

243-
startScan()
244-
})
245-
.catch((error) => {
232+
zeroconf.on("resolved", rebuildServices)
233+
zeroconf.on("remove", rebuildServices)
234+
zeroconf.on("update", rebuildServices)
235+
zeroconf.on("error", (error) => {
246236
if (!active) return
247-
setDiscoveryAvailable(false)
248237
setDiscoveryStatus("error")
249238
setDiscoveryError(toErrorMessage(error))
250239
})
251240

241+
startScan()
242+
} catch (error) {
243+
if (!active) return
244+
setDiscoveryAvailable(false)
245+
setDiscoveryStatus("error")
246+
setDiscoveryError(toErrorMessage(error))
247+
}
248+
252249
return () => {
253250
active = false
254251
startScanRef.current = null

0 commit comments

Comments
 (0)