more safeguards to help diagnose broken EventBridges

This commit is contained in:
humbletim 2017-06-21 16:00:47 -04:00
parent 3d7676e918
commit 9d4f9b0a4b
2 changed files with 13 additions and 6 deletions

View file

@ -88,12 +88,16 @@ try {
}
});
function onEventBridgeOpened(eventBridge) {
EventBridge = eventBridge;
log('openEventBridge.opened', EventBridge);
function onEventBridgeOpened(_eventBridge) {
if (!window.EventBridge) {
window.EventBridge = _eventBridge;
}
assert(_eventBridge === window.EventBridge,
'ERROR: window.EventBridge materialized spontaneously and differently from the QWebChannel-derived value');
log('openEventBridge.opened', window.EventBridge);
bridgedSettings = new BridgedSettings({
eventBridge: EventBridge,
eventBridge: window.EventBridge,
namespace: PARAMS.namespace,
uuid: PARAMS.uuid,
debug: PARAMS.debug,
@ -114,7 +118,7 @@ try {
debugPrint('>>> SENDING ACK');
// let Client script know we are ready
eventBridge.emitWebEvent(location.href);
bridgedSettings.eventBridge.emitWebEvent(location.href);
function onValueReceived(key, value, oldValue, origin) {
onMutationEvent.paused++;

View file

@ -239,12 +239,15 @@ function BrowserUtils(global) {
// this.log('openEventBridge| EventBridge already exists... -- invoking callback', 'typeof EventBridge == ' + typeof global.EventBridge);
return callback(global.EventBridge);
} catch (e) {
this.log('EventBridge does not yet exist -- attempting to instrument via qt.webChannelTransport');
this.log('EventBridge does not yet exist in a usable state -- attempting to instrument via qt.webChannelTransport',
Object.keys(global.EventBridge));
var QWebChannel = assert(global.QWebChannel, 'expected global.QWebChannel to exist'),
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) {
var objects = channel.objects;
assert(!global.EventBridge, '... global.EventBridge was unavailable at page load, but has unexpectedly materialized; ' +
Object.keys(global.EventBridge));
global.EventBridge = objects.eventBridge || (objects.eventBridgeWrapper && objects.eventBridgeWrapper.eventBridge);
assert(global.EventBridge, '!global.EventBridge');
global.EventBridge.$WebChannel = channel;