Skill update round trip / roundtrip (false, macos-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, macos-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, symlink, latest) (push) Canceled after 0s
Skill update round trip / roundtrip (false, windows-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, windows-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, macos-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, macos-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, ubuntu-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, ubuntu-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, windows-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, windows-latest, symlink, 1.5.17) (push) Canceled after 0s
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { createPermissionHook } from 'expo-modules-core'
|
|
import { useEffect, useSyncExternalStore } from 'react'
|
|
import {
|
|
getMicrophonePermissionsAsync,
|
|
isRecording,
|
|
requestMicrophonePermissionsAsync
|
|
} from './core'
|
|
import { ExpoTwoWayAudioEventMap, addExpoTwoWayAudioEventListener } from './events'
|
|
|
|
export const useMicrophonePermissions = createPermissionHook({
|
|
getMethod: getMicrophonePermissionsAsync,
|
|
requestMethod: requestMicrophonePermissionsAsync
|
|
})
|
|
|
|
// Why: useSyncExternalStore resubscribes when these identities change; keep
|
|
// the native recording listener stable across component re-renders.
|
|
const subscribeToRecordingChanges = (cb: () => void) => {
|
|
const sub = addExpoTwoWayAudioEventListener('onRecordingChange', cb)
|
|
return () => sub.remove()
|
|
}
|
|
const getRecordingSnapshot = () => isRecording()
|
|
const getServerRecordingSnapshot = () => false
|
|
|
|
export function useIsRecording() {
|
|
return useSyncExternalStore(
|
|
subscribeToRecordingChanges,
|
|
getRecordingSnapshot,
|
|
getServerRecordingSnapshot
|
|
)
|
|
}
|
|
|
|
export function useExpoTwoWayAudioEventListener<K extends keyof ExpoTwoWayAudioEventMap>(
|
|
eventName: K,
|
|
listener: (ev: ExpoTwoWayAudioEventMap[K]) => void
|
|
) {
|
|
useEffect(() => {
|
|
const sub = addExpoTwoWayAudioEventListener(eventName, listener)
|
|
return () => sub.remove()
|
|
}, [eventName, listener])
|
|
}
|