diff --git a/src/client/events/utils.js b/src/client/events/utils.js index 9e1da037..ce7b562a 100644 --- a/src/client/events/utils.js +++ b/src/client/events/utils.js @@ -45,10 +45,14 @@ module.exports = { // iOS-specific event properties ev.touchType = e.touchType // iOS-pollable event properties - for (var p of ['altitudeAngle', 'azimuthAngle', 'force']) { - Object.defineProperty(ev, 'get_' + p, { - enumerable: true, - value: ()=>e[p] + for (let p of ['altitudeAngle', 'azimuthAngle', 'force']) { + Object.defineProperty(ev, 'update_' + p, { + enumerable: false, + value: function(){ + var changed = this[p] !== e[p] + if (changed) this[p] = e[p] + return changed + } }) } } diff --git a/src/client/widgets/pads/canvas.js b/src/client/widgets/pads/canvas.js index 1a737fc7..e5a3ba76 100644 --- a/src/client/widgets/pads/canvas.js +++ b/src/client/widgets/pads/canvas.js @@ -130,34 +130,33 @@ class CanvasWidget extends Canvas { this.on('draginit',(e)=>{ touchCb(e, 'start') - if (iOS && this.iosTouch) { + if (this.iosTouch) { // cache touch inforamtions this.iosTouchCache[e.pointerId] = e // start polling extra touch inforamtions this.iosTouchPolls[e.pointerId] = setInterval(()=>{ if (!this.iosTouchCache[e.pointerId]) return - var update = false + var changed = false for (var p of iosEvents) { - var newval = e['get_' + p]() - // if polled value has changed, retrig last move event - if (newval !== this.iosTouchCache[e.pointerId][p]) { - // reset movement data since this is only relevant when - // the pointer doesn't move - this.iosTouchCache[e.pointerId].movementX = 0 - this.iosTouchCache[e.pointerId].movementY = 0 - // polled data - this.iosTouchCache[e.pointerId][p] = newval - update = true - } + // update event data + if (this.iosTouchCache[e.pointerId]['update_' + p]()) changed = true + } + if (changed) { + // if polled value has changed, retrig last move event + // reset movement data since this is only relevant when + // the pointer doesn't move + this.iosTouchCache[e.pointerId].movementX = 0 + this.iosTouchCache[e.pointerId].movementY = 0 + // call touch move callback + touchCb(this.iosTouchCache[e.pointerId], 'move') } - if (update) touchCb(this.iosTouchCache[e.pointerId], 'move') }, 1000 / 30) } }, {element: this.container, multitouch: true}) this.on('drag',(e)=>{ touchCb(e, 'move') - if (iOS && this.iosTouch) { + if (this.iosTouch) { // cache touch inforamtions this.iosTouchCache[e.pointerId] = e } @@ -165,7 +164,7 @@ class CanvasWidget extends Canvas { this.on('dragend',(e)=>{ touchCb(e, 'stop') - if (iOS && this.iosTouch) { + if (this.iosTouch) { // stop polling extra touch inforamtions clearInterval(this.iosTouchPolls[e.pointerId]) delete this.iosTouchPolls[e.pointerId] @@ -240,7 +239,7 @@ class CanvasWidget extends Canvas { clearInterval(this.drawInterval) - if (iOS) { + if (this.iosTouch) { for (var k in this.iosTouchPolls) { clearInterval(this.iosTouchPolls[k]) }