feat: add expo-two-way-audio module to workspace

This commit is contained in:
Mohamed Boudra
2026-03-14 16:46:35 +07:00
parent fc7369384b
commit cad4110e24
74 changed files with 48803 additions and 354 deletions
+34
View File
@@ -0,0 +1,34 @@
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,
});
export function useIsRecording() {
const subscribe = (cb: () => void) => {
const sub = addExpoTwoWayAudioEventListener("onRecordingChange", cb);
return () => sub.remove();
};
const getSnapshot = () => isRecording();
const getServerSnapshot = () => false;
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
}
export function useExpoTwoWayAudioEventListener<K extends keyof ExpoTwoWayAudioEventMap>(
eventName: K,
listener: (ev: ExpoTwoWayAudioEventMap[K]) => void,
) {
useEffect(() => {
const sub = addExpoTwoWayAudioEventListener(eventName, listener);
return () => sub.remove();
}, [listener]);
}