Skip to content

Commit

Permalink
Makes audio positional by using THREE.PositionalAudio
Browse files Browse the repository at this point in the history
There's a Chrome bug that it takes into account. Also saves uPort data to send push notifications without scanning qr code when revising a logged in site
  • Loading branch information
AlbertoElias committed Aug 15, 2018
1 parent 116d787 commit 04b798b
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 105 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ before_install:
- npm i -g npm
install:
- npm install
before_script:
- npm install -g gulp-cli
script: gulp
script:
- npm run lint
- npm run test
cache:
directories:
- "node_modules"
73 changes: 55 additions & 18 deletions build/simbol.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -132065,7 +132065,7 @@ class Identity extends eventemitter3 {

this.uPort = new uport.Connect('Simbol', {
clientId: '2on1AwSMW48Asek7N5fT9aGf3voWqMkEAXJ',
network: 'rinkeby',
network: 'rinkeby', // change to main net
signer: uport.SimpleSigner('12856cfa7d87eca683cbccf3617c82c615b8cac4347db20b1874884c2bc6453d') // eslint-disable-line new-cap
});

Expand Down Expand Up @@ -132179,7 +132179,13 @@ class Identity extends eventemitter3 {
* @returns {undefined}
*/
setUPortData(credentials, save) {
this.uPortData = credentials;
this.uPortData = {
publicEncKey: credentials.publicEncKey,
pushToken: credentials.pushToken,
SimbolConfig: credentials.SimbolConfig
};
this.uPort.pushToken = credentials.pushToken;
this.uPort.publicEncKey = credentials.publicEncKey;
if (credentials.SimbolConfig) {
const config = JSON.parse(credentials.SimbolConfig);
this.avatarPath = config.avatar3D ||
Expand Down Expand Up @@ -138987,6 +138993,7 @@ class MultiVP extends eventemitter3 {

this.config = Object.assign({}, defaultConfig, config);
this.vp = vp;
this.audioListener = new AudioListener();

this.getStream()
.then((stream) => {
Expand Down Expand Up @@ -139050,11 +139057,26 @@ class MultiVP extends eventemitter3 {
*
* @returns {undefined}
*/
animate() {
animate(time) {
for (const peerId of Object.keys(this.meshes)) {
const peerMesh = this.meshes[peerId];
peerMesh.mesh.position.set(...peerMesh.position);
peerMesh.mesh.rotation.y = peerMesh.rotation;
if (peerId === 2) {
peerMesh.lookAt(this.vp.mesh);
peerMesh.position.set(
Math.cos(time * 0.0001) * 4,
0,
Math.sin(time * 0.0001) * 4
);
}
// for (let i = 0; i < 3; i++) {
// if (typeof peerMesh.position[i] !== 'number') {
// peerMesh.position[i] = 0;
// }
// }
// peerMesh.mesh.position.set(...peerMesh.position);
// if (typeof peerMesh.rotation === 'number') {
// peerMesh.mesh.rotation.y = peerMesh.rotation;
// }
}
}

Expand Down Expand Up @@ -139164,11 +139186,14 @@ class MultiVP extends eventemitter3 {
* @returns {undefined}
*/
_peerStream(stream) {
this.audioEl = document.createElement('audio');
this.audioEl.autoplay = true;
this.audioEl.srcObject = stream;
document.body.appendChild(this.audioEl);
this.audioEl.play();
this.audioHelper = new PositionalAudio(this.multiVP.audioListener);
const sourceNode = this.audioHelper.context.createMediaStreamSource(stream);
this.audioHelper.setNodeSource(sourceNode);

// Workaround for Chrome to output audio
let audioObj = document.createElement('audio');
audioObj.srcObject = stream;
audioObj = null;
}

/**
Expand Down Expand Up @@ -139239,6 +139264,8 @@ class MultiVP extends eventemitter3 {
if (data.type === 'connected') {
this.multiVP._loadAvatar(data.avatar, this.id)
.then((mesh) => {
// Adds the positional audio object to position it with the mesh
mesh.add(this.audioHelper);
/**
* MultiVP add event that provides a mesh to be added to the scene
*
Expand Down Expand Up @@ -139274,15 +139301,15 @@ class MultiVP extends eventemitter3 {
_peerClose() {
console.log(`peer ${this.id} closing`);
delete this.multiVP.remotePeers[this.id];
document.body.removeChild(this.audioEl);
if (this.multiVP.meshes[this.id]) {
const mesh = this.multiVP.meshes[this.id].mesh;/**
* MultiVP remove event that provides a mesh to be removed
* from the scene
*
* @event MultiVP#remove
* @type {object}
* @property mesh - Mesh to be removed from the scene
const mesh = this.multiVP.meshes[this.id].mesh;
/**
* MultiVP remove event that provides a mesh to be removed
* from the scene
*
* @event MultiVP#remove
* @type {object}
* @property mesh - Mesh to be removed from the scene
*/
this.multiVP.emit('remove', {mesh});
delete this.multiVP.meshes[this.id];
Expand Down Expand Up @@ -142800,10 +142827,20 @@ class Simbol extends eventemitter3 {
this.vpMesh = this.virtualPersona.mesh;
this.controllers.init(this.vpMesh);

// Adds the UI from other components into the scene
this.addToScene([...this.interactions.getMeshes()]);
if (this.locomotion) {
this.addToScene([...this.locomotion.getMeshes()]);
}

// Prepares multiVP for positional audio from other peers
if (this.virtualPersona.multiVP) {
this._scene.camera.add(this.virtualPersona.multiVP.audioListener);
document.body.addEventListener('click', () => {
this.virtualPersona.multiVP.audioListener.context.resume();
});
}

this.addAnimateFunctions([this.animate.bind(this)]);

return Promise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion build/simbol.cjs.js.map

Large diffs are not rendered by default.

73 changes: 55 additions & 18 deletions build/simbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -132061,7 +132061,7 @@ class Identity extends eventemitter3 {

this.uPort = new uport.Connect('Simbol', {
clientId: '2on1AwSMW48Asek7N5fT9aGf3voWqMkEAXJ',
network: 'rinkeby',
network: 'rinkeby', // change to main net
signer: uport.SimpleSigner('12856cfa7d87eca683cbccf3617c82c615b8cac4347db20b1874884c2bc6453d') // eslint-disable-line new-cap
});

Expand Down Expand Up @@ -132175,7 +132175,13 @@ class Identity extends eventemitter3 {
* @returns {undefined}
*/
setUPortData(credentials, save) {
this.uPortData = credentials;
this.uPortData = {
publicEncKey: credentials.publicEncKey,
pushToken: credentials.pushToken,
SimbolConfig: credentials.SimbolConfig
};
this.uPort.pushToken = credentials.pushToken;
this.uPort.publicEncKey = credentials.publicEncKey;
if (credentials.SimbolConfig) {
const config = JSON.parse(credentials.SimbolConfig);
this.avatarPath = config.avatar3D ||
Expand Down Expand Up @@ -138983,6 +138989,7 @@ class MultiVP extends eventemitter3 {

this.config = Object.assign({}, defaultConfig, config);
this.vp = vp;
this.audioListener = new AudioListener();

this.getStream()
.then((stream) => {
Expand Down Expand Up @@ -139046,11 +139053,26 @@ class MultiVP extends eventemitter3 {
*
* @returns {undefined}
*/
animate() {
animate(time) {
for (const peerId of Object.keys(this.meshes)) {
const peerMesh = this.meshes[peerId];
peerMesh.mesh.position.set(...peerMesh.position);
peerMesh.mesh.rotation.y = peerMesh.rotation;
if (peerId === 2) {
peerMesh.lookAt(this.vp.mesh);
peerMesh.position.set(
Math.cos(time * 0.0001) * 4,
0,
Math.sin(time * 0.0001) * 4
);
}
// for (let i = 0; i < 3; i++) {
// if (typeof peerMesh.position[i] !== 'number') {
// peerMesh.position[i] = 0;
// }
// }
// peerMesh.mesh.position.set(...peerMesh.position);
// if (typeof peerMesh.rotation === 'number') {
// peerMesh.mesh.rotation.y = peerMesh.rotation;
// }
}
}

Expand Down Expand Up @@ -139160,11 +139182,14 @@ class MultiVP extends eventemitter3 {
* @returns {undefined}
*/
_peerStream(stream) {
this.audioEl = document.createElement('audio');
this.audioEl.autoplay = true;
this.audioEl.srcObject = stream;
document.body.appendChild(this.audioEl);
this.audioEl.play();
this.audioHelper = new PositionalAudio(this.multiVP.audioListener);
const sourceNode = this.audioHelper.context.createMediaStreamSource(stream);
this.audioHelper.setNodeSource(sourceNode);

// Workaround for Chrome to output audio
let audioObj = document.createElement('audio');
audioObj.srcObject = stream;
audioObj = null;
}

/**
Expand Down Expand Up @@ -139235,6 +139260,8 @@ class MultiVP extends eventemitter3 {
if (data.type === 'connected') {
this.multiVP._loadAvatar(data.avatar, this.id)
.then((mesh) => {
// Adds the positional audio object to position it with the mesh
mesh.add(this.audioHelper);
/**
* MultiVP add event that provides a mesh to be added to the scene
*
Expand Down Expand Up @@ -139270,15 +139297,15 @@ class MultiVP extends eventemitter3 {
_peerClose() {
console.log(`peer ${this.id} closing`);
delete this.multiVP.remotePeers[this.id];
document.body.removeChild(this.audioEl);
if (this.multiVP.meshes[this.id]) {
const mesh = this.multiVP.meshes[this.id].mesh;/**
* MultiVP remove event that provides a mesh to be removed
* from the scene
*
* @event MultiVP#remove
* @type {object}
* @property mesh - Mesh to be removed from the scene
const mesh = this.multiVP.meshes[this.id].mesh;
/**
* MultiVP remove event that provides a mesh to be removed
* from the scene
*
* @event MultiVP#remove
* @type {object}
* @property mesh - Mesh to be removed from the scene
*/
this.multiVP.emit('remove', {mesh});
delete this.multiVP.meshes[this.id];
Expand Down Expand Up @@ -142796,10 +142823,20 @@ class Simbol extends eventemitter3 {
this.vpMesh = this.virtualPersona.mesh;
this.controllers.init(this.vpMesh);

// Adds the UI from other components into the scene
this.addToScene([...this.interactions.getMeshes()]);
if (this.locomotion) {
this.addToScene([...this.locomotion.getMeshes()]);
}

// Prepares multiVP for positional audio from other peers
if (this.virtualPersona.multiVP) {
this._scene.camera.add(this.virtualPersona.multiVP.audioListener);
document.body.addEventListener('click', () => {
this.virtualPersona.multiVP.audioListener.context.resume();
});
}

this.addAnimateFunctions([this.animate.bind(this)]);

return Promise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion build/simbol.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 04b798b

Please sign in to comment.