Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module loading #24

Open
lonce opened this issue Feb 2, 2019 · 7 comments
Open

module loading #24

lonce opened this issue Feb 2, 2019 · 7 comments

Comments

@lonce
Copy link

lonce commented Feb 2, 2019

Feature request:
I would like to import resonance-audio in an ecma6 module so that I don't have to force users to import with a script tag in their html file.

Thanks for a great library,
- lonce

@lonce
Copy link
Author

lonce commented Feb 6, 2019

I've updated the resonance-audio source to ea6 style module loading, and the build looks good. However, I am still struggling to get Omnitone (required in Listener.js) to load properly from the build.

@drewbitllama
Copy link
Contributor

drewbitllama commented Feb 6, 2019 via email

@lonce
Copy link
Author

lonce commented Feb 6, 2019

Hi Drew,

I do believe I've got it working now, but had to make a couple of minor changes in the code to do so.

First, of course, i made the changes necessary for es6 module loading in all the resonance-audio-web-sdk/src files, such as:
// const Utils = require('./utils.js');
import Utils from './utils.js'

I then turned to importing Omnitone in the one necessary place, listener.js :
// Omnitone = require('../node_modules/omnitone/build/omnitone.js');
import Omnitone from '../node_modules/omnitone/build/omnitone.esm.js'

However, the reference (later in listener.js) to
Omnitone.Omnitone.createFOARenderer(context, {});
was creating a problem. Since I couldn't figure out how to construct an import statement that would create this nested structure and work as expected, I just changed the nested reference (in the two places it occurs) to:
Omnitone.createFOARenderer(context, {})
That solved the issue!

One remaining bug popped up. The reference in utils.js to
exports.EPSILON_FLOAT
bombed since 'exports' is no longer defined. Changing it to what it probably should have been in the first place:
Utils.EPSILON_FLOAT
solved that issue.

Now I am getting a build of resonance-audio.js that seems to be working fine with ES6 importing!

Thanks again for this cool library,
- lonce

@drewbitllama
Copy link
Contributor

drewbitllama commented Feb 6, 2019 via email

@hoch
Copy link
Collaborator

hoch commented Feb 6, 2019

FWIW, Omnitone recently updated (v1.3) and now it supports ES6 module. Perhaps we should use that in Resonance as well?

@iooops
Copy link

iooops commented Mar 15, 2019

Same issue here.

Even though I built from the original source code, it caused problem.

The following is the output from running npm run test:

  Listener
    ✖ "before each" hook for "Verify module constructor."
      Chrome 72.0.3626 (Mac OS X 10.14.3)
    TypeError: Cannot read property 'createFOARenderer' of undefined
        at new Listener (build/resonance-audio.js:933:40)
        at Context.<anonymous> (test/test-listener.js:33:16)

  ResonanceAudio
    ✖ "before each" hook for "Verify module constructor."
      Chrome 72.0.3626 (Mac OS X 10.14.3)
    TypeError: Cannot read property 'createFOARenderer' of undefined
        at new Listener (build/resonance-audio.js:933:40)
        at new ResonanceAudio (build/resonance-audio.js:3859:20)
        at Context.<anonymous> (test/test-resonance-audio.js:33:13)

  Source
    ✖ "before each" hook for "Ensure module produces output."
      Chrome 72.0.3626 (Mac OS X 10.14.3)
    TypeError: Cannot read property 'createFOARenderer' of undefined
        at new Listener (build/resonance-audio.js:933:40)
        at new ResonanceAudio (build/resonance-audio.js:3859:20)
        at Context.<anonymous> (test/test-source.js:36:13)

`const Omnitone = require('../node_modules/omnitone/build/omnitone.js');`
  if (this._ambisonicOrder == 1) {
    this._renderer = Omnitone.Omnitone.createFOARenderer(context, {});
  } else if (this._ambisonicOrder > 1) {
    this._renderer = Omnitone.Omnitone.createHOARenderer(context, {
      ambisonicOrder: this._ambisonicOrder,
    });
  }

I think these are the lines of code that caused the problem.

I tried replacing it with newer version of omnitone, but still it cannot pass the test.

@shariq-audiofocus
Copy link

@iooops / anyone else running into this issue - You can fix it minimally by making these two changes:

  1. In src/listener.js. Replace
    Omnitone.Omnitone.createFOARenderer with Omnitone.createFOARenderer
    Omnitone.Omnitone.createHOARenderer with Omnitone.createHOARenderer

  2. In 'node_modules/omnitone/build/omnitone.js'. Add:
    module.exports = Omnitone; to very bottom part of the file.

then npm test should run successfully

Code6226 added a commit to Code6226/resonance-audio-web-sdk that referenced this issue Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants