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

0.5.2 Release #103

Merged
merged 14 commits into from
Mar 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ List of events:
| entityCreated | Fired when a networked entity is created | `evt.detail.el` - new entity |
| entityDeleted | Fired when a networked entity is deleted | `evt.detail.networkId` - networkId of deleted entity |

The following events are fired on the `networked` component. See the [toggle-ownership component](./server/static/js/toggle-ownership.component.js) for examples.

List of ownership transfer events:

| Event | Description | Values |
| -------- | ----------- | ------------- |
| ownership-gained | Fired when a networked entity's ownership is taken | `evt.detail.el` - the entity whose ownership was gained |
| | | `evt.detail.oldOwner` - the clientId of the previous owner |
| ownership-lost | Fired when a networked entity's ownership is lost | `evt.detail.el` - the entity whose ownership was lost |
| | | `evt.detail.newOwner` - the clientId of the new owner |
| ownership-changed | Fired when a networked entity's ownership is changed | `evt.detail.el` - the entity whose ownership was lost |
| | | `evt.detail.oldOwner` - the clientId of the previous owner |
| | | `evt.detail.newOwner` - the clientId of the new owner |

### Adapters

Expand Down
22 changes: 21 additions & 1 deletion dist/networked-aframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3829,7 +3829,14 @@
// @TODO if aframevr/aframe#3042 gets merged, this should just delegate to the aframe sound component
AFRAME.registerComponent('networked-audio-source', {
schema: {
positional: { default: true }
positional: { default: true },
distanceModel: {
default: "inverse",
oneOf: ["linear", "inverse", "exponential"]
},
maxDistance: { default: 10000 },
refDistance: { default: 1 },
rolloffFactor: { default: 1 }
},

init: function init() {
Expand All @@ -3851,6 +3858,9 @@
}
},

update: function update() {
this._setPannerProperties();
},
_setMediaStream: function _setMediaStream(newStream) {
if (!this.sound) {
this.setupSound();
Expand All @@ -3866,12 +3876,21 @@
this.audioEl.setAttribute("autoplay", "autoplay");
this.audioEl.setAttribute("playsinline", "playsinline");
this.audioEl.srcObject = newStream;
this.audioEl.volume = 0; // we don't actually want to hear audio from this element

this.sound.setNodeSource(this.sound.context.createMediaStreamSource(newStream));
}
this.stream = newStream;
}
},
_setPannerProperties: function _setPannerProperties() {
if (this.sound && this.data.positional) {
this.sound.setDistanceModel(this.data.distanceModel);
this.sound.setMaxDistance(this.data.maxDistance);
this.sound.setRefDistance(this.data.refDistance);
this.sound.setRolloffFactor(this.data.rolloffFactor);
}
},


remove: function remove() {
Expand Down Expand Up @@ -3902,6 +3921,7 @@

this.sound = this.data.positional ? new THREE.PositionalAudio(this.listener) : new THREE.Audio(this.listener);
el.setObject3D(this.attrName, this.sound);
this._setPannerProperties();
}
});

