Skip to content

Commit

Permalink
feat(relative-url): Add support for relative URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Meire committed Jan 27, 2019
1 parent 13c7dee commit 3935fbd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export const getMp3MediaRecorder = (config: RecorderConfig): Promise<typeof Medi
defineEventAttribute(Mp3MediaRecorder.prototype, 'error');

return new Promise((resolve, reject) => {
worker.postMessage(initMessage(config));
const wasmURL = new URL(config.wasmURL, window.location.origin).href;
worker.postMessage(initMessage(wasmURL));
worker.onmessage = ({ data }: { data: WorkerPostMessage }) => {
if (data.type === PostMessageType.WORKER_READY) {
resolve(Mp3MediaRecorder as any);
Expand Down
5 changes: 2 additions & 3 deletions src/types/post-message.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RecorderConfig } from './recorder-config.type';
import { WorkerConfig } from './worker-config.type';

export enum PostMessageType {
Expand All @@ -12,9 +11,9 @@ export enum PostMessageType {
WORKER_READY = 'WORKER_READY'
}

export const initMessage = (config: RecorderConfig) => ({
export const initMessage = (wasmURL: string) => ({
type: PostMessageType.INIT_WORKER as PostMessageType.INIT_WORKER,
config
wasmURL
});
export const errorMessage = (error: string) => ({ type: PostMessageType.ERROR as PostMessageType.ERROR, error });
export const startRecordingMessage = (config: WorkerConfig) => ({
Expand Down
6 changes: 3 additions & 3 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ export const mp3EncoderWorker = () => {
switch (message.type) {
case 'INIT_WORKER': {
const imports = getVmsgImports();
getWasmModule(message.config.wasmURL, imports)
getWasmModule(message.wasmURL, imports)
.then(wasm => {
vmsg = wasm.instance.exports;
ctx.postMessage({ type: 'WORKER_READY' });
})
.catch(error => {
ctx.postMessage({ type: 'ERROR', error });
.catch(err => {
ctx.postMessage({ type: 'ERROR', error: err.message });
});
break;
}
Expand Down

0 comments on commit 3935fbd

Please sign in to comment.