* recent changes in master broke event bridge; updated to latest scheme

* fix update throttling for rapidly-changed values from the tablet UI
* include default values for several advanced settings (so if user changes the RESET button works better)
* reduce log spam
This commit is contained in:
humbletim 2017-06-21 15:18:07 -04:00
parent 294d588fc4
commit 01436675b1
6 changed files with 41 additions and 16 deletions

View file

@ -81,6 +81,12 @@ var DEFAULTS = {
'ui-enable-tooltips': true,
'ui-show-advanced-options': false,
'Avatar/Draw Mesh': true,
'Scene/shouldRenderEntities': true,
'Scene/shouldRenderAvatars': true,
'Avatar/Show My Eye Vectors': false,
'Avatar/Show Other Eye Vectors': false,
};
// map setting names to/from corresponding Menu and API properties
@ -203,8 +209,9 @@ function main() {
log('settingsApp.valueUpdated: '+ key + ' = ' + JSON.stringify(value) + ' (was: ' + JSON.stringify(oldValue) + ')');
if (/tablet/i.test(origin)) {
// apply relevant settings immediately if changed from the tablet UI
log('applying immediate setting', key, value);
applicationConfig.applyValue(key, value, origin);
if (applicationConfig.applyValue(key, value, origin)) {
log('settingsApp applied immediate setting', key, value);
}
}
});
@ -228,6 +235,9 @@ function main() {
} break;
case 'reset': {
var resetValues = {};
// maintain current value of 'show advanced' so user can observe any advanced settings being reset
var showAdvancedKey = cameraConfig.resolve('ui-show-advanced-options');
resetValues[showAdvancedKey] = cameraConfig.getValue(showAdvancedKey);
Object.keys(DEFAULTS).reduce(function(out, key) {
var resolved = cameraConfig.resolve(key);
out[resolved] = resolved in out ? out[resolved] : DEFAULTS[key];
@ -396,8 +406,10 @@ function main() {
'triggerReset: ' + triggerReset);
if (/tablet/i.test(origin)) {
log('applying immediate setting', key, value);
applicationConfig.applyValue(key, value, origin);
if (applicationConfig.applyValue(key, value, origin)) {
log('cameraConfig applied immediate setting', key, value);
}
}
triggerReset && cameraControls.reset();
});

View file

@ -119,6 +119,7 @@ try {
function onValueReceived(key, value, oldValue, origin) {
onMutationEvent.paused++;
try {
//debugPrint('>>> onValueReceived', key, value, origin);
jquerySettings.setValue(key, value, origin);
} finally {
setTimeout(function() { onMutationEvent.paused--; }, 1);
@ -135,10 +136,11 @@ try {
var THROTTLE_DELAY_MS = 500;
function throttledSend(update) {
var hash = [update.key, update.method].join('-');
window.clearTimeout(throttledSend[hash]);
throttledSend[hash] = window.setTimeout(function() {
delete throttledSend[hash];
var $hash = [update.params[0], update.method].join('-'); // key-method
window.clearTimeout(throttledSend[$hash]);
throttledSend[$hash] = window.setTimeout(function() {
delete throttledSend[$hash];
//debugPrint('>>> throttled mutation event:', $hash, update.method, update.params);
bridgedSettings.sendEvent(update);
}, THROTTLE_DELAY_MS);
}
@ -147,11 +149,14 @@ try {
function onMutationEvent(event) {
assert(onMutationEvent.paused >= 0);
if (!onMutationEvent.paused) {
//debugPrint('>>> mutation event:', event.key, event.value);
throttledSend({
method: 'valueUpdated', params: [
event.key, event.value, event.oldValue, event.hifiType
]
});
} else {
//debugPrint('>> (paused) mutation event:', event.key, event.value);
}
}
@ -492,6 +497,7 @@ try {
trigger <b>MyAvatar &gt; Reset Sensors</b>;reset <b>bodyPitch</b> and <b>bodyYaw</b>
</span>
</button>
<button title='test EventBridge.emitWebEvent' class='localhost-only' id='test-event-bridge'>EventBridge test</button>
<button title='reload the tablet app web view' class='localhost-only' id='page-reload'>refresh page</button>
<button title='reload the Client script' class='localhost-only' id='script-reload'>reload script</button>
</div>

View file

@ -19,6 +19,11 @@ function setupUI() {
var $json = SettingsJSON;
window.buttonHandlers = {
'test-event-bridge': function() {
log('bridgedSettings.eventBridge === Window.EventBridge', bridgedSettings.eventBridge === window.EventBridge);
bridgedSettings.sendEvent({ method: 'test-event-bridge' });
EventBridge.emitWebEvent('EventBridge.emitWebEvent: testing 1..2..3..');
},
'page-reload': function() {
log('triggering location.reload');
location.reload();

View file

@ -105,11 +105,11 @@ $.widget('ui.hifiButton', $.ui.button, {
var checked = (dataset.checked === 'true');
nv = (nv === 'true' || !!nv);
if (nv !== checked) {
log('hifibutton checked changed', nv, checked);
debugPrint('hifibutton checked changed', nv, checked);
dataset.checked = nv;
this.element.change();
} else {
log('hifibutton value same', nv, checked);
debugPrint('hifibutton value same', nv, checked);
}
}
return dataset.checked === 'true';
@ -133,11 +133,11 @@ $.widget('ui.hifiButton', $.ui.button, {
this.element.find('.tooltip-target').removeClass('tooltip-target');
this.element.prop('id', 'button-'+this.element.prop('id'));
checkbox.element.on('change._hifiButton', function() {
log('checkbox -> button');
debugPrint('checkbox -> button');
this.value(checkbox.value());
}.bind(this));
this.element.on('change', function() {
log('button -> checkbox');
debugPrint('button -> checkbox');
checkbox.value(this.value());
}.bind(this));
this.checkbox = checkbox;

View file

@ -244,7 +244,9 @@ function BrowserUtils(global) {
qt = assert(global.qt, 'expected global.qt to exist');
assert(qt.webChannelTransport, 'expected global.qt.webChannelTransport to exist');
new QWebChannel(qt.webChannelTransport, bind(this, function (channel) {
global.EventBridge = channel.objects.eventBridgeWrapper.eventBridge;
var objects = channel.objects;
global.EventBridge = objects.eventBridge || (objects.eventBridgeWrapper && objects.eventBridgeWrapper.eventBridge);
assert(global.EventBridge, '!global.EventBridge');
global.EventBridge.$WebChannel = channel;
this.log('openEventBridge opened -- invoking callback', 'typeof EventBridge === ' + typeof global.EventBridge);
callback(global.EventBridge);

View file

@ -93,12 +93,12 @@ ApplicationConfig.prototype = {
applyValue: function applyValue(key, value, origin) {
if (this.resolve(key)) {
var appValue = this.getValue(key, value);
log('applyValue', key, value, origin ? '['+origin+']' : '', appValue);
debugPrint('applyValue', key, value, origin ? '['+origin+']' : '', appValue);
if (appValue !== value) {
this.setValue(key, value);
log('applied new setting', key, value, '(was:'+appValue+')');
debugPrint('applied new setting', key, value, '(was:'+appValue+')');
return true;
}
return true;
}
}
};