UNPKG

react-native-feedback-hub

Version:

React Native feedback SDK with Slack, Jira, Discord and Microsoft Teams integration

57 lines 1.9 kB
import { useState } from 'react'; import RecordScreen, { RecordingResult } from 'react-native-record-screen'; export function useScreenRecorder() { const [videoUri, setVideoUri] = useState(null); const [filePath, setFilePath] = useState(null); const start = async () => { try { const res = await RecordScreen.startRecording({ mic: false, fps: 24, bitrate: 512000 }); if (res === RecordingResult.PermissionError) { return null; } return res; } catch (error) { console.warn('Error starting recording:', error); return null; } }; const stop = async () => { var _a; try { const res = (await RecordScreen.stopRecording()); if (res && ((_a = res.result) === null || _a === void 0 ? void 0 : _a.outputURL)) { const path = `file://${res.result.outputURL}`; setVideoUri(path); setFilePath(res.result.outputURL); return path; } return null; } catch (error) { console.warn('Error stopping recording:', error); return null; } }; const cleanup = async () => { try { if (filePath) { await RecordScreen.clean(); const fs = require('react-native-fs'); const fileExists = await fs.exists(filePath); if (fileExists) { await fs.unlink(filePath); } } } catch (error) { console.warn('Error cleaning up recording:', error); } finally { setVideoUri(null); setFilePath(null); } }; return { start, stop, videoUri, setVideoUri, cleanup }; } //# sourceMappingURL=useScreenRecorder.js.map