Javascript mic-recorder-to-mp3 only working on recompile

Viewed 54

I have a simple HTML web element with an embedded audio recorder. I'd like the recorder to start recording automatically upon being loaded. I'm experiencing some very weird behavior, where recording works when I recompile the app and not otherwise. If I refresh the page on an already compiled version of the app, I get an empty recording buffer.

Here are the key parts of my code:

const MicRecorder = require("mic-recorder-to-mp3");
...

class Microphone extends HTMLElement {
  constructor() {
    super();
    // Add a shadow DOM
    const shadowDOM = this.attachShadow({ mode: "open" });
    this.shadowDOM = shadowDOM;

    // Render
    this.shadowDOM.appendChild(template.content.cloneNode(true));

    ...

    // Bind methods
    this.toggleRecord = this.toggleRecord.bind(this);
  }

  connectedCallback() {
    if (this.startRecording) {
      this.toggleRecord();
    }
  }

toggleRecord() {
    const recordButton = this.shadowRoot.querySelector("#record-button");

    if (this.isRecording()) {
      this.recorder
        .stop()
        .getMp3()
        .then(([buffer, blob]) => {...})
    } else {
      this.recorder
        .start()
        .then(() => {...})
    }
  }
  
0 Answers
Related