Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b4b4fb9

Browse files
authored
Merge pull request #6553 from matrix-org/travis/voice-messages/worklet
Fix worklet reference for new webpack pipeline
2 parents 7b8a43b + 9b32a1c commit b4b4fb9

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@
193193
"decoderWorker\\.min\\.js": "<rootDir>/__mocks__/empty.js",
194194
"decoderWorker\\.min\\.wasm": "<rootDir>/__mocks__/empty.js",
195195
"waveWorker\\.min\\.js": "<rootDir>/__mocks__/empty.js",
196-
"workers/(.+)\\.worker\\.ts": "<rootDir>/__mocks__/workerMock.js"
196+
"workers/(.+)\\.worker\\.ts": "<rootDir>/__mocks__/workerMock.js",
197+
"RecorderWorklet": "<rootDir>/__mocks__/empty.js"
197198
},
198199
"transformIgnorePatterns": [
199200
"/node_modules/(?!matrix-js-sdk).+$"

src/audio/VoiceRecording.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { IEncryptedFile } from "matrix-js-sdk/src/@types/event";
3030
import { uploadFile } from "../ContentMessages";
3131
import { FixedRollingArray } from "../utils/FixedRollingArray";
3232
import { clamp } from "../utils/numbers";
33+
import mxRecorderWorkletPath from "./RecorderWorklet";
3334

3435
const CHANNELS = 1; // stereo isn't important
3536
export const SAMPLE_RATE = 48000; // 48khz is what WebRTC uses. 12khz is where we lose quality.
@@ -113,16 +114,10 @@ export class VoiceRecording extends EventEmitter implements IDestroyable {
113114
});
114115
this.recorderSource = this.recorderContext.createMediaStreamSource(this.recorderStream);
115116

116-
// Set up our worklet. We use this for timing information and waveform analysis: the
117-
// web audio API prefers this be done async to avoid holding the main thread with math.
118-
const mxRecorderWorkletPath = document.body.dataset.vectorRecorderWorkletScript;
119-
if (!mxRecorderWorkletPath) {
120-
// noinspection ExceptionCaughtLocallyJS
121-
throw new Error("Unable to create recorder: no worklet script registered");
122-
}
123-
124117
// Connect our inputs and outputs
125118
if (this.recorderContext.audioWorklet) {
119+
// Set up our worklet. We use this for timing information and waveform analysis: the
120+
// web audio API prefers this be done async to avoid holding the main thread with math.
126121
await this.recorderContext.audioWorklet.addModule(mxRecorderWorkletPath);
127122
this.recorderWorklet = new AudioWorkletNode(this.recorderContext, WORKLET_NAME);
128123
this.recorderSource.connect(this.recorderWorklet);

0 commit comments

Comments
 (0)