Expand Down
6 changes: 3 additions & 3 deletions dist/networked-aframe.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "networked-aframe",
"version": "0.5.1",
"version": "0.5.2",
"description": "A web framework for building multi-user virtual reality experiences.",
"homepage": "",
"main": "dist/networked-aframe.js",
Expand Down
30 changes: 30 additions & 0 deletions server/static/js/toggle-ownership.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,37 @@ AFRAME.registerComponent('toggle-ownership', {

if (NAF.utils.isMine(this.el)) {
this.updateColor();
} else {
this.el.setAttribute('material', 'opacity', 0.5);
}

// Opacity is not a networked attribute, but change it based on ownership events
this.networkedEl = NAF.utils.getNetworkedEntity(this.el);

let timeout;

this.networkedEl.addEventListener("ownership-gained", e => {
e.detail.el.setAttribute('material', 'opacity', 1);
});

this.networkedEl.addEventListener("ownership-lost", e => {
e.detail.el.setAttribute('material', 'opacity', 0.5);
});

this.networkedEl.addEventListener("ownership-changed", e => {
clearTimeout(timeout);
console.log(e.detail)
if (e.detail.newOwner == NAF.clientId) {
//same as listening to "ownership-gained"
} else if (e.detail.oldOwner == NAF.clientId) {
//same as listening to "ownership-lost"
} else {
e.detail.el.setAttribute('material', 'opacity', 0.8);
timeout = setTimeout(() => {
e.detail.el.setAttribute('material', 'opacity', 0.5);
}, 200)
}
});
},

onKeyUp(e) {
Expand Down
2 changes: 1 addition & 1 deletion src/NafIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ naf.options = options;
naf.utils = utils;
naf.log = new NafLogger();
naf.schemas = new Schemas();
naf.version = "0.5.0";
naf.version = "0.5.2";

naf.adapters = new AdapterFactory();
var entities = new NetworkEntities();
Expand Down
25 changes: 23 additions & 2 deletions src/components/networked-audio-source.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
var naf = require('../NafIndex');

// @TODO if aframevr/aframe#3042 gets merged, this should just delegate to the aframe sound component
AFRAME.registerComponent('networked-audio-source', {
schema: {
positional: { default: true }
positional: { default: true },
distanceModel: {
default: "inverse",
oneOf: ["linear", "inverse", "exponential"]
},
maxDistance: { default: 10000 },
refDistance: { default: 1 },
rolloffFactor: { default: 1 }
},

init: function () {
Expand All @@ -25,6 +31,10 @@ AFRAME.registerComponent('networked-audio-source', {
}
},

update() {
this._setPannerProperties();
},

_setMediaStream(newStream) {
if(!this.sound) {
this.setupSound();
Expand All @@ -40,13 +50,23 @@ AFRAME.registerComponent('networked-audio-source', {
this.audioEl.setAttribute("autoplay", "autoplay");
this.audioEl.setAttribute("playsinline", "playsinline");
this.audioEl.srcObject = newStream;
this.audioEl.volume = 0; // we don't actually want to hear audio from this element

this.sound.setNodeSource(this.sound.context.createMediaStreamSource(newStream));
}
this.stream = newStream;
}
},

_setPannerProperties() {
if (this.sound && this.data.positional) {
this.sound.setDistanceModel(this.data.distanceModel);
this.sound.setMaxDistance(this.data.maxDistance);
this.sound.setRefDistance(this.data.refDistance);
this.sound.setRolloffFactor(this.data.rolloffFactor);
}
},

remove: function() {
if (!this.sound) return;

Expand Down Expand Up @@ -77,5 +97,6 @@ AFRAME.registerComponent('networked-audio-source', {
? new THREE.PositionalAudio(this.listener)
: new THREE.Audio(this.listener);
el.setObject3D(this.attrName, this.sound);
this._setPannerProperties();
}
});
16 changes: 15 additions & 1 deletion src/components/networked.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ AFRAME.registerComponent('networked', {
},

init: function() {
this.OWNERSHIP_GAINED = 'ownership-gained';
this.OWNERSHIP_CHANGED = 'ownership-changed';
this.OWNERSHIP_LOST = 'ownership-lost';

var wasCreatedByNetwork = this.wasCreatedByNetwork();

this.onConnected = bind(this.onConnected, this);
Expand Down Expand Up @@ -59,6 +63,8 @@ AFRAME.registerComponent('networked', {
this.removeLerp();
this.el.setAttribute('networked', { owner: NAF.clientId });
this.syncAll();
this.el.emit(this.OWNERSHIP_GAINED, { el: this.el, oldOwner: owner });
this.el.emit(this.OWNERSHIP_CHANGED, { el: this.el, oldOwner: owner, newOwner: NAF.clientId});
return true;
}
return false;
Expand Down Expand Up @@ -286,11 +292,19 @@ AFRAME.registerComponent('networked', {
}

if (this.data.owner !== entityData.owner) {
var wasMine = this.isMine();
this.lastOwnerTime = entityData.lastOwnerTime;
this.attachLerp();

const oldOwner = this.data.owner;
const newOwner = entityData.owner;
if (wasMine) {
this.el.emit(this.OWNERSHIP_LOST, { el: this.el, newOwner: newOwner });
}
this.el.emit(this.OWNERSHIP_CHANGED, { el: this.el, oldOwner: oldOwner, newOwner: newOwner});

this.el.setAttribute('networked', { owner: entityData.owner });
}

this.updateComponents(entityData.components);
},

Expand Down