quiet / quiet-js

Transmit data with sound using Web Audio -- Javascript binding for libquiet
BSD 3-Clause "New" or "Revised" License
2.19k stars 150 forks source link

Usage with React #39

Closed yaroslav-perec closed 3 years ago

yaroslav-perec commented 3 years ago

Hi!

Is there a way of using this library with React?

I try to integrate this library in my React project, and I have some issues with that, I've included all scripts in my index.html, and I try to initialize quiet-js like this:

useEffect(() => {
    // some code...

    window.Quiet.init({
      profilesPrefix: "/",
      memoryInitializerPrefix: "/",
      libfecPrefix: "/",
    });

    function onTransmitFinish() {
      textbox.focus();
      btn.addEventListener('click', onClick, false);
      btn.disabled = false;
      var originalText = btn.innerText;
      btn.innerText = btn.getAttribute('data-quiet-sending-text');
      btn.setAttribute('data-quiet-sending-text', originalText);
    }

    function onQuietReady() {
      var profilename = document.querySelector('[data-quiet-profile-name]').getAttribute('data-quiet-profile-name');

      transmit = window.Quiet.transmitter({ profile: profilename, onFinish: onTransmitFinish });

      btn.addEventListener('click', onClick, false);
    }

    window.Quiet.addReadyCallback(onQuietReady, onQuietFail);
  }, []);

And I get the next error:

Screenshot 2021-02-16 at 18 08 37

I tried to debug this and it seems that the error occurs on this line:

Screenshot 2021-02-16 at 18 16 18

Does anyone have any ideas on how to fix this issue or provide some minimal example of integration with React?

yaroslav-perec commented 3 years ago

Update: Initially I downloaded the library from the example page and I think there was an old version, then I downloaded the files directly from Github and now there are no errors.