Hello all, new guy here!
On v4.1.0, I’m using this code to attach a WebRTC coming from a remote stream:
// all of this code below requires user interaction (button) to activate
window.handleRemoteStreamAdded = ({stream}) => {
// need to attach the stream to an audio object otherwise it won't play!
var audio = new Audio();
audio.muted = true;
audio.srcObject = stream;
var remoteSound = new BABYLON.Sound("RemoteSound", stream, scene, null, { streaming: true, autoplay: true, spatialSound: true });
remoteSound.attachToMesh(box);
remoteSound.setDirectionalCone(90, 180, 0); // sets remoteSound variable only, not updating remoteSound._soundPanner directionalCone settings
remoteSound.setLocalDirectionToMesh(new BABYLON.Vector3(1, 0, 0));
remoteSound.play(); // need this here otherwise remoteSound._soundPanner directionalCone settings won't be updated!
};
As you can see from the comment above, I found out that while using a remote MediaStream coming through via WebRTC:
- the hack some people proposed few months ago (there is a post in the forum and a GitHub merge) didn’t worked for me
- setDirectionalCone only updates the directional cone variables of the remoteSound object, but not the ones in the attached soundPanner
In order to get the soundPanner updated, remoteSound needs to get called with play, because Sound.play() forces the update of soundPanner.
Otherwise sound will come from the connected mesh as omnidirectional.
I tried what’s on master but got the same results.
Although, I didn’t understood how is it possible that in this playground https://www.babylonjs-playground.com/#1BO0YS, using static asset, it works.