Skip to content

Commit

Permalink
fix: add init'd flag for init->ready listener pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-liang committed Jun 7, 2023
1 parent 49cfc1b commit e9da1a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/components/arena-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ AFRAME.registerComponent('arena-camera', {
* @ignore
*/
init: function() {
this.initialized = false;
ARENA.events.addEventListener(ARENA_EVENTS.ARENA_LOADED, this.ready.bind(this));
},

ready: function() {
this.initialized = true;
const data = this.data;
const el = this.el;

Expand Down Expand Up @@ -209,6 +211,7 @@ AFRAME.registerComponent('arena-camera', {
* @ignore
*/
tick: function(t, dt) {
if (!this.initialized) return;
const data = this.data;
const el = this.el;

Expand Down
12 changes: 7 additions & 5 deletions src/components/arena-hand.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,23 @@ AFRAME.registerComponent('arena-hand', {
dependencies: ['laser-controls'],

init: function() {
this.rotation = new THREE.Quaternion();
this.position = new THREE.Vector3();
this.lastPose = '';
this.initialized = false;

ARENA.events.addEventListener(ARENA_EVENTS.ARENA_LOADED, this.ready.bind(this));
},

ready: function() {
this.initialized = true;
const data = this.data;
const el = this.el;

const sceneEl = el.sceneEl;

this.rotation = new THREE.Quaternion();
this.position = new THREE.Vector3();

this.arena = sceneEl.systems['arena-scene'];

this.lastPose = '';

// capitalize hand type
data.hand = data.hand.charAt(0).toUpperCase() + data.hand.slice(1);

Expand Down Expand Up @@ -198,6 +199,7 @@ AFRAME.registerComponent('arena-hand', {
},

tick: function(t, dt) {
if (!this.initialized) return;
if (!this.name) {
this.name = this.data.hand === 'Left' ? this.arena.handLName : this.arena.handRName;
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/arena-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ AFRAME.registerComponent('arena-user', {
},

init: function() {
this.initialized = false;
ARENA.events.addEventListener(ARENA_EVENTS.JITSI_LOADED, this.ready.bind(this));
},
ready: function() {
this.initialized = true;
const data = this.data;
const el = this.el;

Expand Down Expand Up @@ -458,6 +460,7 @@ AFRAME.registerComponent('arena-user', {
},

tick: function() {
if (!this.initialized) return;
const data = this.data;

// do periodic a/v updates
Expand Down
4 changes: 3 additions & 1 deletion src/components/network-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ AFRAME.registerComponent('network-latency', {
},

init: function() {
if (!this.data.enabled) return;
this.initialized = false;
ARENA.events.addEventListener(ARENA_EVENTS.MQTT_LOADED, this.ready.bind(this));
},
ready: function() {
this.initialized = true;
const data = this.data;
const el = this.el;

Expand All @@ -50,6 +51,7 @@ AFRAME.registerComponent('network-latency', {
},

tick: function() {
if (!this.initialized || !this.enabled) return;
const data = this.data;
const el = this.el;

Expand Down

0 comments on commit e9da1a1

Please sign in to comment.