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

switch from non positional to positional in networked-audio-source #245

Closed
vincentfretin opened this issue Feb 27, 2021 · 4 comments · Fixed by #330
Closed

switch from non positional to positional in networked-audio-source #245

vincentfretin opened this issue Feb 27, 2021 · 4 comments · Fixed by #330

Comments

@vincentfretin
Copy link
Member

If I use for example in my template networked-audio-source="positional:false" and later want to switch to positional audio with
setAttribute('networked-audio-source', 'positional:true;rolloffFactor:2.0;distanceModel:exponential') I get an error.
I did get around it with this code in my app but this is quite ugly, this needs to be properly handled by the networked-audio-source update function.

    // change to positional audio
    const players = document.querySelectorAll('[player-info]');
    for (let i = 0; i < players.length; i++) {
      if (players[i].id !== 'cameraRig') {
        const nas = players[i].querySelector('.camera').components['networked-audio-source'];
        const stream = nas.stream;
        nas.remove();
        nas.sound = null;
        nas.stream = null;
        players[i].querySelector('.camera').setAttribute('networked-audio-source', 'positional:true;rolloffFactor:2.0;distanceModel:exponential');
        nas._setMediaStream(stream);
      }
    }

This should really be:

    // change to positional audio
    const players = document.querySelectorAll('[player-info]');
    for (let i = 0; i < players.length; i++) {
      if (players[i].id !== 'cameraRig') {
        players[i].querySelector('.camera').setAttribute('networked-audio-source', 'positional:true;rolloffFactor:2.0;distanceModel:exponential');
      }
    }
@vincentfretin
Copy link
Member Author

Hubs has their version of networked-audio-source that is called avatar-audio-source and properly handle positional attribute update by recreating the audio. We need a similar fix. https://github.com/mozilla/hubs/blob/00cc63e58079bebd63f3115b49038da60180d59b/src/components/avatar-audio-source.js

@vincentfretin
Copy link
Member Author

This is a good first issue if anyone want to fix it and write an example (maybe update the basic-audio.html example) to switch between non positional and positional.

@kylebakerio
Copy link
Member

Do you know if the hubs example actually works properly when non-positional? I had a client pay me to update their hubs fork to have a 'positional audio off' mode on short notice. I wasn't familiar with hubs, and they had already had their developers make an attempt at it that was incomplete, so I wasn't sure what was originally in the hubs code vs. what they had added.

If this feature already exists in the hubs code and works, though, it's strange that they paid me to implement a version of it. I'll have to look into that more.

In any case, I'm pretty comfortable with this task one way or the other and can look into it.

@vincentfretin
Copy link
Member Author

I know that in Hubs you can type "/audiomode" command in the chat bar to disable positional audio or enabled it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants