diff --git a/src/components/vive-tracker.js b/src/components/vive-tracker.js index 32be848e7df..34add319979 100644 --- a/src/components/vive-tracker.js +++ b/src/components/vive-tracker.js @@ -1,6 +1,6 @@ var registerComponent = require('../core/component').registerComponent; var bind = require('../utils/bind'); -var getGamepadsByPrefix = require('../utils/tracked-controls').getGamepadsByPrefix; +var checkControllerPresentAndSetup = require('../utils/tracked-controls').checkControllerPresentAndSetup; var emitIfAxesChanged = require('../utils/tracked-controls').emitIfAxesChanged; var VIVE_CONTROLLER_MODEL_OBJ_URL = 'https://cdn.aframe.io/controllers/vive/vr_controller_vive.obj'; @@ -59,7 +59,7 @@ module.exports.Component = registerComponent('vive-tracker', { this.lastControllerCheck = 0; this.previousButtonValues = {}; this.bindMethods(); - this.getGamepadsByPrefix = getGamepadsByPrefix; // to allow mock + this.checkControllerPresentAndSetup = checkControllerPresentAndSetup; // to allow mock this.emitIfAxesChanged = emitIfAxesChanged; // to allow mock }, @@ -87,21 +87,7 @@ module.exports.Component = registerComponent('vive-tracker', { checkIfControllerPresent: function () { var data = this.data; - var gamepads = this.el.sceneEl.systems['tracked-controls'].controllers; - var seenIndex = 0; - var controllerIndex = -1; - for (var i = 0; i < gamepads.length; i++) { - if (gamepads[i].id.indexOf(GAMEPAD_ID_PREFIX) < 0 || gamepads[i].hand) { continue; } - if (seenIndex === data.index) { controllerIndex = seenIndex; } - seenIndex++; - } - var isPresent = controllerIndex >= 0; - if (isPresent === this.controllerPresent) { return; } - this.controllerPresent = isPresent; - if (isPresent) { - this.injectTrackedControls(controllerIndex); - this.addEventListeners(); - } else { this.removeEventListeners(); } + this.checkControllerPresentAndSetup(this, GAMEPAD_ID_PREFIX, { hand: '', index: data.index }); }, play: function () {