Skip to content

Commit

Permalink
Merge pull request #26 from braden-w:feature/sid-322-feat-attempt-lig…
Browse files Browse the repository at this point in the history
…hter-weight-recording-mechanism

feat: lighter recording mechanism (use polyfill, not RecordRTC)
  • Loading branch information
braden-w authored May 30, 2023
2 parents 80aa596 + 5698452 commit edd507b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 90 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"@sveltejs/adapter-cloudflare": "^2.2.0",
"@tauri-apps/api": "^1.2.0",
"audio-recorder-polyfill": "^0.4.1",
"recordrtc": "^5.6.2",
"svelte-french-toast": "1.0.4-beta.0"
}
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions src/lib/recorder/mediaRecorder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/**
* This implementation uses the native mediaRecorder api.
* Unfortunately, it didn't reliably work with Safari or Tauri.
*
* For the main implementation, see {@link ./recordRtcRecorder.ts}.
*/
import AudioRecorder from 'audio-recorder-polyfill';

let mediaRecorder: MediaRecorder | null = null;
let recordedChunks: Blob[] = [];

export async function startRecording(): Promise<void> {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder = new AudioRecorder(stream);
if (!mediaRecorder) throw new Error('MediaRecorder is not initialized.');
mediaRecorder.addEventListener('dataavailable', (event: BlobEvent) => {
recordedChunks.push(event.data);
});
Expand Down
79 changes: 0 additions & 79 deletions src/lib/recorder/recordRtcRecorder.ts

This file was deleted.

5 changes: 1 addition & 4 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { startRecording, stopRecording } from '$lib/recorder/mediaRecorder';
import { apiKey } from '$lib/stores/apiKey';
import { writeText } from '$lib/system-apis/clipboard';
import { registerShortcut, unregisterAllShortcuts } from '$lib/system-apis/shorcuts';
Expand All @@ -22,10 +23,6 @@
return;
}
const { startRecording, stopRecording } = /Chrome/.test(navigator.userAgent)
? await import('$lib/recorder/mediaRecorder')
: await import('$lib/recorder/recordRtcRecorder');
if (!isRecording) {
await setAlwaysOnTop(true);
await startRecording();
Expand Down

0 comments on commit edd507b

Please sign in to comment.