From 9d4f9b0a4b0a69a6603fffc7b5674e4d97c64790 Mon Sep 17 00:00:00 2001 From: humbletim Date: Wed, 21 Jun 2017 16:00:47 -0400 Subject: [PATCH] more safeguards to help diagnose broken EventBridges --- .../marketplace/camera-move/app.html | 14 +++++++++----- .../marketplace/camera-move/modules/_utils.js | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/unpublishedScripts/marketplace/camera-move/app.html b/unpublishedScripts/marketplace/camera-move/app.html index 00df8e7514..6ab439d58d 100644 --- a/unpublishedScripts/marketplace/camera-move/app.html +++ b/unpublishedScripts/marketplace/camera-move/app.html @@ -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++; diff --git a/unpublishedScripts/marketplace/camera-move/modules/_utils.js b/unpublishedScripts/marketplace/camera-move/modules/_utils.js index 8e57e5b7cf..65314ef98e 100644 --- a/unpublishedScripts/marketplace/camera-move/modules/_utils.js +++ b/unpublishedScripts/marketplace/camera-move/modules/_utils.js @@ -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;